Installation and use of keepalived-1.3.5 under Centos7.4

1. Installation dependencies (Centos7.4 used in this article is the minimum installation, and some dependencies are incomplete, so you need to install the dependencies first)

yum install -y gcc gcc-c++  openssl-devel

2. Download the keepalived-1.3.5 compressed package and decompress it, the steps are omitted

3. Enter the decompressed directory and execute the following command:

./configure --prefix=/usr/local/keepalived && make && make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
mkdir -p /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived-1.3.5/keepalived/etc/init.d/keepalived /etc/init.d/
chmod 755 /etc/init.d/keepalived

4. Edit keepalived.service

vi /lib/systemd/system/keepalived.service

Replace all strings "/usr/local/keepalived" with blanks, vi editor command: [%s/\/usr\/local\/keepalived//g]

5. Refresh the configuration

systemctl daemon-reload

6. Edit /etc/keepalived/keepalived.conf to configure your own configuration. For details, refer to Portal . Example:

global_defs {
    router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eno16780032
    virtual_router_id 151
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass inspur
    }

    virtual_ipaddress {
        192.168.10.175
    }
}


virtual_server 192.168.10.175 5555 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.255
    persistence_timeout 0
    protocol TCP

    real_server 192.168.10.181 5555 {
        weight 100
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 5555
        }
    }

    real_server 192.168.10.182 5555 {
        weight 100
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 5555
        }
    }
}

The example is the configuration on the standby node

 

7. Add a script to each Real Server, named [rs.sh], from the content in the portal above:

SNS_VIP=$2
#/etc/rc.d/init.d/functions
case "$1" in
start)
       ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
       /sbin/route add -host $SNS_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/all/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
       sysctl -p >/dev/null 2>&1
       echo "RealServer Start OK"
       ;;
stop)
       ifconfig lo:0 down
       route del $SNS_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"
       ;;
*)
       echo "Usage: $0 {start|stop}"
       exit 1
esac
exit 0

Increase execute permission:

chmod  755 rs. sh

implement:

./rs.sh start [VIP]

 

8. Execute on the master node 

systemctl start keepalived

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324648900&siteId=291194637