Shell 错误保留-故障状态

Shell 错误保留-故障状态,shell,high-availability,keep-alive,failover,Shell,High Availability,Keep Alive,Failover,我正在尝试使用KeepAlive监视某些服务。 请参阅我的配置文件“keepalived.conf”: 在我的脚本中,我将比较pid文件的编号和服务进程: #!/bin/bash # check if haproxy is running, return 1 if not. # Used by keepalived to initiate a failover in case haproxy is down process="" HAPROXY_STATUS="" if [ -f "/var

我正在尝试使用KeepAlive监视某些服务。 请参阅我的配置文件“keepalived.conf”:

在我的脚本中,我将比较pid文件的编号和服务进程:

#!/bin/bash
# check if haproxy is running, return 1 if not.
# Used by keepalived to initiate a failover in case haproxy is down

process=""
HAPROXY_STATUS=""

if [ -f "/var/run/haproxy.pid" ]
then
        process=$(cat /var/run/haproxy.pid)
        HAPROXY_STATUS=$(ps -aux | grep -w "$process.*[h]aproxy")
fi

if [ "$HAPROXY_STATUS" ]
then
        exit 0
else
        exit 1
fi
我的问题是,当我开始保存命令时:

keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console --log-detail    
万事如意,万事如意。但当我使用systemd启动服务时:

systemctl start keepalived
我的“/var/log/messages”文件中有以下几行:


有人有什么想法吗?

我正在使用非常简单的配置来实现同样的目的。默认情况下,大多数OSs Linux上都必须有实用程序pidof。请尝试以下示例:

vrrp_script check_haproxy
{
    script "pidof haproxy"
    interval 2
    weight 2
}

这是一个有效的解决方案,伙计。

在启动KeepAlive作为systemctl服务时,我的
track\u脚本
也遇到了类似的问题

我发现将我的
跟踪脚本
放入
/usr/libexec/keepalived
解决了这个问题。这可能是因为


在脚本部分使用脚本的地址时,我也有同样的问题,但使用命令是可以的,您找到解决方案了吗?有没有办法在脚本部分使用某个脚本的地址而不是命令?嗨!你能分享一下你在健康检查脚本中使用了什么吗?
Mar 15 17:05:51 localhost systemd: Starting Session 10 of user root.
Mar 15 17:06:23 localhost systemd: Starting LVS and VRRP High Availability Monitor...
Mar 15 17:06:23 localhost Keepalived[34182]: Starting Keepalived v1.2.13 (11/20,2015)
Mar 15 17:06:23 localhost systemd: Started LVS and VRRP High Availability Monitor.
Mar 15 17:06:23 localhost Keepalived[34183]: Starting Healthcheck child process, pid=34184
Mar 15 17:06:23 localhost Keepalived[34183]: Starting VRRP child process, pid=34185
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Netlink reflector reports IP 172.28.7.132 added
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Netlink reflector reports IP fe80::20c:29ff:fe22:a18e added
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Registering Kernel netlink reflector
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Registering Kernel netlink command channel
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Registering gratuitous ARP shared channel
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Opening file '/etc/keepalived/keepalived.conf'.
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Configuration is using : 64365 Bytes
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: Using LinkWatch kernel netlink reflector...
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: VRRP_Instance(Vtest_2) Entering BACKUP STATE
Mar 15 17:06:23 localhost Keepalived_vrrp[34185]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Netlink reflector reports IP 172.28.7.132 added
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Netlink reflector reports IP fe80::20c:29ff:fe22:a18e added
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Registering Kernel netlink reflector
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Registering Kernel netlink command channel
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Opening file '/etc/keepalived/keepalived.conf'.
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Configuration is using : 5344 Bytes
Mar 15 17:06:23 localhost Keepalived_healthcheckers[34184]: Using LinkWatch kernel netlink reflector...
Mar 15 17:06:26 localhost Keepalived_vrrp[34185]: VRRP_Instance(Vtest_2) Now in FAULT state
vrrp_script check_haproxy
{
    script "pidof haproxy"
    interval 2
    weight 2
}
! Configuration File for keepalived

global_defs {
}

vrrp_script odr_check {
        script "/usr/libexec/keepalived/health_check.sh"
        interval 2
        weight 50
        fall 1
        rise 1
}

vrrp_instance VI_1 {
    state BACKUP
    interface eno16777984
    virtual_router_id 42
    priority 90

    track_script {
        odr_check
    }

    virtual_ipaddress {
        192.168.110.84
    }
}