LVS DR mode (operation piece)

1) prepare three virtual machines

server1 192.168.200.111 LVS load balancer

server2 192.168.200.112 WEB host (server node)

server3 192.168.200.113 WEB host (server node)

2) all hosts turn off the firewall and selinux

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# iptables -F

[root@localhost ~]# setenforce 0

3) Configure the load balancer

     Configure virtual IP address (VIP) by way of a virtual interface (ens32: 0), bind VIP address for the network card ens32, in order to respond to access the cluster.

[root@localhost ~]# yum -y install ipvsadm

[root@localhost ~]# ifconfig ens32:0 192.168.200.254 netmask 255.255.255.0

4) configure the load allocation policy

[root@localhost ~]# ipvsadm -A -t 192.168.200.254:80 -s rr

[root@localhost ~]# ipvsadm -a -t 192.168.200.254:80 -r 192.168.112:80 -g -w 1

[root@localhost ~]# ipvsadm -a -t 192.168.200.254:80 -r 192.168.113:80 -g -w 1

[root@localhost ~]# ipvsadm -Ln

5) the configuration node server

  When using the DR mode, the node server need to configure the VIP address, and adjusting the kernel update ARP response to VIP prevent the MAC address, to avoid conflict. In addition, similar to the way NAT configuration and Web services.

  Each node in the server, there is also need VIP address 192.168.200.254, but this address is used only as the transmission source address of the Web response packet does not need to listen for client access request (to change the listen and distributed by the scheduler). Thus using virtual interface lo: 0 to carry VIP address, and add a route recording native, VIP access data limit to avoid local communication disorder.

[root@localhost ~]# ifconfig lo:0 192.168.200.254 netmask 255.255.255.255     

[root@localhost ~]# route add -host 192.168.200.254 dev lo0

6) install httpd, to create a test page

(112)     [root@localhost ~]# yum -y install httpd

                  [root@localhost ~]# echo "server1" > /var/www/html/index.html

                  [root@localhost ~]# systemctl start httpd

(113)     [root@localhost ~]# yum -y install httpd

                  [root@localhost ~]# echo "server2" > /var/www/html/index.html

                  [root@localhost ~]# systemctl start httpd

7) Adjust / proc response parameters

 [root@localhost ~]# vim /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.default.arp_ignore = 1

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

 [root@localhost ~]# sysctl -p

● arp_ignore = 1, the destination IP system only answer to the local IP packet, which is broadcast package does not respond.

● arp_announce = 2, the system ignores the source address of the IP packet (source address), and according to the destination host (target host), select the local address.

8) Test LVS cluster

  Arrange multiple test machines, access http://192.168.200.254/ directly from the Internet, will be able to see the real web page content provided by the server - the nodes if the page is different, different clients may not see the page Like (can refresh a few times)

Guess you like

Origin www.cnblogs.com/2567xl/p/11626897.html