Centos

keepalived 註冊失敗但不會進行故障轉移

  • December 12, 2017

我正在執行 2 個共享公共 IP(Server1 和 Server2)的 keepalived 伺服器。Server1 是主伺服器,只要 haproxy 死了,Server2 就應該接管。如果 Server1 重新啟動,Server2 應該釋放 vIP 並讓 Server1 再次接管。

我已經設法使用下面的 2 個配置來執行它,但是,我最近注意到它停止工作了。

伺服器執行 CentOS 7 並已全面更新。如果我在 Server1 上手動終止 keepalived,它會故障轉移到 Server2,當 keepalived 恢復時,Server1 會再次接管。但是,如果我殺死 haproxy,keepalived 會記錄 check_haproxy 檢查失敗,但不會進行故障轉移。

只是為了確保它不是 FW 或 SELinux,我刪除了所有 IPtables 規則並禁用了 SELinux。

配置是:

伺服器1

global_defs {
   # Keepalived process identifier
   # Probably should be unique: http://www.keepalived.org/LVS-NAT-Keepalived-HOWTO.html
   lvs_id haproxy_DH
}
# Script used to check if HAProxy is running
vrrp_script check_haproxy {
   script "killall -0 haproxy"
   interval 2
   weight 2
}
# Virtual interface
# The priority specifies the order in which the assigned interface to take over in a failover
vrrp_instance VI_01 {
   state EQUAL
   interface eno16777984
   virtual_router_id 51
   notify /etc/keepalived/notify.sh
   priority 100
   # The virtual ip address shared between the two loadbalancers
   virtual_ipaddress {
       10.9.17.20
       10.9.17.19
   }
   track_script {
       check_haproxy
   }
}

伺服器2

global_defs {
   # Keepalived process identifier
   # Probably should be unique: http://www.keepalived.org/LVS-NAT-Keepalived-HOWTO.html
   lvs_id haps2a

# Script used to check if HAProxy is running
vrrp_script check_haproxy {
   script "killall -0 haproxy"
   interval 2
   weight 2
}
# Virtual interface
# The priority specifies the order in which the assigned interface to take over in a failover
vrrp_instance VI_01 {
   state EQUAL
   interface eno16777984
   virtual_router_id 51
   notify /etc/keepalived/notify.sh
   priority 100
   # The virtual ip address shared between the two loadbalancers
   virtual_ipaddress {
       10.9.17.20
       10.9.17.19
   }
   track_script {
       check_haproxy
   }
}

我找不到任何解釋state EQUAL. 我通常將初始狀態定義為BACKUP並讓選舉過程選擇主實例。

我將您的配置文件複製到實驗室環境中,發現global_defsServer2 的 keepalived.conf 中缺少右括號。但是,儘管沒有字元,故障轉移似乎執行良好。

請檢查是否存在tcpdump -i eno16777984 vrrp不相關的 VRRP 數據包VRID=51。或嘗試將 更改virtual_router_id為另一個數字。由於 VRRP 數據包被發送到多播地址224.0.0.18,因此網路中的每個虛擬 IP 都必須使用唯一的VRID

另外,如果你打算讓Server1接管虛擬IP,我建議你priority 101在它的vrrp_instance. RFC57986.4.3 節。Master說如果Server1的IP地址大於Server2的IP地址,並且兩台伺服器的優先級相同,則Server1贏得選舉並獲得虛擬IP。但是,keepalived似乎只比較優先級。


**編輯:**實際上,我忘記在第二次測試中刪除右括號。實際上,keepalived 啟動過程忽略了缺少的大括號,但是在執行時故障轉移不起作用。

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