Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The installation and deployment of LVS+keepalived how to complete the load balancing of mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Installation and deployment of LVS+keepalived how to complete mysql load balancing, I believe that many inexperienced people do not know what to do. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Test environment:

LVS1:192.168.9.27

LVS2:192.168.9.28

VIP:192.168.9.230 of keepalived

Mysql1 to be distributed: 192.168.9.29

Mysql2:192.168.9.30 to be distributed

Specific installation steps:

# download ipvsadm (i.e. LVS package)

Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz

# decompression

[root@lvs-a ~] # tar-zxf ipvsadm-1.24.tar.gz

# enter the ipvsadm directory

[root@lvs-a ~] # cd / usr/local/ipvsadm-1.24

# install the development package and library files

[root@lvs-an ipvsadm-1.24] # # yum install zlib-devel gcc gcc-c++ openssl-devel pcre-devel libtool kernel-devel ncurses-devel-y

# create a kernel connection

[root@lvs-an ipvsadm-1.24] # ln-sv / usr/src/kernels/2.6.18-194.el5-i686/ / usr/src/linux # (2.6.18-194.el5-i686) is modified according to the system version.

# compile and install

[root@lvs-an ipvsadm-1.24] # make;make install

# enter the directory

[root@lvs-a ~] # cd / usr/local/

# download keepalived

Wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz

# decompression

[root@lvs-an ipvsadm-1.24] # tar-zxf keepalived-1.2.12.tar.gz

# enter the keepalived directory

[root@lvs-a ~] cd keepalived-1.2.12

# compile and install

[root@lvs-a keepalived-1.2.12] #. / configure-- prefix=/usr/local/keepalived # there are three yes displayed after compilation, indicating that the compilation was successful, otherwise the installation would not be successful.

# the following is version 1.2.12. / configure results are as follows

# if version 1.1.17. / configure results are as follows

[root@lvs-a keepalived-1.2.12] # make

[root@lvs-a keepalived-1.2.12] # make install

# copy startup files

[root@lvs-a keepalived-1.2.12] # cp / usr/local/keepalived/etc/rc.d/init.d/keepalived / etc/init.d/ # # so that you can use the service keepalived command.

# copy command file

[root@lvs-a keepalived-1.2.12] # cp / usr/local/keepalived/sbin/keepalived / usr/sbin/

# copy [configuration file]

[root@lvs-a keepalived-1.2.12] # cp / usr/local/keepalived/etc/sysconfig/keepalived / etc/sysconfig/

# create a new main configuration file directory

[root@lvs-a keepalived-1.2.12] # mkdir-p / etc/keepalived

# Editing configuration file LVS1

[root@lvs-a sysconfig] # vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Router_id lvs

}

Vrrp_sync_group http {# set the vrrp group and name it casually

Group {

Mysql # A random name

}

}

Vrrp_instance apache {# define an vrrp instance

State MASTER # sets the status of lvs, MASTER and BACKUP, which must be uppercase, master node master, slave node backup

Interface eth0 # sets the interface of the external service, that is, the network interface of / LVS monitoring

Virtual_router_id 01 # sets the interface for lvs listening. Under the same instance, virtual_router_id must be the same. Name it casually.

Priority 500 # # sets the priority. The higher the value, the higher the priority, that is, the higher the value of the primary node.

Advert_int 1 # / / the time interval between MASTER and BACKUP load balancers for synchronization checks (in seconds)

Authentication {# set authentication type and password

Auth_type PASS

Auth_pass aabb # # password

}

Virtual_ipaddress {# # set the VIP of keepalived

192.168.9.230 # if there are more than one, just add it down

# 192.168.9.231

# 192.168.9.232

}

}

Virtual_server 192.168.9.230 3306 {# # define a virtual server

Delay_loop 6 # health check-up time in seconds.

Lb_algo rr # load scheduling algorithm, which is set to rr, that is, polling algorithm

The mechanism of lb_kind DR # LVS to achieve load balancing. You can choose three modes: NAT, TUN and DR.

Nat_mask 255.255.255.0 # you don't need to enter this parameter

# persistence_timeout 50

Protocol TCP

Real_server 192.168.9.29 3306 {# # Target Server IP to be distributed

Weight 1 # sets the weight, that is, the number of distributions, which means one for each distribution

TCP_CHECK {# judge the health status of RealServer through tcpcheck

Connect_timeout 3 # # connection timeout

# nb_get_retry 3 # number of reconnections, with default value

# delay_before_retry 3 # default value for interval between reconnection

Connect_port 3306

}

}

Real_server 192.168.9.30 3306 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Connect_port 3306

}

}

}

# restart keepalived after configuration

[root@lvs-a sysconfig] # service keepalived restart

# add your own gateway

[root@lvs-a network-scripts] # route add-host 192.168.9.254 dev eth0

# installing keepalived is the same as lvs1

# configure LVS2 after installing keepalived, as follows:

[root@lvs-b ~] # cat / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Router_id lvs

}

Vrrp_sync_group http {

Group {

Mysql

}

}

Vrrp_instance apache {

State BACKUP

Interface eth0

Virtual_router_id 01

Priority 400

Advert_int 1

# nopreempt

Authentication {

Auth_type PASS

Auth_pass aabb

}

Virtual_ipaddress {

192.168.9.230

}

}

Virtual_server 192.168.9.230 3306 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

# persistence_timeout 50

Protocol TCP

Real_server 192.168.9.29 3306 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Connect_port 3306

}

}

Real_server 192.168.9.30 3306 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Connect_port 3306

}

}

}

# restart keepalived after configuration

Service keepalived restart

# add your own gateway

Route add-host 192.168.9.254 dev eth0

# View

Route-n

# View the distribution results

Ipvsadm-ln

# clear distribution

Ipvsadm-C

# View Virtual ip (VIP)

Ip addr

# configure mysql-realserver1 to be executed on 192.168.9.29:

[root@lvs-a ~] # ifconfig lo:0 192.168.9.230 netmask 255.255.255.0 broadcast 192.168.9.230 up # # set a temporary IP

Set the route to the host

[root@lvs-b ~] # route add-host 192.168.9.230 dev lo:0

Set default rout

[root@lvs-b ~] # route add default gw 192.168.9.137

Ensure that during the connection process of the arp protocol, the router only knows that 192.168.9.230 corresponds to the dispenser.

[root@lvs-b ~] # echo 1 > / proc/sys/net/ipv4/conf/all/arp_ignore

[root@lvs-b ~] # echo 2 > / proc/sys/net/ipv4/conf/all/arp_announce

# configure mysql-realserver2 to be executed on 192.168.9.30:

[root@lvs-a ~] # ifconfig lo:0 192.168.9.230 netmask 255.255.255.0 broadcast 192.168.9.230 up

Set the route to the host

[root@lvs-a ~] # route add-host 192.168.9.230 dev lo:0

Set default rout

[root@lvs-a ~] # route add default gw 192.168.153.137

Ensure that during the connection process of the arp protocol, the router only knows that 192.168.9.230 corresponds to the dispenser.

[root@lvs-a ~] # echo 1 > / proc/sys/net/ipv4/conf/all/arp_ignore

[root@lvs-a ~] # echo 2 > / proc/sys/net/ipv4/conf/all/arp_announce

# launch separate mysql after the configuration of two mysql-realserver is completed

Service mysqld start

LVS Distribution Test:

1, create a database called slave1 in mysql-realserver1 (192.168.9.29):

Mysql > create database slave1

Query OK, 1 row affected (0.00 sec)

2, create a database called slave2 on mysql-realserver2 (192.168.9.30):

Mysql > create database slave2

Query OK, 1 row affected (0.00 sec)

3, execute on a machine that can ping mysql-realserver1 and mysql-realserver2 (be careful not to execute on the lvs machine you are using, for example, lvs now uses [root@lvs-a ~] # this machine, if you execute it here, it will report an error.

[root@lvs-a] # mysql-uroot-pliuwenhe-h292.168.9.230-e'show databases'

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.9.230'

You have new mail in / var/spool/mail/root

[root@lvs-b] # mysql-uroot-pliuwenhe-h292.168.9.230-e'show databases'

+-+

| | Database |

+-+

| | information_schema |

| | he |

| | liuwenhe |

| | mysql |

| | performance_schema |

| | slave1 |

| | test |

+-+

[root@lvs-b] # mysql-uroot-pliuwenhe-h292.168.9.230-e'show databases'

+-+

| | Database |

+-+

| | information_schema |

| | he |

| | liuwenhe |

| | mysql |

| | performance_schema |

| | slave2 |

| | test |

+-+

Indicates that the lvs was distributed successfully.

After reading the above, have you mastered the installation and deployment of LVS+keepalived how to complete the load balancing of mysql? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report