keepalived无法调用track_script里的脚本,绑定VIP失败
配置文件内容
[root@localhost ~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
! extra script call demonstration
! scripts are supported in Instance and groups
! declarations.
global_defs {
router_id localhost
}
vrrp_script check_run{
script "/opt/test.sh"
interval 5
}
vrrp_sync_group G1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass admin123
}
track_script{
check_run
}
virtual_ipaddress {
192.168.0.115
}
}
脚本很简单
[root@localhost opt]# ./test.sh
hello
查看日志,无法绑定VIP
Oct 12 10:34:47 localhost Keepalived[1738]: Starting Keepalived v1.2.19 (10/12,2015)
Oct 12 10:34:47 localhost Keepalived[1739]: Starting Healthcheck child process, pid=1741
Oct 12 10:34:47 localhost Keepalived[1739]: Starting VRRP child process, pid=1742
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Netlink reflector reports IP 192.168.0.101 added
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Netlink reflector reports IP fe80::20c:29ff:fe9d:fbb7 added
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Registering Kernel netlink reflector
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Registering Kernel netlink command channel
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Registering gratuitous ARP shared channel
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Opening file '/etc/keepalived/keepalived.conf'.
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Configuration is using : 67259 Bytes
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: Using LinkWatch kernel netlink reflector...
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: VRRP_Instance(VI_1) Entering BACKUP STATE
Oct 12 10:34:47 localhost Keepalived_vrrp[1742]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Netlink reflector reports IP 192.168.0.101 added
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Netlink reflector reports IP fe80::20c:29ff:fe9d:fbb7 added
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Registering Kernel netlink reflector
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Registering Kernel netlink command channel
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Opening file '/etc/keepalived/keepalived.conf'.
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Configuration is using : 9882 Bytes
Oct 12 10:34:47 localhost kernel: IPVS: Registered protocols (TCP, UDP, SCTP, AH, ESP)
Oct 12 10:34:47 localhost kernel: IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
Oct 12 10:34:47 localhost kernel: IPVS: ipvs loaded.
Oct 12 10:34:47 localhost Keepalived_healthcheckers[1741]: Using LinkWatch kernel netlink reflector...
Oct 12 10:34:50 localhost Keepalived_vrrp[1742]: VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 12 10:34:50 localhost Keepalived_vrrp[1742]: VRRP_Group(G1) Syncing instances to MASTER state
Oct 12 10:34:51 localhost Keepalived_vrrp[1742]: VRRP_Instance(VI_1) Entering MASTER STATE
但是如果将keepalived.conf 中的
track_script{
check_run
}
这三行注释掉,又能绑定VIP。查看日志如下:
[root@localhost opt]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
! extra script call demonstration
! scripts are supported in Instance and groups
! declarations.
global_defs {
router_id localhost
}
vrrp_script check_run{
script "/opt/test.sh"
interval 5
}
vrrp_sync_group G1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass admin123
}
# track_script{
# check_run
# }
virtual_ipaddress {
192.168.0.115
}
}
"/etc/keepalived/keepalived.conf" 36L, 572C written
[root@localhost opt]# service keepalived restart
停止 keepalived: [确定]
正在启动 keepalived: [确定]
[root@localhost opt]# tail -30 /var/log/messages
Oct 12 10:34:51 localhost Keepalived_vrrp[1742]: VRRP_Instance(VI_1) Entering MASTER STATE
Oct 12 10:38:57 localhost Keepalived[1739]: Stopping Keepalived v1.2.19 (10/12,2015)
Oct 12 10:38:57 localhost Keepalived_vrrp[1742]: VRRP_Instance(VI_1) sending 0 priority
Oct 12 10:38:58 localhost Keepalived[1787]: Starting Keepalived v1.2.19 (10/12,2015)
Oct 12 10:38:58 localhost Keepalived[1788]: Starting Healthcheck child process, pid=1790
Oct 12 10:38:58 localhost Keepalived[1788]: Starting VRRP child process, pid=1791
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Netlink reflector reports IP 192.168.0.101 added
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Netlink reflector reports IP fe80::20c:29ff:fe9d:fbb7 added
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Registering Kernel netlink reflector
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Registering Kernel netlink command channel
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Registering gratuitous ARP shared channel
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Opening file '/etc/keepalived/keepalived.conf'.
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Configuration is using : 68199 Bytes
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: Using LinkWatch kernel netlink reflector...
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: VRRP_Instance(VI_1) Entering BACKUP STATE
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Netlink reflector reports IP 192.168.0.101 added
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Netlink reflector reports IP fe80::20c:29ff:fe9d:fbb7 added
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Registering Kernel netlink reflector
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Registering Kernel netlink command channel
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Opening file '/etc/keepalived/keepalived.conf'.
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Configuration is using : 9686 Bytes
Oct 12 10:38:58 localhost Keepalived_vrrp[1791]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Oct 12 10:38:58 localhost Keepalived_healthcheckers[1790]: Using LinkWatch kernel netlink reflector...
Oct 12 10:39:01 localhost Keepalived_vrrp[1791]: VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 12 10:39:01 localhost Keepalived_vrrp[1791]: VRRP_Group(G1) Syncing instances to MASTER state
Oct 12 10:39:02 localhost Keepalived_vrrp[1791]: VRRP_Instance(VI_1) Entering MASTER STATE
Oct 12 10:39:02 localhost Keepalived_vrrp[1791]: VRRP_Instance(VI_1) setting protocol VIPs.
Oct 12 10:39:02 localhost Keepalived_vrrp[1791]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.0.115
Oct 12 10:39:02 localhost Keepalived_healthcheckers[1790]: Netlink reflector reports IP 192.168.0.115 added
Oct 12 10:39:07 localhost Keepalived_vrrp[1791]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.0.115
无论换了哪个版本,都是一样。脚本也chmod 777了。iptables和selinux都已经关闭。求哪位大神帮忙解决下。