Keepalived健康检查脚本在主节点未正常运行问题排查
问题描述
我有两台运行Keepalived的虚拟机,已编写VRRP脚本用于检查容器是否运行,若容器未运行则降低VRRP节点优先级以触发故障转移。但主节点出现脚本被忽略的错误,备份节点的脚本可正常运行并调整权重。附错误日志及配置文件,求问单VRRP场景下该错误原因。
错误日志(主节点)
Starting Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+ Keepalived[57489]: Running on Linux 5.14.0-503.31.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 6 09:41:44 EST 2025 (built for Linux 5.14.0) Keepalived[57489]: Command line: '/usr/sbin/keepalived' '--dont-fork' '-D' Keepalived[57489]: Opening file '/etc/keepalived/keepalived.conf'. Keepalived[57489]: Configuration file /etc/keepalived/keepalived.conf Keepalived[57489]: NOTICE: setting config option max_auto_priority should result in better keepalived performance Keepalived[57489]: Starting VRRP child process, pid=57491 Keepalived_vrrp[57491]: Registering Kernel netlink reflector Keepalived_vrrp[57491]: Registering Kernel netlink command channel Keepalived_vrrp[57491]: Assigned address 10.50.0.52 for interface ens192 Keepalived_vrrp[57491]: (VI_1) ignoring tracked script sc4s_health_check with weights due to address_owner Keepalived_vrrp[57491]: Warning - script sc4s_health_check is not used Keepalived_vrrp[57491]: Registering gratuitous ARP shared channel Keepalived_vrrp[57491]: (VI_1) removing VIPs. Keepalived[57489]: Startup complete systemd[1]: Started LVS and VRRP High Availability Monitor. Keepalived_vrrp[57491]: VRRP sockpool: [ifindex( 2), family(IPv4), proto(112), fd(12,13) multicast, address(224.0.0.18)] Keepalived_vrrp[57491]: (VI_1) Receive advertisement timeout Keepalived_vrrp[57491]: (VI_1) Entering MASTER STATE Keepalived_vrrp[57491]: (VI_1) setting VIPs.
配置文件
主节点(NODE1)/etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { enable_script_security script_user root } vrrp_script sc4s_health_check { script "/etc/keepalived/sc4s_health_check_script.sh" interval 2 weight 20 rise 2 fall 2 } vrrp_instance VI_1 { state MASTER interface ens192 virtual_router_id 51 priority 255 advert_int 1 authentication { auth_type PASS auth_pass ##### } virtual_ipaddress { ####/26 } track_script { sc4s_health_check } }
备份节点(NODE2)/etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { enable_script_security script_user root } vrrp_script sc4s_health_check { script "/etc/keepalived/sc4s_health_check_script.sh" interval 2 weight 20 rise 2 fall 2 } vrrp_instance VI_1 { state BACKUP interface ens192 virtual_router_id 51 priority 254 advert_int 1 authentication { auth_type PASS auth_pass #### } virtual_ipaddress { ####/26 } track_script { sc4s_health_check } }
健康检查脚本 /etc/keepalived/sc4s_health_check_script.sh
#!/bin/bash if podman container exists SC4S; then exit 0 fi if ss -ltn | grep ':514 '; then exit 0 fi exit 1
原因分析与解决方案
核心原因
错误日志中的关键信息 (VI_1) ignoring tracked script sc4s_health_check with weights due to address_owner 直接点明问题:主节点的优先级被设置为255,这是VRRP协议保留给「IP地址所有者」的最高优先级(物理网卡直接配置了VIP的节点)。当Keepalived检测到节点优先级为255时,会默认禁止任何带权重的跟踪脚本生效——因为权重调整会让优先级低于255,违背地址所有者的优先级规则。
备份节点优先级为254(低于255),不受此限制,所以脚本可以正常工作。
解决方案
- 降低主节点基础优先级:将主节点配置中的
priority从255改为低于255的值,比如240。这样脚本的权重调整(±20)后,优先级范围会在220-240之间,既保留主节点的优先级优势,又能让健康检查脚本正常触发优先级调整。
修改主节点配置行:priority 240 - 调整备份节点优先级:将备份节点的
priority设置为低于主节点基础优先级的值(比如230),确保主节点故障时,备份节点能顺利接管VIP。
验证方法
修改配置后重启Keepalived:
systemctl restart keepalived
查看日志确认不再出现ignoring tracked script和script is not used的警告,同时停止SC4S容器,检查主节点优先级是否降低,备份节点是否成功接管VIP。
内容的提问来源于stack exchange,提问作者Leon_P
相关产品推荐
相关产品推荐

