Article Directory
keepalived notification example
Notification Configuration
The script is triggered when the current node becomes the master node: <QUOTED-STRING> | notify_master <STRING>
Script triggered the current node into standby node: <QUOTED-STRING> | notify_backup <STRING>
The script is triggered when the current node to "failed" states: <QUOTED-STRING> | notify_fault <STRING>
notify <STRING> | <QUOTED-STRING>: notification triggers a common format, a script can be completed notification of conversion of more than three states
ubuntu 1804 send e-mail qq
root@z6:~# vi /etc/apt/sources.list 追加
deb http://cz.archive.ubuntu.com/ubuntu xenial main universe
root@z6:~# apt-get update
root@z6:~# apt install heirloom-mailx
root@z6:~# vim /etc/s-nail.rc 添加发件人
set from=" [email protected]"
set smtp="smtps://smtp.qq.com:465"
set smtp-auth-user="[email protected]"
set smtp-auth-password="qieqdcaxxxkbhbb"
set smtp-auth=login
Test whether you can send a message qq
root@z6:~# echo "omg" | heirloom-mailx -s "kiss the rain" [email protected]
Script notify.sh notice
#!/bin/bash
contact='[email protected]'
notify() {
mailsubject="$(hostname) to be $1, vip转移"
mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1"
echo "$mailbody" | heirloom-mailx -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
keepalive call script
root@z6:~# chmod +x /etc/keepalived/notify.sh
keepalived.conf Configuration
vrrp_instance VI_1{
state MASTER
interface eth0
virtual_router_id 50
priority 70
advert_int 1
authentication {
auth_type PASS
auth_pass 1111qwer
}
virtual_ipaddress {
192.168.7.248/24 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"
}
Add the following two lines or log alarms
global_defs {
script_user root
enable_script_security
}
Mar 26 15:23:00 z6 Keepalived_vrrp[1854]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Mar 26 15:28:18 z6 Keepalived_vrrp[1907]: SECURITY VIOLATION - scripts are being executed but script_security not enabled. There are insecur
e scripts.
Start and stop the test keepalived
result