About Keepalived
Keepalived is originally designed for LVS, which is specially used to monitor the status of each service node in the cluster system. It detects the status of each service node according to the third, fourth and fifth layer switching mechanisms of the TCP/IP reference model. If a server node is abnormal, or the work fails, keepalived will detect it and set the failed server nodes from the set In the group system, these tasks are all done automatically without human intervention. What needs to be done manually is only to repair the failed service nodes.
Topology of this experiment:
Experimental steps:
Synchronize the time of the machines in the cluster, turn off the firewall and selinux
ntpdate cn.pool.ntp.org systemctl stop firewalld.service setenforce 0
Operation on lvs1/2
-
Download necessary tools
yum install gcc gcc-c++ openssl-devel.x86_64 -y
-
Download keepalived and LVS tools
Website: https://keepalived.orgwget https://keepalived.org/software/keepalived-2.0.10.tar.gz yum install ipvsadm.x86_64 -y
-
Install and compile keepalived
tar -xzf keepalived-2.0.10.tar.gz -C /usr/local/src/ cd /usr/local/src/keepalived-2.0.10/ mkdir /data yum install libnl-devel.x86_64 -y ./configure --prefix=/data/kepalived
[root@master1 keepalived-2.0.10]# make && make install
-
. configure startup
cp /data/kepalived/etc/init.d/keepalived /etc/init.d/ cp /data/kepalived/etc/sysconfig/keepalived /etc/sysconfig/ mkdir /etc/keepalived cp /data/kepalived/etc/keepalived/keepalived.conf /etc/keepalived/
-
Modify profile
vim /etc/keepalived/keepalived.conf
#Profile of the master node ! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_1 } vrrp_instance VI_1 { state MASTER interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.192.123 } } virtual_server 192.168.192.123 80 { delay_loop 6 lb_algo wrr lb_kind DR nat_mask 255.255.255.255 persistence_timeout 300 protocol TCP real_server 192.168.192.139 80 { weight 1 TCP_CHECK { connect_timeout 8 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.192.140 80 { weight 1 TCP_CHECK { connect_timeout 8 nb_get_retry 3 delay_before_retry 3 conect_port 80 } } } #Profile from node ! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_1 } vrrp_instance VI_1 { state BACKUP interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.192.123 } } virtual_server 192.168.192.123 80 { delay_loop 6 lb_algo wrr lb_kind DR nat_mask 255.255.255.255 persistence_timeout 300 protocol TCP real_server 192.168.192.140 80 { weight 1 TCP_CHECK { connect_timeout 8 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.192.139 80 { weight 1 TCP_CHECK { connect_timeout 8 nb_get_retry 3 delay_before_retry 3 conect_port 80 } } }
-
Turn on services and view LVS
systemctl start keepalived
Operation on RS1/2 node
-
Disable responding to ARP requests to VIP s
Because of the DR model based on LVS, we need to set the local VIP to not respond to arp requests from external hostsecho 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
-
Set vip
ifconfig lo:0 192.168.192.123 netmask 255.255.255.255
-
Configure pages for httpd
yum install httpd.x86_64 -y #192.168.192.139 echo web 139 > /var/www/html/index.html #192.168.192.140 echo web 140 > /var/www/html/index.html
test
View LVS configuration
ipvsadm -Ln
Testing at clien
The configuration file of keepalived is in / etc/keepalived/keepalived.conf by default, which is not stored at will