【问题标题】:Error Keepalived - FAULT state错误 Keepalived - FAULT 状态
【发布时间】:2017-09-07 22:40:54
【问题描述】:

我正在尝试使用 keepalived 来监控某些服务。 查看我的配置文件“keepalived.conf”:

! Configuration File for keepalived
vrrp_script check_haproxy {
        script "/usr/local/bin/check_haproxy.sh"
        interval 2
        fail 2
        rise 2
}

vrrp_instance Vtest_2 {
        interface eno16777736

        track_interface {
                eno16777736
        }

        state BACKUP
        virtual_router_id 178
        priority 100
        nopreempt

        unicast_src_ip 172.28.7.132
        unicast_peer {
                172.28.7.133
        }

        virtual_ipaddress {
                195.221.2.14/32 dev eno16777736
        }

        track_script {
                check_haproxy
        }

        notify /usr/local/bin/keepalived.state.sh
}

在我的脚本中我比较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命令的时候:

keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console --log-detail    

一切正常,keepalived 故障转移运行良好。但是当我用 systemd 启动服务时:

systemctl start keepalived

我的“/var/log/messages”文件中有这行:

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

有人有想法吗?

【问题讨论】:

  • 我在脚本部分使用我的脚本地址时遇到同样的问题,但是使用命令是可以的,你找到解决方案了吗?

标签: shell high-availability keep-alive failover


【解决方案1】:

我是一个使用非常简单的配置来实现相同目的的人。默认情况下,实用程序 pidof 必须在大多数操作系统 Linux 上。试试这个例子:

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

这是一个可行的解决方案伙伴。

【讨论】:

  • 有什么方法可以在脚本部分使用某些脚本的地址而不是命令?
【解决方案2】:

我的track_script 在启动keepalived 作为systemctl 服务时没有运行也有类似的问题。

我发现将我的track_script 放入/usr/libexec/keepalived 解决了这个问题。大概和this issue有关。

! 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
    }
}

【讨论】:

  • 嗨!您能分享一下您在运行状况检查脚本中使用的内容吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-15
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多