Linux

Keepalived 在 master 重啟時失去 VIP

  • August 17, 2014

我有兩台伺服器執行 Keepalived 1.2.7,主機名leftright. 以下是配置:

# keepalived.conf on left
vrrp_instance VI_1 {
   state MASTER
   interface eth1
   virtual_router_id 51
   priority 160
   advert_int 1
   virtual_ipaddress {
       10.10.10.200
   }
}

# keepalived.conf on right
vrrp_instance VI_1 {
   state MASTER
   interface eth1
   virtual_router_id 51
   priority 100
   advert_int 1
   virtual_ipaddress {
       10.10.10.200
   }
}

現在我重新啟動left。以下是系統日誌的外觀,交錯和註釋:

>> started servers <<
Aug 15 19:07:32 left Keepalived[4041]: Starting VRRP child process, pid=4043
Aug 15 19:07:32 right Keepalived[4041]: Starting VRRP child process, pid=4043
Aug 15 19:07:33 left Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:07:33 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:07:33 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Received higher prio advert
Aug 15 19:07:33 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering BACKUP STATE
Aug 15 19:07:34 left Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering MASTER STATE
>> left has 10.10.10.200 <<

>> powered off left <<
Aug 15 19:08:25 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:08:26 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering MASTER STATE
>> right has 10.10.10.200 <<

>> powered on left <<
Aug 15 19:08:58 left Keepalived[1027]: Starting VRRP child process, pid=1029
Aug 15 19:08:59 left Keepalived_vrrp[1029]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:09:00 left Keepalived_vrrp[1029]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug 15 19:09:00 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Received higher prio advert
Aug 15 19:09:00 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering BACKUP STATE
>> neither has 10.10.10.200 <<

我期待left在它恢復時收回 10.10.10.200。為什麼不呢?我怎樣才能修改我keepalived.conf的 s 以便它這樣做?

您希望“右側”上的配置如下所示:

vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 100
advert_int 1
virtual_ipaddress {
   10.10.10.200
}

BACKUP關鍵字告訴 keepalived在可用時故障回復到MASTER

以下配置有效~~,儘管我仍然很好奇為什麼我的問題中的那個沒有~~.

# keepalived.conf on left
vrrp_instance VI_1 {
   state BACKUP
   interface eth1
   virtual_router_id 51
   priority 160
   advert_int 1
   preempt_delay 15
   virtual_ipaddress {
       10.10.10.200
   }
}

# keepalived.conf on right
vrrp_instance VI_1 {
   state BACKUP
   interface eth1
   virtual_router_id 51
   priority 100
   advert_int 1
   preempt_delay 15
   virtual_ipaddress {
       10.10.10.200
   }
}

此配置表示在更高優先級的機器上線 15 秒後重新選擇一個新的主機。郵件列表上preempt_delay有該選項的說明。

這種配置的一個問題:如果兩台機器都宕機了,當它們恢復時都不會聲明 10.10.10.200。(這是由於 Vagrant 所做的網路自動配置。)

引用自:https://serverfault.com/questions/620789