keepalived实例状态变换只脚本提醒

####BACKUP和MASTER一样
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 22222
    }
    virtual_ipaddress {
        192.168.0.104/24
    }

    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
}

###notify.sh
#!/bin/bash

smail(){
to=$1
subject=$2
body=$3
/usr/local/bin/sendEmail -f ronghedai_server@sina.com -t "$to" -s smtp.sina.com  -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu sender@sina.com  -xp feng123.123 -m "$body" >> /tmp/keepalived_mail.log
}
notify(){
    content="`hostname` has been $1"
    smail reciver@qq.com `hostname`  "$content"
}

case $1 in
  master)
    notify $1
    ;;
  backup)
    notify $1
    ;;
  fault)
    notify $1
    ;;
  *)
    echo "usage master | backup | falt"
    ;;
esac
    原文作者:EmptyBottl_520d
    原文地址: https://www.jianshu.com/p/6c2afc584545
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞