Keepalived通知脚本配置
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalived通知脚本配置相关的知识,希望对你有一定的参考价值。
邮件配置
qq邮箱配置
[root@ka1 ~]# vi /etc/mail.rc
在最下面添加下面行
set from=123456@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=123456@qq.com
set smtp-auth-password=tubnnnxdaqyacagd
set smtp-auth=login
set ssl-verify=ignore
[root@ka1 ~]#
发送测试邮件
[root@ka1 ~]# systemctl restart postfix
[root@ka1 ~]# echo "Test Mail" |mail -s Warning 123456@163.com
全局配置邮箱设置
[root@ka1 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
123456@163.com #收
}
notification_email_from 123456@qq.com #发
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka1.example.com
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
include /etc/keepalived/conf.d/*.conf
[root@ka1 ~]#
实现keepalived状态切换的通知脚本
#在所有keepalived节点配置如下
[root@ka1 ~]# cat /etc/keepalived/notify.sh
#!/bin/bash
contact='calm_yzl@163.com'
notify() {
mailsubject="$(hostname) to be $1,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 ~]#
[root@ka1 ~]# chmod a+x /etc/keepalived/notify.sh
脚本的调用
#脚本的调用
[root@ka1 ~]# cat /etc/keepalived/conf.d/m1.conf
vrrp_instance m1 {
state MASTER
interface ens33
virtual_router_id 66
priority 100
advert_int 1
preempt_delay 10
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.100/24 dev ens33 label ens33:1
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
unicast_src_ip 10.0.0.10
unicast_peer {
10.0.0.20
}
}
[root@ka1 ~]#
模拟故障
[root@ka1 ~]# killall keepalived
查看邮件
以上是关于Keepalived通知脚本配置的主要内容,如果未能解决你的问题,请参考以下文章