拓撲圖介紹:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?RS01 (real-server)
Client <- [DR01 + DR02-BACKUP] keepalived (Director-s) <-- |
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? RS02 (real-server)
DR01:
? ? ? ? 192.168.131.90? (內網)
? ? ? ? 192.168.43.90? ?(外網)
DR02-BACKUP:
? ? ? ? 192.168.131.91 (內網)
? ? ? ? 192.168.43.91? ?(外網)
RS01:?
? ? ? ? 192.168.131.92? (內網)
RS02:?
? ? ? ? 192.168.131.93? (內網)
Client:?
? ? ? ? 192.168.43.110
vip(內網): 192.168.131.190
vip(外網): 192.168.43.199
內網網關: 192.168.131.190
外網網關: 192.168.43.1
附:IP地址嚴格此規(guī)劃,selinux設置、關閉防火墻、基本軟件的安裝(略)
如果使用vmware進行試驗,RS01、RS02、DR02-BACKUP、DR01的131網段均使用host-only模式,DR01、DR02-BACKUP的43網段使用橋接模式。
報文請求過程分析
1.當用戶請求到達DS時,請求報文會先經過內核空間中的PREROUTING鏈,此時源IP為CIP,目的IP為VIP;
2.在PREROUTING規(guī)則鏈上進行檢查目的IP是否為本機,如果是的話將數據包送至INPUT 鏈;
3.數據包到達INPUT鏈后,IPVS會比對數據包請求的服務是否為集群服務,若是,修改數據包的目標IP地址為后端服務器IP(這里需要根據各種算法計算,哪臺RS更合適),
再將數據包發(fā)至POSTROUTING鏈,此時報文的源IP為CIP,目標IP為 RIP;
4.POSTROUTING鏈的作用就是選路,根據INPUT鏈中目標IP,將數據包發(fā)送給RS;
5.RS發(fā)現數據包中的目標IP是自己的IP,此時它會開始構建響應報文發(fā)并回給DS, 此時報文的源IP為RIP,目標IP為CIP;
6.DS收到RS響應后,但在響應客戶端,會將源IP地址修改為自己的VIP地址,然后發(fā)送給客戶端,此時報文的源IP為 VIP,目標IP為CIP;
參閱(圖):
https://www.cnblogs.com/blxt/p/13099437.html
(一)ipvsadm與keepalived安裝配置
1.開啟ip_forward轉發(fā)功能
執(zhí)行機器:DR01與DR02-BACKUP
[root@DR01 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@DR01 ~]# cat /proc/sys/net/ipv4/ip_forward
1
[root@DR02-BACKUP ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@DR02-BACKUP ~]# cat /proc/sys/net/ipv4/ip_forward
1
2.ipvsadmin與keepalived安裝
執(zhí)行機器:DR01與DR02-BACKUP
[root@DR01 ~]# yum install ipvsadm keepalived -y
[root@DR01 ~]# rpm -qa | grep ipvs
ipvsadm-1.27-8.el7.x86_64
[root@DR01 ~]# rpm -qa | grep keepalived
keepalived-1.3.5-16.el7.x86_64
[root@DR01 ~]#
[root@DR02-BACKUP ~]# yum install ipvsadm keepalived -y
[root@DR02-BACKUP ~]# rpm -qa | grep ipvs
ipvsadm-1.27-8.el7.x86_64
[root@DR02-BACKUP ~]# rpm -qa | grep keepalived
keepalived-1.3.5-16.el7.x86_64
[root@DR02-BACKUP ~]#
3.keepalived的配置
*DR01配置:
[root@DR01 /]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
? router_id LVS_01
? #vrrp_skip_check_adv_addr
? #vrrp_garp_interval 0
? #vrrp_gna_interval 0
}
vrrp_instance VI_1 {
? ? state MASTER
? ? interface ens37
? ? virtual_router_id 51
? ? priority 100
? ? advert_int 1
? ? authentication {
? ? ? ? auth_type PASS
? ? ? ? auth_pass 1111
? ? }
? ? virtual_ipaddress {
? ? ? ? 192.168.43.199
? ? }
}
vrrp_instance LAN_GATEWAY {
? ? state MASTER
? ? interface ens33
? ? virtual_router_id 52
? ? priority 100
? ? advert_int 1
? ? authentication {
? ? ? ? auth_type PASS
? ? ? ? auth_pass 1111
? ? }
? ? virtual_ipaddress {
? ? ? ? 192.168.131.190
? ? }
}
virtual_server 192.168.43.199 80 {
? ? delay_loop 6
? ? lb_algo rr
? ? lb_kind NAT
? ? #persistence_timeout 50
? ? protocol TCP
? ? real_server 192.168.131.92 80 {
? ? ? ? weight 10
? ? ? ? TCP_CHECK {
? ? ? ? ? connect_timeout 3
? ? ? ? ? retry 3
? ? ? ? ? delay_before_retry 3
? ? ? ? ? connect_port 80
? ? ? ? }
? ? }
? ? real_server 192.168.131.93 80 {
? ? ? weight 10
? ? ? TCP_CHECK {
? ? ? connect_timeout 3
? ? ? retry 3
? ? ? delay_before_retry 3
? ? ? connect_port 80
? ? ? }
? ? }
}
[root@DR01 /]#
*DR02-BACKUP配置:
[root@DR02-BACKUP keepalived]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
? router_id LVS_01
? #vrrp_skip_check_adv_addr
? #vrrp_garp_interval 0
? #vrrp_gna_interval 0
}
vrrp_instance VI_1 {
? ? state BACKUP
? ? interface ens37
? ? virtual_router_id 51
? ? priority 90
? ? advert_int 1
? ? authentication {
? ? ? ? auth_type PASS
? ? ? ? auth_pass 1111
? ? }
? ? virtual_ipaddress {
? ? ? ? 192.168.43.199
? ? }
}
vrrp_instance LAN_GATEWAY {
? ? state BACKUP
? ? interface ens33
? ? virtual_router_id 52
? ? priority 90
? ? advert_int 1
? ? authentication {
? ? ? ? auth_type PASS
? ? ? ? auth_pass 1111
? ? }
? ? virtual_ipaddress {
? ? ? ? 192.168.131.190
? ? }
}
virtual_server 192.168.43.199 80 {
? ? delay_loop 6
? ? lb_algo rr
? ? lb_kind NAT
? ? #persistence_timeout 50
? ? protocol TCP
? ? real_server 192.168.131.92 80 {
? ? ? ? weight 10
? ? ? ? TCP_CHECK {
? ? ? ? ? connect_timeout 3
? ? ? ? ? retry 3
? ? ? ? ? delay_before_retry 3
? ? ? ? ? connect_port 80
? ? ? ? }
? ? }
? ? real_server 192.168.131.93 80 {
? ? ? weight 10
? ? ? TCP_CHECK {
? ? ? connect_timeout 3
? ? ? retry 3
? ? ? delay_before_retry 3
? ? ? connect_port 80
? ? ? }
? ? }
}
[root@DR02-BACKUP keepalived]#
4.keepalived服務腳本調整與更改日志路徑
執(zhí)行機器:DR01與DR02-BACKUP
[1]服務腳本修正:
[root@DR01 ~]# cat /usr/lib/systemd/system/keepalived.service
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network-online.target
[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
#KillMode=process? 調整的這里,注釋掉
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@DR01 ~]#
[root@DR01 ~]# systemctl daemon-reload
[root@DR02-BACKUP ~]#? cat /usr/lib/systemd/system/keepalived.service
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network-online.target
[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
#KillMode=process? 調整的這里,注釋掉
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@DR02-BACKUP ~]#
[root@DR02-BACKUP ~]# systemctl daemon-reload
[2]日志路徑更改
[root@DR01 ~]#? grep 'local0.*' /etc/rsyslog.conf
local0.*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /var/log/keepalived.log
[root@DR01 ~]# grep 'KEEPALIVED_OPTIONS' /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -d -S 0"
[root@DR01 ~]# systemctl start rsyslog
[root@DR01 ~]#? systemctl status rsyslog
● rsyslog.service - System Logging Service
? Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
? Active: active (running) since Mon 2020-08-03 13:49:07 CST; 1h 9min ago
? ? Docs: man:rsyslogd(8)
? ? ? ? ? http://www.rsyslog.com/doc/
Main PID: 999 (rsyslogd)
? CGroup: /system.slice/rsyslog.service
? ? ? ? ? └─999 /usr/sbin/rsyslogd -n
Aug 03 13:49:07 DR01 systemd[1]: Starting System Logging Service...
Aug 03 13:49:07 DR01 rsyslogd[999]:? [origin software="rsyslogd" swVersion="8.24.0-38.el7" x-pid="999" x-info="http://www.rsyslog.com"] start
Aug 03 13:49:07 DR01 systemd[1]: Started System Logging Service.
[root@DR01 ~]# systemctl enable rsyslog
[root@DR01 ~]#
[root@DR02-BACKUP ~]# grep 'local0.*' /etc/rsyslog.conf
local0.*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /var/log/keepalived.log
[root@DR02-BACKUP ~]# grep 'KEEPALIVED_OPTIONS' /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -d -S 0"
[root@DR02-BACKUP ~]# systemctl start rsyslog
[root@DR02-BACKUP ~]# systemctl status rsyslog
● rsyslog.service - System Logging Service
? Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
? Active: active (running) since Mon 2020-08-03 12:17:59 CST; 2h 37min ago
? ? Docs: man:rsyslogd(8)
? ? ? ? ? http://www.rsyslog.com/doc/
Main PID: 999 (rsyslogd)
? CGroup: /system.slice/rsyslog.service
? ? ? ? ? └─999 /usr/sbin/rsyslogd -n
Aug 03 12:17:59 DR02-BACKUP systemd[1]: Starting System Logging Service...
Aug 03 12:17:59 DR02-BACKUP rsyslogd[999]:? [origin software="rsyslogd" swVersion="8.24.0-38.el7" x-pid="999" x-info="http://www.rsyslog.com"] start
Aug 03 12:17:59 DR02-BACKUP systemd[1]: Started System Logging Service.
[root@DR02-BACKUP ~]# systemctl enable rsyslog
[root@DR02-BACKUP ~]#
5.nginx的安裝以便于測試
執(zhí)行機器:RS01與RS02
[root@RS01 wordpress]# yum install -y nginx
[root@RS01 opt]# curl http://192.168.43.92/wordpress/index.html
This is RS01!!
[root@RS02 wordpress]# yum install -y nginx
[root@RS02 opt]# curl http://192.168.43.93/wordpress/index.html
This is RS02!!
(二)服務的啟動與自啟
1.keepalived添加開機自啟
[root@DR01 ~]# systemctl start keepalived
[root@DR01 ~]# systemctl enable keepalived
[root@DR02 ~]# systemctl start keepalived
[root@DR02 ~]# systemctl enable keepalived
2.nginx添加開機自啟
[root@RS01 opt]# systemctl start nginx
[root@RS01 opt]# systemctl enable nginx
[root@RS02 opt]# systemctl start nginx
[root@RS02 opt]# systemctl enable nginx
(三)配置完成后的分析與觀察
DR01與DR02-BACKUP的情況:
觀察vip的產生及負載均衡情況:
[root@DR01 /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host
? ? ? valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:09:5e:dd brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.131.90/24 brd 192.168.131.255 scope global ens33
? ? ? valid_lft forever preferred_lft forever
? ? inet 192.168.131.190/32 scope global ens33? # 觀察:產生VIP
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5edd/64 scope link
? ? ? valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:09:5e:e7 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.43.90/24 brd 192.168.43.255 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet 192.168.43.199/32 scope global ens37? # 觀察:產生VIP
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5ee7/64 scope link
? ? ? valid_lft forever preferred_lft forever
[root@DR01 /]# 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.43.199:80 rr
? -> 192.168.131.92:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
? -> 192.168.131.93:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
[root@DR01 /]#
[root@DR02-BACKUP keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host
? ? ? valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:e4:23:8e brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.131.91/24 brd 192.168.131.255 scope global ens33
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fee4:238e/64 scope link
? ? ? valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:e4:23:98 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.43.91/24 brd 192.168.43.255 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fee4:2398/64 scope link
? ? ? valid_lft forever preferred_lft forever
[root@DR02-BACKUP keepalived]# 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.43.199:80 rr
? -> 192.168.131.92:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
? -> 192.168.131.93:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
[root@DR02-BACKUP keepalived]#
(四)測試
我們在IP為192.168.43.110的客戶端進行測試調度情況:
[root@harbor ~]# while true ; do? curl http://192.168.43.199/wordpress/index.html ; sleep 2; done
This is RS01!!
This is RS02!!
This is RS01!!
This is RS02!!
This is RS01!!
This is RS02!!
This is RS01!!
This is RS02!!
This is RS01!!
This is RS02!!
^C
(五)故障模擬及日志分析
1.模擬DR01關閉keepalived服務
DR01分析:
[root@DR01 /]# systemctl stop keepalived
[root@DR01 /]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
? -> RemoteAddress:Port? ? ? ? ? Forward Weight ActiveConn InActConn
[root@DR01 /]# tail -f /var/log/keepalived.log
Aug? 3 21:25:27 DR01 Keepalived[2801]: Stopping
Aug? 3 21:25:27 DR01 Keepalived_healthcheckers[2802]: Removing service [192.168.131.92]:80 from VS [192.168.43.199]:80
Aug? 3 21:25:27 DR01 Keepalived_healthcheckers[2802]: Removing service [192.168.131.93]:80 from VS [192.168.43.199]:80
Aug? 3 21:25:27 DR01 Keepalived_healthcheckers[2802]: Stopped? ? # 已經關閉
Aug? 3 21:25:27 DR01 Keepalived_vrrp[2803]: VRRP_Instance(VI_1) sent 0 priority
Aug? 3 21:25:27 DR01 Keepalived_vrrp[2803]: VRRP_Instance(VI_1) removing protocol VIPs.
Aug? 3 21:25:27 DR01 Keepalived_vrrp[2803]: VRRP_Instance(LAN_GATEWAY) sent 0 priority
Aug? 3 21:25:27 DR01 Keepalived_vrrp[2803]: VRRP_Instance(LAN_GATEWAY) removing protocol VIPs.
Aug? 3 21:25:28 DR01 Keepalived_vrrp[2803]: Stopped
Aug? 3 21:25:28 DR01 Keepalived[2801]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
[root@DR01 /]# ip a? # vip發(fā)生漂移
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host
? ? ? valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:09:5e:dd brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.131.90/24 brd 192.168.131.255 scope global ens33
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5edd/64 scope link
? ? ? valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:09:5e:e7 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.43.90/24 brd 192.168.43.255 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5ee7/64 scope link
? ? ? valid_lft forever preferred_lft forever
[root@DR01 /]#
DR02-BACKUP分析:
[root@DR02-BACKUP keepalived]# 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.43.199:80 rr
? -> 192.168.131.92:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
? -> 192.168.131.93:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
[root@DR02-BACKUP keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host
? ? ? valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:e4:23:8e brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.131.91/24 brd 192.168.131.255 scope global ens33
? ? ? valid_lft forever preferred_lft forever
? ? inet 192.168.131.190/32 scope global ens33? ? # VIP漂移過來
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fee4:238e/64 scope link
? ? ? valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:e4:23:98 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.43.91/24 brd 192.168.43.255 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet 192.168.43.199/32 scope global ens37? ? ? # VIP漂移過來
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fee4:2398/64 scope link
? ? ? valid_lft forever preferred_lft forever
[root@DR02-BACKUP keepalived]#
[root@DR02-BACKUP ~]# tail -f /var/log/keepalived.log
Aug? 3 21:25:28 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug? 3 21:25:28 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) Transition to MASTER STATE
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) setting protocol VIPs.
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens37 for 192.168.43.199
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) Entering MASTER STATE
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) setting protocol VIPs.
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) Sending/queueing gratuitous ARPs on ens33 for 192.168.131.190
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:25:29 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:25:34 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:25:34 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens37 for 192.168.43.199
Aug? 3 21:25:34 DR02-BACKUP Keepalived_vrrp[2741]: Sending gratuitous ARP on ens37 for 192.168.43.199
2.模擬DR01關閉恢復開啟keepalived服務
[1]DR01分析:
[root@DR01 /]# systemctl start keepalived
[root@DR01 /]# 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.43.199:80 rr
? -> 192.168.131.92:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
? -> 192.168.131.93:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
[root@DR01 /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host
? ? ? valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:09:5e:dd brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.131.90/24 brd 192.168.131.255 scope global ens33
? ? ? valid_lft forever preferred_lft forever
? ? inet 192.168.131.190/32 scope global ens33? ? # 注意:vip漂移還原
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5edd/64 scope link
? ? ? valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
? ? link/ether 00:0c:29:09:5e:e7 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.43.90/24 brd 192.168.43.255 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet 192.168.43.199/32 scope global ens37? ? ? # 注意:vip漂移還原
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5ee7/64 scope link
? ? ? valid_lft forever preferred_lft forever
[root@DR01 /]#
[root@DR01 /]# tail -f /var/log/keepalived.log
Aug? 3 21:30:25 DR01 Keepalived[2854]: Starting Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
Aug? 3 21:30:25 DR01 Keepalived[2854]: Opening file '/etc/keepalived/keepalived.conf'.
Aug? 3 21:30:25 DR01 Keepalived[2855]: Starting Healthcheck child process, pid=2856
Aug? 3 21:30:25 DR01 Keepalived[2855]: Starting VRRP child process, pid=2857
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Initializing ipvs
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Opening file '/etc/keepalived/keepalived.conf'.
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ------< Global definitions >------
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Router ID = LVS_01
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Default interface = eth0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: LVS flush = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP IPv4 mcast group = 224.0.0.18
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP IPv6 mcast group = ff02::12
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP delay = 5
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP refresh timer = 0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP refresh repeat = 1
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP lower priority delay = 4294
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP lower priority repeat = -1
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Send advert after receive lower priority advert = true
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Send advert after receive higher priority advert = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous ARP interval = 0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Gratuitous NA interval = 0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP default protocol version = 2
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Iptables input chain = INPUT
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Using ipsets = true
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ipset IPv4 address set = keepalived
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ipset IPv6 address set = keepalived6
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ipset IPv6 address,iface set = keepalived_if6
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP check unicast_src = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP skip check advert addresses = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP strict mode = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP process priority = 0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VRRP don't swap = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Checker process priority = 0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Checker don't swap = false
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: SNMP keepalived disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: SNMP checker disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: SNMP RFCv2 disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: SNMP RFCv3 disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: SNMP traps disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: SNMP socket = default (unix:/var/agentx/master)
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Network namespace = (default)
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Script security disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Default script uid:gid 0:0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ------< SSL definitions >------
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Using autogen SSL context
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ------< LVS Topology >------
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: System is compiled with LVS v1.2.1
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: VIP = 192.168.43.199, VPORT = 80
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Address family = inet
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? delay_loop = 6, lb_algo = rr
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Hashed = disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? flag-1 = disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? flag-2 = disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? flag-3 = disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? One packet scheduling = disabled
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? protocol = TCP
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? alpha is OFF, omega is OFF
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? quorum = 1, hysteresis = 0
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? lb_kind = NAT
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? RIP = 192.168.131.92, RPORT = 80, WEIGHT = 10
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? RIP = 192.168.131.93, RPORT = 80, WEIGHT = 10
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: ------< Health checkers >------
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: [192.168.131.92]:80
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Keepalive method = TCP_CHECK
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Connection dest = [192.168.131.92]:80
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Connection timeout = 3
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? ? Retry count = 3
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? ? Retry delay = 3
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: [192.168.131.93]:80
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Keepalive method = TCP_CHECK
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Connection dest = [192.168.131.93]:80
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? Connection timeout = 3
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? ? Retry count = 3
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]:? ? Retry delay = 3
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Activating healthchecker for service [192.168.43.199]:80
Aug? 3 21:30:25 DR01 Keepalived_healthcheckers[2856]: Activating healthchecker for service [192.168.43.199]:80
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Registering Kernel netlink reflector
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Registering Kernel netlink command channel
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Registering gratuitous ARP shared channel
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Opening file '/etc/keepalived/keepalived.conf'.
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP_Instance(VI_1) removing protocol VIPs.
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP_Instance(LAN_GATEWAY) removing protocol VIPs.
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ------< Global definitions >------
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Router ID = LVS_01
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Default interface = eth0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: LVS flush = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP IPv4 mcast group = 224.0.0.18
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP IPv6 mcast group = ff02::12
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP delay = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP refresh timer = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP refresh repeat = 1
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP lower priority delay = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP lower priority repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Send advert after receive lower priority advert = true
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Send advert after receive higher priority advert = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous ARP interval = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Gratuitous NA interval = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP default protocol version = 2
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Iptables input chain = INPUT
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Using ipsets = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ipset IPv4 address set = keepalived
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ipset IPv6 address set = keepalived6
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ipset IPv6 address,iface set = keepalived_if6
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP check unicast_src = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP skip check advert addresses = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP strict mode = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP process priority = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP don't swap = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Checker process priority = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Checker don't swap = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: SNMP keepalived disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: SNMP checker disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: SNMP RFCv2 disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: SNMP RFCv3 disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: SNMP traps disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: SNMP socket = default (unix:/var/agentx/master)
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Network namespace = (default)
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Script security disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Default script uid:gid 0:0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ------< VRRP Topology >------
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP Instance = VI_1
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Using VRRPv2
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Want State = MASTER
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Running on device = ens37
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Skip checking advert IP addresses = no
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Enforcing strict VRRP compliance = no
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Using src_ip = 192.168.43.90
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP delay = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP refresh timer = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP refresh repeat = 1
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP lower priority delay = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP lower priority repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Send advert after receive lower priority advert = true
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Send advert after receive higher priority advert = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Virtual Router ID = 51
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Priority = 100
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Advert interval = 1 sec
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Accept enabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Promote_secondaries disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Authentication type = SIMPLE_PASSWORD
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Password = 1111
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Virtual IP = 1
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? ? 192.168.43.199/32 dev ens37 scope global
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP Instance = LAN_GATEWAY
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Using VRRPv2
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Want State = MASTER
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Running on device = ens33
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Skip checking advert IP addresses = no
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Enforcing strict VRRP compliance = no
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Using src_ip = 192.168.131.90
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP delay = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP refresh timer = 0
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP refresh repeat = 1
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP lower priority delay = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Gratuitous ARP lower priority repeat = 5
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Send advert after receive lower priority advert = true
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Send advert after receive higher priority advert = false
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Virtual Router ID = 52
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Priority = 100
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Advert interval = 1 sec
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Accept enabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Promote_secondaries disabled
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Authentication type = SIMPLE_PASSWORD
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Password = 1111
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? Virtual IP = 1
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]:? ? 192.168.131.190/32 dev ens33 scope global
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ------< NIC >------
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Name = ens33
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: index = 2
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: IPv4 address = 192.168.131.90
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: IPv6 address = fe80::20c:29ff:fe09:5edd
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: MAC = 00:0c:29:09:5e:dd
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: is UP
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: is RUNNING
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: MTU = 1500
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: HW Type = ETHERNET
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: ------< NIC >------
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Name = ens37
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: index = 3
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: IPv4 address = 192.168.43.90
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: IPv6 address = fe80::20c:29ff:fe09:5ee7
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: MAC = 00:0c:29:09:5e:e7
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: is UP
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: is RUNNING
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: MTU = 1500
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: HW Type = ETHERNET
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: Using LinkWatch kernel netlink reflector...
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(12,13)]
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug? 3 21:30:25 DR01 Keepalived_vrrp[2857]: VRRP_Instance(LAN_GATEWAY) Transition to MASTER STATE
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: VRRP_Instance(VI_1) setting protocol VIPs.
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens37 for 192.168.43.199
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: VRRP_Instance(LAN_GATEWAY) Entering MASTER STATE
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: VRRP_Instance(LAN_GATEWAY) setting protocol VIPs.
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: VRRP_Instance(LAN_GATEWAY) Sending/queueing gratuitous ARPs on ens33 for 192.168.131.190
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:26 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens37 for 192.168.43.199
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens37 for 192.168.43.199
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: VRRP_Instance(LAN_GATEWAY) Sending/queueing gratuitous ARPs on ens33 for 192.168.131.190
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
Aug? 3 21:30:31 DR01 Keepalived_vrrp[2857]: Sending gratuitous ARP on ens33 for 192.168.131.190
[root@DR02-BACKUP ~]# tail -f /var/log/keepalived.log
Aug? 3 21:30:25 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) Received advert with higher priority 100, ours 90
Aug? 3 21:30:25 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) Entering BACKUP STATE
Aug? 3 21:30:25 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(VI_1) removing protocol VIPs.
Aug? 3 21:30:25 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) Received advert with higher priority 100, ours 90
Aug? 3 21:30:25 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) Entering BACKUP STATE
Aug? 3 21:30:25 DR02-BACKUP Keepalived_vrrp[2741]: VRRP_Instance(LAN_GATEWAY) removing protocol VIPs
3.模擬RS01上nginx關閉時的情況
[root@RS02 opt]# systemctl stop nginx
[root@RS02 opt]#
[root@DR01 /]# 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.43.199:80 rr
? -> 192.168.131.92:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
? # 同樣被移除
[root@DR01 ~]# tail -f /var/log/keepalived.log
Aug? 3 21:33:58 DR01 Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:01 DR01 Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:04 DR01 Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:07 DR01 Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:07 DR01 Keepalived_healthcheckers[2856]: Check on service [192.168.131.93]:80 failed after 3 retry.
Aug? 3 21:34:07 DR01 Keepalived_healthcheckers[2856]: Removing service [192.168.131.93]:80 from VS [192.168.43.199]:80
[root@DR02-BACKUP ~]# tail -f /var/log/keepalived.log
Aug? 3 21:33:58 DR02-BACKUP Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:01 DR02-BACKUP Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:04 DR02-BACKUP Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:07 DR02-BACKUP Keepalived_healthcheckers[2856]: TCP connection to [192.168.131.93]:80 failed.
Aug? 3 21:34:07 DR02-BACKUP Keepalived_healthcheckers[2856]: Check on service [192.168.131.93]:80 failed after 3 retry.
Aug? 3 21:34:07 DR02-BACKUP Keepalived_healthcheckers[2856]: Removing service [192.168.131.93]:80 from VS [192.168.43.199]:80
[root@DR02-BACKUP keepalived]# 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.43.199:80 rr
? -> 192.168.131.92:80? ? ? ? ? ? Masq? ? 10? ? 0? ? ? ? ? 0
[root@DR02-BACKUP keepalived]#
[root@harbor ~]# while true ; do? curl http://192.168.43.199/wordpress/index.html ; sleep 2; done
This is RS01!!
This is RS01!!
This is RS01!!
This is RS01!!
This is RS01!!
^C
[root@harbor ~]#