实战案例:实现Keepalived 状态切换的通知脚本
#在所有keepalived节点配置如下
[root@ka1-centos8 ~]#cat /etc/keepalived/notify.sh
#!/bin/bash
#
contact='root@wangxiaochun.com'
notify() {
mailsubject="(hostname) to be1, vip floating"
mailbody="(date +'%F %T'): vrrp transition,(hostname) changed to be 1"
echo "mailbody" | mail -s "mailsubject"contact
}
case 1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage:(basename $0) {master|backup|fault}"
exit 1
;;
esac
[root@ka1-centos8 ~]#chmod a+x /etc/keepalived/notify.sh
[root@ka1-centos8 ~]#vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
......
virtual_ipaddress {
10.0.0.10 dev eth0 label eth0:1
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
#模拟master故障
[root@ka1-centos8 ~]#killall keepalived
查看邮箱收到邮件如下:
本文链接:http://www.yunweipai.com/35373.html
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/52716.html