Keepalived 通知脚本未执行

Keepalived 通知脚本未执行

我刚刚在/etc/keepalived/keepalived.conf

/etc/keepalived/keepalived.conf

global_defs {
  notification_email {
    [email protected]
  }
  notification_email_from [email protected]
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id DEFAULT_ROUT_ID
}


vrrp_script notification {
  script ""
  interval
  weight
}

vrrp_instance VI_1 {
  interface eth0
  virtual_router_id 10
  nopreempt
  state backup
  priority 110
  advert_int 1
  virtual_ipaddress {
    22.22.22.22
  }
  track_script {
    notification
  }

  notify_master "/etc/keepalived/master.sh"
  notify_backup "/etc/keepalived/backup.sh"
}

每当状态发生变化时,它就会出现

在此处输入图片描述

它似乎可以工作,但是那些 shell 脚本并未执行。

你有什么建议吗?

答案1

我也遇到了同样的问题,我的通知脚本没有被执行,最后我意识到 SELinux 阻止了我的脚本运行,我通过输入以下内容发现了这一点:

[root@server ~]# journalctl

因此,查看输出,它会提示您禁用 SELinux 的命令,以便您的通知脚本可以运行。另外,我没有使用通知,但是

      notify_master "/path/to/script"
      notify_backup "/path/to/script"

SELinux 的结果:如果您认为 keepalived 默认应该具有 dac_override 功能。那么您应该将此报告为错误。您可以生成本地策略模块以允许此访问。现在通过执行以下命令允许此访问:

   ausearch -c 'keepalived' --raw | audit2allow -M my-keepalived

   semodule -i my-keepalived.pp

运行这些命令后,重新启动 keepalived:

   service keepalived restart

答案2

就我而言,我必须指定完整路径(正确地)。

Feb 14 17:14:01 lb0-0 Keepalived_vrrp[22728]: WARNING - script `killall` resolved by path search to `/usr/bin/killall`. Please specify full path.
Feb 14 17:14:01 lb0-0 Keepalived_vrrp[22728]: Cannot find script  in path
Feb 14 17:14:01 lb0-0 Keepalived_vrrp[22728]: Disabling track script chk_haproxy since not found

相关内容