keepalived无法调用track_script里的脚本,绑定VIP失败

littleboybin 2015-10-17 03:53:01

配置文件内容
[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都已经关闭。求哪位大神帮忙解决下。
...全文
2505 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
-Cristiano- 2018-11-27
  • 打赏
  • 举报
回复
还真是,加个空格就好了,太变态了
jiaxiangwo 2018-08-30
  • 打赏
  • 举报
回复
确实是因为 track_script{ t和{需要加一个空格
cqyy725 2016-08-19
  • 打赏
  • 举报
回复
我不知道你用的什么版本的。虚拟ip配了,你的真实ip呢? 我贴一段我的吧 两台机器,196是虚拟,211 和201是物理机 global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface ens32 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.100.1.196 } } virtual_server 192.100.1.196 8080 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP real_server 192.100.1.211 8080 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 8080 } } } }
sswvf520 2016-07-27
  • 打赏
  • 举报
回复
我遇到你和一样的问题。权限也给了777都不得行。。最后发现是个很吐血的原因 track_script{ t和{需要加一个空格。不能连在一起
u010242127 2015-12-27
  • 打赏
  • 举报
回复
我看到你主备的优先级都是90,把备的改低
牛迁迁 2015-12-26
  • 打赏
  • 举报
回复
把 ,track_script {} 放到 virtual_ipaddress{}的下面。

19,610

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧