The previous article on the introduction of load Balancer LVS has explained the principle of lvs-dr, this article mainly introduces its implementation process in MySQL application:
Test environment: 4 virtual machines are CENTOS6 operating systems, using the system's own MySQL package installation test:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/4E/wKioL1YY3QbTEdf8AAFbNDovCbk650.jpg "title=" Qq20151010173656.png "alt=" Wkiol1yy3qbtedf8aafbndovcbk650.jpg "/>
As shown, VIP and RIP use the LVS-DR model to implement the MySQL Cluster service in the same network segment
Director
#!/bin/bash#!/bin/bash# auto install lvm-dr# date 2015-10-10#close selinux and iptablessed -i "s/selinux=.*/selinux=permissive/" /etc/sysconfig/selinux //Close selinuxchkconfig iptables off service iptables stop &> /dev/null //Stop iptables service # ip_forward=1sed -i "[Email protected]_ Forward = [email protected]_forward = [email protected] " /etc/sysctl.conf && sysctl -p &>/dev/null //Turn on forwarding function # install ipvsadm rpm -q ipvsadm &> /dev/ null // Installing the IPVSADM command-line tool If [ $? -eq 1 ]; then yum install -y ipvsadm & > /dev/nullfi# define variableipvsadm= ' Which ipvsadm ' vip=172.16.16.2rs1=172.16.16.3rs2= 172.16.16.4#ifconfig eth0:0 vipifconfig eth0:0 $VIP/32 broadcast $VIP up# define lvs-dr$IPVSADM -C //Purge rule $ipvsadm -a -t $VIP:3306 -s lblc //define MySQL Cluster service $ipvsadm -a -t $VIP:3306 -r $RS 1:3306 -g //Add node to the DR model of the MySQL Cluster service $ipvsadm -a -t $VIP: 3306 -r $RS 2:3306 -g$ipvsadm -l -n
Node1
#!/bin/bash# lvs-nat node define# # define hostnamename=node1 // Define host name hostname $namesed -i s/hostname=localhost/hostname= $name/" /etc/sysconfig/network# define ip echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/lo/arp_ ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announceecho 2 > /proc/sys/ net/ipv4/conf/eth0/arp_announceecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announcevip= 172.16.16.2ifconfig lo:0 $VIP/32 broadcast $vip up //definition viproute add -host $VIP dev lo:0# yum Install mysql-server rpm -q mysql-server &> /dev/null //installation mysql if [ $? -eq 1 ];then Yum install -y mysql-server &> /dev/nullfichkconfig mysqld onservice mysqld start &> /dev/null && ss -tanl | grep 3306 &> /dev/null //start the MySQL service if [ $? -eq 0 ]; then echo -e "mysqld start \033[32m[ok]\033[0m" else echo -e "mysqld start \033[31m[fail]\033[0m" exit 2fi
mysql> CREATE DATABASE Node1; Create Node1 Database mysql> grant all on * * to [email protected] ' 172.16.%.% ' identified by ' 123456 '; Authorized Telnet user mysql> flush privileges;
Node2
#!/bin/bash# lvs-nat node define# # define hostnamename=node2 //Define host name hostname $namesed -i "s/hostname=localhost/hostname= $name/" /etc/sysconfig/network# define ip echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/lo/ arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announceecho 2 > /proc/ sys/net/ipv4/conf/eth0/arp_announceecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announcevip= 172.16.16.2ifconfig lo:0 $VIP/32 broadcast $vip up //definition viproute add -host $VIP dev lo:0# yum Install mysql-server rpm -q mysql-server & > /dev/null // Installing Mysql if [ $? -eq 1 ];then yum install -y mysql-server &> /dev/nullfichkconfig mysqld onservice mysqld start &> /dev/null && ss -tanl | grep 3306 &> /dev/null //start the MySQL service if [ $? -eq 0 ]; then echo -e "mysqld start \033[32m[ok]\033[0m" else echo -e "mysqld start \033[31m[fail]\033[0m" exit 2fi
mysql> CREATE DATABASE Node2; Create Node2 Database mysql> grant all on * * to [email protected] ' 172.16.%.% ' identified by ' 123456 '; Authorized Telnet user mysql> flush privileges;
LVs needs to turn off ARP in DR Mode:arp_announce and Arp_ignore used to block ARP requests
Arp_ignore
Define a different answer mode for ARP that has a destination address of local IP 0
0-(default): Responds to ARP query requests for any local IP address on any network interface
1-Answer only the destination IP address is the ARP query request that visited the local address of the network interface
2-Answer only the destination IP address is the ARP query request that accesses the local address of the network interface, and the visiting IP must be within the subnet segment of the network interface
3-Do not respond to ARP requests from the network interface, but only to the unique and connected addresses of the settings
4-7-Leave unused
8-ARP queries that do not respond to all (local addresses)
Arp_ignore set to 1, this is a good understanding, when someone else's ARP request come over, if the receiving device does not have this IP, will not respond, the default is 0, as long as the machine above any one of the devices above the IP, respond to the ARP request, and send a MAC address answer.
Arp_announce
On the network interface, the local IP address of the emitted, ARP response, to make the appropriate level of restriction: to determine the different degrees of limitation, announcing the interface from the local source IP address to make an ARP request
0-(default) Any local address on any network interface (ETH0,ETH1,LO)
1-try to avoid an ARP response that does not take the local address of the network interface subnet segment. It is useful when the source IP address of the originating ARP request is set to reach this network interface through a route. This checks whether the visiting IP is one of the IP within the subnet segment on all interfaces. If the IP is not in the subnet segment of each network interface, then the Level 2 is used for processing.
2-Use the most appropriate local address for the query target. In this mode, the source address of this IP packet is ignored and an attempt is to select a local address that can communicate with that address. First, select the local address in the subnet of all network interfaces that contains the destination IP address in the subnet. If no appropriate address is found, the current send network interface or other network interface that is likely to receive the ARP response will be selected for sending.
Test
[[email protected] ~]# mysql -uroot -h172.16.16.2 -p123456 welcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 4server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its Affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or Itsaffiliates. other names may be trademarks of their respectiveowners . type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> show databases;+--------------------+| database |+--------------------+| information_schema | | mysql | | node2 | | test |+-------- ------------+4 rows in set (0.00 sec) [[Email protected] ~]# mysql -uroot -h172.16.16.2 -p123456 //Test once again mysql> show databases;+---- ----------------+| database |+---------- ----------+| information_schema | | mysql | | node2 | | test |+--------------------+4 rows in set (0.00 sec)
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/50/wKioL1YZG5iDoufGAAEZu0M7444628.jpg "title=" Qq20151010220649.png "alt=" Wkiol1yzg5idoufgaaezu0m7444628.jpg "/>
Test complete!!!
This article is from the "Bengbengtu" blog, make sure to keep this source http://bengbengtu.blog.51cto.com/9505633/1701745
Linux cluster-load balancer LVS-DR implementation MySQL