LVS DR Mode + keepalived

 

First environment requires:

LVS: Main 192.168.238.141

LVS: Preparation of 192.168.238.142

VIP:  IP 192.168.238.181

web1 : 192.168.238.131

web2 :    192.168.238.132

 

Ipvsadm installation and service keepalived on LVS

yum -y install ipvsadm keepalived

 

Configuration profiles increase keepalived VIP address and web server address in the primary LVS

vim /etc/keepalived/keepalived.conf
Modifications are as follows:
virtual_ipaddress {
     192.168 . 238.181 #VIP address      
}

virtual_server 192.168 . 238.181  80 {#VIP address
    delay_loop 6
    lb_algo rr #rr algorithm
    lb_kind DR #DR mode
   Persistence_timeout # 50   conversation held in 50 seconds
    nat_mask 255,255 . 255.0
    protocol TCP

    real_server 192.168 . 238.133  80 {# server address web1
        weight 1
        TCP_CHECK {# health checks
            connect_prot    80   # 80 to check the connection port
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.238.134 80 {
        weight 1
        TCP_CHECK {
            connect_prot   80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

Preparation of the same modified LVS

Xintian following changes

modify the BACKUP state (to the standby state)

prioity 90 (90 to less than the main priority)

Turn off the firewall service restart keepalived

ip a VIP checks to see if

Increase LVS rule

First increase VIP
ipvsadm -A -t 192.168.238.181:80 -s rr
Increase web server address
ipvsadm -a -t 192.168.238.181:80 -r 192.168.238.133:80 -g
ipvsadm -a -t 192.168.238.181:80 -r 192.168.238.133:80 -g

After the completion of the increase can be viewed through -Ln ipvsadm

 

The following operation is performed two end web

Copy out a loopback interface is convenient VIP

cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0:
Modify the following
DEVICE=lo:0
IPADDR=192.168.238.181
NETMASK=255.255.255.255
ONBOOT=yes

Modify arp level

Response level
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
Notice level
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

Increased routing

route add 192.168.238.181 dev lo

 Written test page in a web end and turn off the firewall

VIP access through the successful test page appears!

Guess you like

Origin www.cnblogs.com/l999999999/p/12060588.html