拓?fù)浣榻B:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?RS01 (real-server)
[DR01 + DR02-BACKUP] keepalived (Director-s) --> |? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | -> Client
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?RS02 (real-server)
DR02-BACKUP : 192.168.43.91
DR01 : 192.168.43.90
RS01? : 192.168.43.92
RS02 : 192.168.43.93
Client : 192.168.43.110
vip? ? ? : 192.168.43.166
網(wǎng)關(guān)? ? :192.168.43.1
附:這里演示的是在同一網(wǎng)段的情況,TUN支持跨網(wǎng)段操作。
參閱:
http://www.atomicgain.com/keepalived-lvs-tun/
報(bào)文請(qǐng)求過(guò)程分析
Ip Tunnel模式下,客戶(hù)端的請(qǐng)求包到達(dá)負(fù)載均衡器的虛擬服務(wù)IP端口后,負(fù)載均衡器不會(huì)改寫(xiě)請(qǐng)求包的IP和端口,但是會(huì)在數(shù)據(jù)包IP層外面再封裝一個(gè)IP層,然后將數(shù)據(jù)包轉(zhuǎn)發(fā);
真實(shí)服務(wù)器收到請(qǐng)求后,會(huì)先將外面封裝的Ip Tunnel頭去掉,然后處理里面實(shí)際的請(qǐng)求報(bào)文;
與DR模式類(lèi)似,響應(yīng)包也不再經(jīng)過(guò)LVS,而是直接返回給客戶(hù)端。所以Ip Tunnel模式的轉(zhuǎn)發(fā)效率雖然弱于DR,但是強(qiáng)于NAT。
為什么要用Ip Tunnel模式?
既然Ip Tunnel模式的性能比不上DR,那為什么還要用它呢? 因?yàn)樗梢钥缇W(wǎng)段轉(zhuǎn)發(fā)!
Ip Tunnel模式最大的優(yōu)點(diǎn)就在于它可以跨網(wǎng)段轉(zhuǎn)發(fā),沒(méi)有DR和NAT模式的組網(wǎng)限制。
這在部署上帶來(lái)的很大的靈活性,甚至還可以跨機(jī)房轉(zhuǎn)發(fā),不過(guò)不建議這樣使用,一是會(huì)帶來(lái)跨機(jī)房間的流量,提高了成本;
二是跨機(jī)房轉(zhuǎn)發(fā)必然會(huì)要在RS機(jī)房上綁定LVS機(jī)房的VIP,這有可能會(huì)被運(yùn)營(yíng)商的防火墻認(rèn)為是IP偽造請(qǐng)求而攔截。
參閱:
https://www.vxiaobai.com/article/544/
(一)ipvsadm與keepalived安裝配置
1.開(kāi)啟ip_forward轉(zhuǎn)發(fā)功能及ipip加載
執(zhí)行機(jī)器:DR01與DR02-BACKUP
[root@DR01 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@DR01 ~]# cat /proc/sys/net/ipv4/ip_forward
1
[root@DR01 ~]# modprobe ipip
[root@DR01 ~]# lsmod | grep ipip
ipip? ? ? ? ? ? ? ? ? 13465? 0
tunnel4? ? ? ? ? ? ? ? 13252? 1 ipip
ip_tunnel? ? ? ? ? ? ? 25163? 1 ipip
[root@DR01 ~]#
[root@DR02-BACKUP ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@DR02-BACKUP ~]# cat /proc/sys/net/ipv4/ip_forward
1
[root@DR02-BACKUP keepalived]# lsmod | grep ipip
ipip? ? ? ? ? ? ? ? ? 13465? 0
tunnel4? ? ? ? ? ? ? ? 13252? 1 ipip
ip_tunnel? ? ? ? ? ? ? 25163? 1 ipip
[root@DR02-BACKUP keepalived]#
2.ipvsadmin與keepalived安裝
執(zhí)行機(jī)器: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 {
? notification_email {
? ? #acassen@firewall.loc
? ? #failover@firewall.loc
? ? #sysadmin@firewall.loc
? }
? #notification_email_from Alexandre.Cassen@firewall.loc
? #smtp_server 192.168.200.1
? #smtp_connect_timeout 30
? router_id LVS_ds1
? vrrp_skip_check_adv_addr
? #vrrp_strict
? vrrp_garp_interval 0
? vrrp_gna_interval 0
}
vrrp_instance VI_1 {
? ? state MASTER
? ? interface ens37
? ? virtual_router_id 50
? ? priority 100
? ? advert_int 1
? ? authentication {
? ? ? ? auth_type PASS
? ? ? ? auth_pass 1111
? ? }
? ? virtual_ipaddress {
? ? ? ? 192.168.43.166
? ? }
}
virtual_server 192.168.43.166 80 {
? ? delay_loop 6
? ? lb_algo wrr
? ? lb_kind TUN
? ? # persistence_timeout 0
? ? protocol TCP
? ? real_server 192.168.43.92 80 {
? ? ? ? weight 1
? ? ? ? TCP_CHECK {
? ? ? ? ? ? connect_timeout 3
? ? ? ? ? ? delay_before_retry 3
? ? ? ? ? ? connect_port 80
? ? ? ? }
? ? }
? ? real_server 192.168.43.93 80 {
? ? ? ? weight 1
? ? ? ? TCP_CHECK {
? ? ? ? ? ? connect_timeout 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 {
? notification_email {
? ? #acassen@firewall.loc
? ? #failover@firewall.loc
? ? #sysadmin@firewall.loc
? }
? #notification_email_from Alexandre.Cassen@firewall.loc
? #smtp_server 192.168.200.1
? #smtp_connect_timeout 30
? router_id LVS_ds1
? vrrp_skip_check_adv_addr
? #vrrp_strict
? vrrp_garp_interval 0
? vrrp_gna_interval 0
}
vrrp_instance VI_1 {
? ? state BACKUP
? ? interface ens37
? ? virtual_router_id 50
? ? priority 90
? ? advert_int 1
? ? authentication {
? ? ? ? auth_type PASS
? ? ? ? auth_pass 1111
? ? }
? ? virtual_ipaddress {
? ? ? ? 192.168.43.166
? ? }
}
virtual_server 192.168.43.166 80 {
? ? delay_loop 6
? ? lb_algo wrr
? ? lb_kind TUN
? ? # persistence_timeout 0
? ? protocol TCP
? ? real_server 192.168.43.92 80 {
? ? ? ? weight 1
? ? ? ? TCP_CHECK {
? ? ? ? ? ? connect_timeout 3
? ? ? ? ? ? delay_before_retry 3
? ? ? ? ? ? connect_port 80
? ? ? ? }
? ? }
? ? real_server 192.168.43.93 80 {
? ? ? ? weight 1
? ? ? ? TCP_CHECK {
? ? ? ? ? ? connect_timeout 3
? ? ? ? ? ? delay_before_retry 3
? ? ? ? ? ? connect_port 80
? ? ? ? }
? ? }
}
[root@DR02-BACKUP keepalived]#
4.keepalived服務(wù)腳本調(diào)整與更改日志路徑
執(zhí)行機(jī)器:DR01與DR02-BACKUP
[1]服務(wù)腳本修正:
[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? 調(diào)整的這里,注釋掉
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? 調(diào)整的這里,注釋掉
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的安裝以便于測(cè)試
執(zhí)行機(jī)器: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!!
(二)服務(wù)的啟動(dòng)與自啟
1.keepalived添加開(kāi)機(jī)自啟
[root@DR01 ~]# systemctl start keepalived
[root@DR01 ~]# systemctl enable keepalived
[root@DR02 ~]# systemctl start keepalived
[root@DR02 ~]# systemctl enable keepalived
2.nginx添加開(kāi)機(jī)自啟
[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的產(chǎn)生及負(fù)載均衡情況:
[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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
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.166/32 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5ee7/64 scope link
? ? ? valid_lft forever preferred_lft forever
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 30
? -> 192.168.43.93:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 29
[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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 0
? -> 192.168.43.93:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 0
[root@DR02-BACKUP keepalived]#
(四)測(cè)試
我們?cè)贗P為192.168.43.110的客戶(hù)端進(jìn)行測(cè)試調(diào)度情況:
[root@harbor ~]# while true ; do? curl http://192.168.43.166/wordpress/index.html ; sleep 2; done
This is RS02!!
This is RS01!!
This is RS02!!
This is RS01!!
This is RS02!!
^C
[root@harbor ~]#
(五)故障模擬及日志分析
1.模擬DR01關(guān)閉keepalived服務(wù)
DR01分析:
[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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 18
? -> 192.168.43.93:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 19
[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 ~]#
[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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
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
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[root@DR01 ~]#
[root@DR01 ~]# tail -f /var/log/keepalived.log
Aug? 3 23:05:22 DR01 Keepalived[1005]: Stopping
Aug? 3 23:05:22 DR01 Keepalived_healthcheckers[1006]: Removing service [192.168.43.92]:80 from VS [192.168.43.166]:80
Aug? 3 23:05:22 DR01 Keepalived_healthcheckers[1006]: Removing service [192.168.43.93]:80 from VS [192.168.43.166]:80
Aug? 3 23:05:22 DR01 Keepalived_healthcheckers[1006]: Stopped
Aug? 3 23:05:22 DR01 Keepalived_vrrp[1007]: VRRP_Instance(VI_1) sent 0 priority
Aug? 3 23:05:22 DR01 Keepalived_vrrp[1007]: VRRP_Instance(VI_1) removing protocol VIPs.
Aug? 3 23:05:23 DR01 Keepalived_vrrp[1007]: Stopped
Aug? 3 23:05:23 DR01 Keepalived[1005]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 0
? -> 192.168.43.93:80? ? ? ? ? ? Tunnel? 1? ? ? 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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
? ? inet 192.168.43.166/32 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fee4:2398/64 scope link
? ? ? valid_lft forever preferred_lft forever
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[root@DR02-BACKUP keepalived]#
[root@DR02-BACKUP ~]#? tail -f /var/log/keepalived.log
Aug? 3 23:05:23 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) setting protocol VIPs.
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens37 for 192.168.43.166
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:24 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:29 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:29 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens37 for 192.168.43.166
Aug? 3 23:05:29 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:29 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:29 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
Aug? 3 23:05:29 DR02-BACKUP Keepalived_vrrp[2875]: Sending gratuitous ARP on ens37 for 192.168.43.166
2.模擬DR01關(guān)閉恢復(fù)開(kāi)啟keepalived服務(wù)
DR01分析:
[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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
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
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[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 ~]# 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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 0
? -> 192.168.43.93:80? ? ? ? ? ? Tunnel? 1? ? ? 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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
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.166/32 scope global ens37
? ? ? valid_lft forever preferred_lft forever
? ? inet6 fe80::20c:29ff:fe09:5ee7/64 scope link
? ? ? valid_lft forever preferred_lft forever
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 0
? -> 192.168.43.93:80? ? ? ? ? ? Tunnel? 1? ? ? 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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN 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
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
? ? link/ipip 0.0.0.0 brd 0.0.0.0
[root@DR02-BACKUP keepalived]# tail -f /var/log/keepalived.log
Aug? 3 23:08:36 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) Received advert with higher priority 100, ours 90
Aug? 3 23:08:36 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) Entering BACKUP STATE
Aug? 3 23:08:36 DR02-BACKUP Keepalived_vrrp[2875]: VRRP_Instance(VI_1) removing protocol VIPs.
3.模擬RS01上nginx關(guān)閉時(shí)的情況
[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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 4
[root@DR01 ~]#
[root@DR01 keepalived]# tail -f /var/log/keepalived.log
Aug? 3 23:10:38 DR01 Keepalived_healthcheckers[2874]: TCP connection to [192.168.43.93]:80 failed.
Aug? 3 23:10:41 DR01 Keepalived_healthcheckers[2874]: TCP connection to [192.168.43.93]:80 failed.
Aug? 3 23:10:41 DR01 Keepalived_healthcheckers[2874]: Check on service [192.168.43.93]:80 failed after 1 retry.
Aug? 3 23:10:41 DR01 Keepalived_healthcheckers[2874]: Removing service [192.168.43.93]:80 from VS [192.168.43.166]: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.166:80 wrr
? -> 192.168.43.92:80? ? ? ? ? ? Tunnel? 1? ? ? 0? ? ? ? ? 0
[root@DR02-BACKUP keepalived]#
[root@DR02-BACKUP keepalived]# tail -f /var/log/keepalived.log
Aug? 3 23:10:38 DR02-BACKUP Keepalived_healthcheckers[2874]: TCP connection to [192.168.43.93]:80 failed.
Aug? 3 23:10:41 DR02-BACKUP Keepalived_healthcheckers[2874]: TCP connection to [192.168.43.93]:80 failed.
Aug? 3 23:10:41 DR02-BACKUP Keepalived_healthcheckers[2874]: Check on service [192.168.43.93]:80 failed after 1 retry.
Aug? 3 23:10:41 DR02-BACKUP Keepalived_healthcheckers[2874]: Removing service [192.168.43.93]:80 from VS [192.168.43.166]:80
[root@harbor ~]# while true ; do? curl http://192.168.43.166/wordpress/index.html ; sleep 2; done
curl: (7) Failed connect to 192.168.43.166:80; Connection refused
This is RS01!!
This is RS01!!
This is RS01!!
This is RS01!!
^C