Linux Cluster Architecture (LVS DR mode building, preserved + LVS)

Posted by jackpf on Sun, 05 Jan 2020 09:12:48 +0100

LVS DR mode building

Preparatory work: three machines

Distributor, also called scheduler (dir in short): 192.168.248.128
rs1 : 192.168.248.129
rs2 : 192.168.248.130
vip : 192.168.248.200

1. Edit the script file * * / usr/local/sbin/lvs_dr.sh * * on dir as follows:

#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward #Open port forwarding
ipv=/usr/sbin/ipvsadm
vip=192.168.248.200
rs1=192.168.248.132
rs2=192.168.248.133
#Pay attention to the name of the network card here
#Binding vip
ifdown ens33
ifup ens33
ifconfig ens33:2 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev ens33:2
$ipv -C
$ipv -A -t $vip:80 -s rr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1

2. Execute script

[root@yolks-001 ~]# sh /usr/local/sbin/lvs_dr.sh
 Device 'ens33' disconnected successfully.
Connection activated successfully (D-Bus active path / org/freedesktop/NetworkManager/ActiveConnection/5)

3. The RS machine also needs to edit the configuration file and add the script file * * / usr/local/sbin/lvs_rs.sh * *, as follows:

#/bin/bash
vip=192.168.248.200
#The purpose of binding vip to lo is to realize rs to directly return the result to the client
ifdown lo
ifup lo
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
#The following operation is to change the arp kernel parameters so that rs can send the mac address to the client smoothly
#Reference document: www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

4. Test and view activity status

keepalived + LVS

The complete architecture requires two servers (the role is dir) to install the keepalived software respectively, in order to achieve high availability, but keepalived itself has the function of load balancing, so this experiment can only install one keepalived

The function of ipvsadm is built in keepalived, so there is no need to install the ipvsadm package, and no need to write and execute the LVS? Dir script

The three machines are:
dir (installed) 192.168.248.128
rs1 192.168.248.129
rs2 192.168.248.130
vip 192.168.248.200

1. Edit the keepalived configuration file / etc/keepalived/keepalived.conf, as follows:

vrrp_instance VI_1 {
    #BACKUP on standby server
    state MASTER
    #The network card bound to vip is ens33. Your network card may be different from that of Amin. You need to change it here
    interface ens33
    virtual_router_id 51
    #90 on standby server
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass aminglinux
    }
    virtual_ipaddress {
        192.168.248.200
    }
}
virtual_server 192.168.248.200 80 {
    #(query realserver status every 10 seconds)
    delay_loop 10
    #(lvs algorithm)
    lb_algo wlc
    #(DR mode)
    lb_kind DR
    #(the connection of the same IP is allocated to the same RealServer within 60 seconds)
    persistence_timeout 60
    #(check the state of realserver with TCP protocol)
    protocol TCP

    real_server 192.168.248.129 80 {
        #(weight)
        weight 100
        TCP_CHECK {
        #(10 seconds no response timeout)
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.248.130 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}

2. Restart keepalived on dir

systemctl stop keepalived
systemctl start keepalived

3. View the keepalived rule

[root@yolks-001 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.248.200:80 wlc persistent 60
  -> 192.168.248.129:80           Route   100    0          0         
  -> 192.168.248.130:80           Route   100    0          0

4. Stop nginx of rs3 machine

systemctl stop nginx

5. Check the keepalived rule again for the dir machine: there are fewer rules for the stopped rs2 machine

[root@yolks-001 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.248.200:80 wlc persistent 60
  -> 192.168.248.129:80           Route   100    0          0

Expand

haproxy+keepalived http://blog.csdn.net/xrt95050/article/details/40926255
Comparison of nginx, lvs and haproxy http://www.csdn.net/article/2014-07-24/2820837
Custom script VRRP? Script in keepalived http://my.oschina.net/hncscwc/blog/158746
The implementation of lvs dr mode using only one public ip http://storysky.blog.51cto.com/628458/338726

Topics: network Nginx Mac