0

我正在使用默认 yum v1.3.5 (03/19,2017) 的 keepalived,在 centos 7 (2009) 上使用 git commit v1.3.5-6-g6fa32f2

vip 工作正常,但是当我添加通知脚本时,它正在打开文件但没有运行它(我猜)。这是我备份的配置文件。我使用 root 是因为我在某处读到 keepalived 需要类似于 root 的权限(我可能错了)

! Configuration File for keepalived

global_defs {
enable_script_security
script_user root
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp0s3
    virtual_router_id 51
    priority 100 #used in election, 150 for master & 100 for backup
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.11.33/24   dev enp0s3
    }
    notify "/etc/keepalive/notify.sh"
    notify_master "/etc/keepalive/notify_master.sh"
    notify_backup "/etc/keepalive/notify_backup.sh"
}

这是我的通知脚本(主备有相同的东西)。我已经尝试使用 /bin/bash notify.sh 运行它并且它可以工作。脚本的权限是755

#!/bin/bash
echo "test" > /etc/keepalived/logs/log.log

当我启动/停止主服务时,备份服务器获取 vip 但文件夹日志中没有任何内容

这是来自 journalctl -u keepalived 的日志 | 尾 -n 100

Jan 31 03:17:25 smtp.domain.com systemd[1]: Starting LVS and VRRP High Availability Monitor...
Jan 31 03:17:25 smtp.domain.com Keepalived[17729]: Starting Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
Jan 31 03:17:25 smtp.domain.com Keepalived[17729]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 31 03:17:25 smtp.domain.com Keepalived[17730]: Starting Healthcheck child process, pid=17731
Jan 31 03:17:25 smtp.domain.com Keepalived[17730]: Starting VRRP child process, pid=17732
Jan 31 03:17:25 smtp.domain.com systemd[1]: Started LVS and VRRP High Availability Monitor.
Jan 31 03:17:25 smtp.domain.com Keepalived_vrrp[17732]: Registering Kernel netlink reflector
Jan 31 03:17:25 smtp.domain.com Keepalived_vrrp[17732]: Registering Kernel netlink command channel
Jan 31 03:17:25 smtp.domain.com Keepalived_vrrp[17732]: Registering gratuitous ARP shared channel
Jan 31 03:17:25 smtp.domain.com Keepalived_vrrp[17732]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 31 03:17:25 smtp.domain.com Keepalived_healthcheckers[17731]: Initializing ipvs
Jan 31 03:17:25 smtp.domain.com Keepalived_healthcheckers[17731]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 31 03:17:30 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) removing protocol VIPs.
Jan 31 03:17:30 smtp.domain.com Keepalived_vrrp[17732]: Using LinkWatch kernel netlink reflector...
Jan 31 03:17:30 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) Entering BACKUP STATE
Jan 31 03:17:30 smtp.domain.com Keepalived_vrrp[17732]: Opening script file /etc/keepalived/notify_backup.sh
Jan 31 03:17:30 smtp.domain.com Keepalived_vrrp[17732]: Opening script file /etc/keepalived/notify.sh
Jan 31 03:17:30 smtp.domain.com Keepalived_vrrp[17732]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Jan 31 03:17:34 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) Entering MASTER STATE
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) setting protocol VIPs.
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on enp0s3 for 192.168.11.33
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Opening script file /etc/keepalived/notify_master.sh
Jan 31 03:17:35 smtp.domain.com Keepalived_vrrp[17732]: Opening script file /etc/keepalived/notify.sh
Jan 31 03:17:40 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:40 smtp.domain.com Keepalived_vrrp[17732]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on enp0s3 for 192.168.11.33
Jan 31 03:17:40 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:40 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:40 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
Jan 31 03:17:40 smtp.domain.com Keepalived_vrrp[17732]: Sending gratuitous ARP on enp0s3 for 192.168.11.33
4

1 回答 1

0

对于我使用的临时答案:放置一个 cron 来检查服务器的当前状态并运行脚本

当前服务器状态命令行

journalctl -u keepalived | grep Entering | awk 'END{print $8}'

更新:

最后我发现了问题,当我运行 getenforce 时,它​​返回执行。除非我制定规则或 setenforce 0,否则 vrrp_script 似乎不会运行

我编辑了 /etc/selinux/config 所以重启后它不会重置

SELINUX=permissive
于 2022-02-01T07:17:53.760 回答