首页 Keepalived教程实战案例: 实现Keepalived 状态切换的通知脚本

Keepalived实现master/slave的单主架构

实战案例:实现master/master的Keepalivde 双主架构

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

实战案例:实现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

查看邮箱收到邮件如下:

实战案例: 实现Keepalived 状态切换的通知脚本插图

本文链接:http://www.yunweipai.com/35373.html

Keepalived实现master/slave的单主架构

实战案例:实现master/master的Keepalivde 双主架构

网友评论comments

发表评论

邮箱地址不会被公开。

暂无评论

Copyright © 2012-2021 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部