1. 程式人生 > 實用技巧 >高可用keepalived的搶佔式與非搶佔式

高可用keepalived的搶佔式與非搶佔式

1.兩個節點都啟動

#由於節點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

2.停止主節點

[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

3.重新啟動主節點

[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

4.配置非搶佔式

1)節點一修改

[root@lb01 ~]# vim /etc/keepalived/keepalived.conf 
... ...
vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    ......
}

[root@lb01 ~]# systemctl restart keepalived

2)節點2修改

[root@lb02 ~]# vim /etc/keepalived/keepalived.conf 
... ...
vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    ......
}

[root@lb02 
~]# systemctl restart keepalived

3)配置注意事項

1.兩臺機器節點狀態都要改成 BACKUP
2.兩個節點都要加上 nopreempt
3.優先順序不需要改變

5.訪問頁面測試

#配置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 動態