keepalived通知脚本
作者:互联网
一 通知脚本类型
- 当前节点成为主节点时触发脚本 notify_master <STRING>|<QUOTED-STRING>
- 当前节点转为备节点时触发脚本 notify_back <STRING>|<QUOTED-STRING>
- 当前节点转为失败状态时触发脚本 notify_fault <STRING>|<QUOTED-STRING>
- 通过格式的通知触发机制 notify <STRING>|<QUOTED-STRING>
- 当停止vrrp时触发脚本 notify_stop <STRING>|<QUOTED-STRING>
二 创建通知脚本
root@node-01:~# cat /etc/keepalived/notify.sh
#!/bin/bash
#
contact='1304995320@qq.com'
notify() {
mailsubject="$(hostname) to be master, vip floating"
mailbody="$(date +'%F %T'): vrrp transition,$(hostname) changed to be master"
echo "$mailbody" | s-nail -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@node-01:~# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived
global_defs {
notification_email {
1304005320@qq.com
}
notification_email_from 1304005320@qq.com
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id node-01
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 101
priority 100
advert_int 1
preempt
preempt_delay 300
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.174.20
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
四 模拟node-01故障
root@node-01:~# systemctl stop keepalived
标签:脚本,01,通知,keepalived,vrrp,master,notify,fault 来源: https://www.cnblogs.com/wangguishe/p/15530364.html