Keepalived

keepalived track_script 似乎沒有執行

  • October 15, 2014

我希望有人能看到我做錯了什麼並提供幫助以執行 keepalived track_script。

我在主 keepalived 框的 vrrp_instance 上將優先級設置為 101,在故障轉移框上設置為 100。斷開網路或停止主盒子上的 keepalived 會導致 VIP 按預期轉移到輔助盒子。

如果腳本要執行,如果腳本返回成功,我希望它將優先級添加 2。但是 atcpdump始終顯示優先級不變。即使我設置了一個虛假的腳本定義,我也從來沒有在 /var/log/messages 中看到任何關於它的腳本。停止 HAProxy 服務沒有任何效果,我用腳本完成的其他測試表明它永遠不會執行。

輸出tcpdump

172.18.8.2 > 224.0.0.18: vrrp 172.18.8.2 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 101, authtype simple, intvl 1s, length 20, addrs: 172.18.8.4 auth "password"

這是keepalived配置:

global_defs {
  router_id BETAPROXYSLC01
}

vrrp_script chk_haproxy {
       script "killall -0 haproxy"
       interval 2
       weight 2
}

vrrp_instance VI_1 {
   state BACKUP
   interface eth0
   virtual_router_id 51
   priority 101
   advert_int 1
   notify /usr/local/bin/notify.sh
   authentication {
       auth_type PASS
       auth_pass password
   }
   virtual_ipaddress {
       172.18.8.4
   }
  track_script{
       chk_haproxy
   }
}

這是使用“-D -d”啟動keepalived的日誌:

Oct 15 11:50:31 BETAPROXYSLC01 systemd: Starting LVS and VRRP High Availability Monitor...
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived[2702]: Starting Keepalived v1.2.10 (06/10,2014)
Oct 15 11:50:31 BETAPROXYSLC01 systemd: Started LVS and VRRP High Availability Monitor.
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived[2703]: Starting Healthcheck child process, pid=2704
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived[2703]: Starting VRRP child process, pid=2705
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Netlink reflector reports IP 172.18.8.2 added
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Netlink reflector reports IP fe80::215:5dff:fe01:108 added
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Registering Kernel netlink reflector
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Registering Kernel netlink command channel
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Opening file '/etc/keepalived/keepalived.conf'.
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Configuration is using : 6133 Bytes
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: ------< Global definitions >------
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Router ID = BETAPROXYSLC01
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Smtp server connection timeout = 30
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Email notification from = root@betaproxyslc01
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Netlink reflector reports IP 172.18.8.2 added
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Netlink reflector reports IP fe80::215:5dff:fe01:108 added
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Registering Kernel netlink reflector
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Registering Kernel netlink command channel
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Registering gratuitous ARP shared channel
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Opening file '/etc/keepalived/keepalived.conf'.
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Configuration is using : 63558 Bytes
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: ------< Global definitions >------
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Router ID = BETAPROXYSLC01
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Smtp server connection timeout = 30
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Email notification from = root@betaproxyslc01
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP IPv4 mcast group = 224.0.0.18
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP IPv6 mcast group = 224.0.0.18
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: SNMP Trap disabled
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: ------< VRRP Topology >------
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP Instance = VI_1
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Want State = BACKUP
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Runing on device = eth0
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Virtual Router ID = 51
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Priority = 101
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Advert interval = 1sec
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Authentication type = SIMPLE_PASSWORD
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Password = password
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Virtual IP = 1
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: 172.18.8.4/32 dev eth0 scope global
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Generic state transition script = '/usr/local/bin/notify.sh'
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: ------< VRRP Scripts >------
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP Script = chk_haproxy
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Command = /usr/local/bin/chk_haproxy
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Interval = 2 sec
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Timeout = 0 sec
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Weight = 2
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Rise = 1
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Fall = 1
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Status = INIT
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: Using LinkWatch kernel netlink reflector...
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) Entering BACKUP STATE
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: VRRP IPv4 mcast group = 224.0.0.18
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: VRRP IPv6 mcast group = 224.0.0.18
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: SNMP Trap disabled
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: ------< SSL definitions >------
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Using autogen SSL context
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Using LinkWatch kernel netlink reflector...
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) forcing a new MASTER election
Oct 15 11:50:31 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) forcing a new MASTER election
Oct 15 11:50:32 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 15 11:50:33 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) Entering MASTER STATE
Oct 15 11:50:33 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) setting protocol VIPs.
Oct 15 11:50:33 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.18.8.4
Oct 15 11:50:33 BETAPROXYSLC01 avahi-daemon[510]: Registering new address record for 172.18.8.4 on eth0.IPv4.
Oct 15 11:50:33 BETAPROXYSLC01 Keepalived_healthcheckers[2704]: Netlink reflector reports IP 172.18.8.4 added
Oct 15 11:50:38 BETAPROXYSLC01 Keepalived_vrrp[2705]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.18.8.4

我的問題是 keepalived.conf 文件中的拼寫錯誤。

這在 track_script 和左括號之間缺少一個空格:

track_script{
       chk_haproxy
   }

將其更改為此有效:

track_script {
       chk_haproxy
   }

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