keepalived.conf

! Configuration File for keepalived

vrrp_script chk_http_port {
        script "/etc/keepalived/check_haproxy.sh"
        interval 2
        weight 2


}
global_defs {
   notification_email {
        [email protected]
   }
   router_id itv_haproxy
}

vrrp_instance VI_1 {
    state BACKUP 
    interface eth1
    virtual_router_id 27
    priority 100
    nopreempt
    advert_int 1
 garp_master_delay 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {

        10.141.10.111  dev eth1 scope global #test VIP

}
   track_script {
        chk_http_port
   }
}



cat check_haproxy.sh 
#!/bin/bash
SendMailProgram=/usr/local/bin/sendEmail
#MailServer=smtp.itv.cn
MailServer=10.141.10.22
MailUser=CnBdwPHap
MailPass="KiO<!&"
MailFrom=([email protected])
MailTo=([email protected])
Mailcc=([email protected])
Mailbcc=([email protected])
MailAdminUser=([email protected])


A=`ps -C haproxy --no-header |wc -l`
if [ $A -eq 0 ];then
        #/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
        /etc/init.d/haproxy restart
        sleep 2
        if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
                /etc/init.d/keepalived restart
                /usr/local/bin/sendEmail -f  ${MailFrom[@]} -t ${MailTo[@]}   -s $MailServer -u "ERROR: [$(hostname)] keepalived haproxy switch" -xu $MailUser -xp $MailPass -m "[$(hostname)] keepalived haproxy switch. Please check!!!!!"



        fi
fi

results matching ""

    No results matching ""