LVS load balancing: Dr + maintained deployment

What is keepalived

  • List item

keepalived is a service software to ensure high availability of cluster in cluster management. Its function is similar to heartbeat to prevent single point of failure.
Three core modules of keepalived`

  • core module
  • chech health monitoring
  • vrrp virtual routing Redundancy Protocol
    Three important functions of keepalived
  • Managing LVS
  • Check LVS cluster node
  • High availability as a system network service
    How keepalived works
  • Keepvlied uses VRRP hot backup protocol to realize multi machine hot backup function of Linux server
  • VRRP, virtual route redundancy protocol, is a backup solution for routers
    ① A hot standby group is composed of multiple routers to provide external services through the public virtual IP address
    ② There is only one main router in each hot backup group at the same time to provide services, and other routers are in redundant state
    ③ If the current online router fails, other routers will automatically replace the virtual IP address according to the set priority and continue to provide services
    General configuration options
  • priority 100: priority, the higher the value, the higher the priority
  • Advert? INT1: number of seconds between announcements (heartbeat frequency)
  • Auth? Type pass: authentication type
  • auth_pass 123456: password string
  • virtual_ipaddress{vip}: Specifies the drift address (VIP), which can have multiple
    There are three different options for the configuration of the keepalived backup server and the master
  • Rooter? ID: set to own name
  • state: set to BACKUP
  • priority: value lower than primary server
    The experimental steps are as follows
    LVS_DR mode + keepalied
    Dispatcher service DR1 (main) 192.168.100.110
    Dispatcher service DR2 (standby) 192.168.100.111
    Node server web1 192.168.100.201
    Node server web2 192.168.100.202
    Virtual IP 192.168.100.10
    Configure two scheduling servers of DR
    //Install two software packages maintained (double-click hot standby) ipvsadm (DR scheduling)
yum install keepalived ipvsadm -y
//Set forwarding of routing packets
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
#proc response turns off redirection
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects=0

//Make parameters effective
sysctl -p
//Set up virtual network card
cp -p /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33:0
//Set up virtual network card
vim /etc/sysconfig/network-scripts//ifcfg-ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.0

//Writing startup scripts

vim /etc/init.d/dr.sh
#!/bin/bash
GW=192.168.100.1
VIP=192.168.100.10
RIP1=192.168.100.201
RIP2=192.168.100.202
case "$1" in
start)
        /sbin/ipvsadm --save > /etc/sysconfig/ipvsadm
        systemctl start ipvsadm
        /sbin/ifconfig ens33:0 $VIP broadcast $VIP netmask 255.255.255.255 broadcast $VIP up
        /sbin/route add -host $VIP dev ens33:0
        /sbin/ipvsadm -A -t $VIP:80 -s rr
        /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
        /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
        echo "ipvsadm starting------------------[ok]"
        ;;
        stop)
        /sbin/ipvsadm -C
        systemctl stop ipvsadm
        ifconfig ens33:0 down
        route del $VIP
        echo "ipvsamd stoped--------------------[ok]"
        ;;
   stop)
       /sbin/ipvsadm -C
        systemctl stop ipvsadm
        ifconfig ens33:0 down
        route del $VIP
        echo "ipvsamd stoped--------------------[ok]"
        ;;
        status)
        if [ ! -e ar/lock/subsys/ipvsadm ];then
        echo "ipvsadm stoped--------------------"
        exit 1
                   else
                echo "ipvsamd Runing-------------[ok]"
        fi
        ;;
        *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        esac
        exit 0
    

    

        //Add authority
chmod +x /etc/init.d/dr.sh

Change the network card to host only connection mode

//Change network card to static network card
vim /etc/sysconfig/network-scripts/ifcfg-ens33
//DR1 server
IPADDR=192.168.100.110            
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
//DR2 server
IPADDR=192.168.100.111           
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
#Change DHCP to static
//Restart service
service network start

//Start virtual network card
ifup ens33:0
//Start the dr.sh script
service dr.sh start
//Turn off firewall
systemctl stop firewalld.service
setenforce 0

Establishing two node server web (apache)

//Install apache services
yum install httpd -y
//Turn off firewall
systemctl stop firewalld.service 
setenforce 0
//Create home page
#web1 server
vim /var/www/html/index.html
<h1>this is kgc</h1>

web2 server

vim /var/www/html/index.html
<h1>this is accp</h1>

Set loopback address

//Create a virtual network card
cp -p /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.0
ONBOOT=yes
//Edit the startup script (web2 will operate on the following script through remote replication)
vim /etc/init.d/web.sh
#!/bin/bash
VIP=192.168.100.10
        case "$1" in
        start)
             ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
                /sbin/route add -host $VIP dev lo:0
        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/lo/arp_ignore
        echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
        sysctl -p > /dev/null 2>&1
        echo "RealServer Start OK "
        ;;
        stop)
                ifconfig lo:0 down
                route del $VIP /dev/null 2>&1
                echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
                echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
                echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
                echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
    echo "RealServer Stoped"
        
//Remote copy script file to web2 server (address: 192.168.183.150)
scp /etc/init.d/web.sh root@192.168.183.150:/etc/init.d/web.sh

//Grant authority
chmod +x /etc/init.d/web.sh

Modify the virtual data network card to static mode (only host connected mode)

/Modify NIC
#web1 server
vim /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.100.201           
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
#web2 server
vim /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.100.202           
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
#Change DHCP to static
//Restart service
service network start
//Start script file
service web.sh start
//Start apache service
systemctl start httpd
//Start loopback address
ifup lo:0

Build hot standby

//Modify profile
cd /etc/keepalived/
vim /keepalived.conf
//Modify file
   smtp_server 127.0.0.1
   router_id LVS_01
 
   interface ens33
   virtual_router_id 10
   #Delete the following two lines of IP address 192.168.100.16 and change it to virtual host address 192.168.100.10
29     virtual_ipaddress {
      192.168.200.16
      192.168.200.17
     192.168.200.18
//Modify file
34 virtual_server 192.168.100.10 80 {
      delay_loop 6
      lb_algo rr
      lb_kind DR
      persistence_timeout 50
      protocol TCP
       //Change the meta IP address to the web address (port 192.168.100.201 to 80). Delete 9 lines under weight 1 and add TCP "check" {  ,connect_port 80
real_server 192.168.100.201 80 {
          weight 1
          TCP_CHECK {
              connect_port 80
              connect_timeout 3
              nb_get_retry 3
              delay_before_retry 3
          }   
//Copy the real_server modified above on line 49 and change the IP address to 192.168.100.202
      real_server 192.168.100.202 80 {
          weight 1
          TCP_CHECK {
              connect_port 80
              connect_timeout 3
              nb_get_retry 3
              delay_before_retry 3
//Delete after 60 lines
//Restart service
systemctl start keepalived.service 
//Copy the modified file to web2 remotely (192.168.100.111)
scp /etc/keepalived/keepalived.conf root@192.168.100.111:/etc/keepalived/
//Modifying the maintained profile in web2
 vim /etc/keepalived/keepalived.conf
router_id LVS_02
vrrp_instance VI_1 {
    state BACKUP
priority 90
//Restart service
systemctl start keepalived.service 

Note: if the ping fails, restart the service

Published 45 original articles, won praise 10, visited 154
Private letter follow

Tags: network vim Apache yum

Posted on Thu, 16 Jan 2020 02:33:13 -0800 by DjNaF