高可用keepalived的搶佔式與非搶佔式
阿新 • • 發佈:2020-09-11
#由於節點1的優先順序高於節點2,所以VIP在節點1上面
[root@lb01 ~]# ip addr | grep 10.0.0.3
inet 10.0.0.3/32 scope global eth0
[root@lb02 ~]# ip addr | grep 10.0.0.3
[root@lb01 ~]# systemctl stop keepalived
#節點2聯絡不上節點1,主動接管VIP
[root@lb02 ~]# ip addr | grep 10.0.0.3
inet 10.0.0.3/32 scope global eth0
[root@lb01 ~]# systemctl start keepalived
#由於節點1的優先順序高於節點2,所以恢復節點1之後,vip又漂回節點1
[root@lb01 ~]# ip addr | grep 10.0.0.3
inet 10.0.0.3/32 scope global eth0
[root@lb01 ~]# vim /etc/keepalived/keepalived.conf
... ...
vrrp_instance VI_1 {
state BACKUP
nopreempt
......
}
[root@lb01 ~]# systemctl restart keepalived
[root@lb02 ~]# vim /etc/keepalived/keepalived.conf
... ...
vrrp_instance VI_1 {
state BACKUP
nopreempt
......
}
[root@lb02 ~]# systemctl restart keepalived
1.兩臺機器節點狀態都要改成 BACKUP
2.兩個節點都要加上 nopreempt
3.優先順序不需要改變
#配置hosts
10.0.0.3 linux.blog.com
#訪問頁面
http://linux.blog.com/
#節點測試
[root@lb01 ~]# ip addr | grep 10.0.0.3
inet 10.0.0.3/32 scope global eth0
#訪問網站,並且windows檢視mac地址測試
C:\Users\11764>arp -a
VIP VMAC
10.0.0.3 00-0c-29-d7-bc-2c 動態
10.0.0.4 00-0c-29-d7-bc-2c 動態
10.0.0.5 00-0c-29-89-2f-10 動態
#關閉節點1keepalived
[root@lb01 ~]# systemctl stop keepalived.service
[root@lb02 ~]# ip addr | grep 10.0.0.3
inet 10.0.0.3/32 scope global eth0
#訪問網站,並且windows檢視mac地址測試
C:\Users\11764>arp -a
VIP VMAC
10.0.0.3 00-0c-29-89-2f-10 動態
10.0.0.4 00-0c-29-d7-bc-2c 動態
10.0.0.5 00-0c-29-89-2f-10 動態