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 [email protected] -t "$to" -s smtp.sina.com  -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu [email protected]  -xp feng123.123 -m "$body" >> /tmp/keepalived_mail.log
}
notify(){
    content="`hostname` has been $1"
    smail [email protected] `hostname`  "$content"
}

case $1 in
  master)
    notify $1
    ;;
  backup)
    notify $1
    ;;
  fault)
    notify $1
    ;;
  *)
    echo "usage master | backup | falt"
    ;;
esac

你可能感兴趣的:(keepalived实例状态变换只脚本提醒)