码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived 非抢占模式 以及nginx状态监控

时间:2017-05-23 21:46:18      阅读:1070      评论:0      收藏:0      [点我收藏+]

标签:keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id f6
   vrrp_mcast_group4 224.0.0.20
   nopreempt
}
vrrp_script chk_nginx {
#    script "killall -0 nginx"
    script "/etc/keepalived/check_nginx.sh"
    interval 2
    weight -5
    fall 3  
    rise 2
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 58
    priority 150
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
     172.21.10.199/24 dev eth0 label eth0:1
 }
     track_script {
       chk_nginx
    }

}


[root@e7 ~]# cat  /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id e7
   vrrp_mcast_group4 224.0.0.20
}
vrrp_script chk_nginx {
#    script "killall -0 nginx"
    script "/etc/keepalived/check_nginx.sh"
    interval 2
    weight -5
    fall 3  
    rise 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 58
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
   172.21.10.199/24 dev eth0 label eth0:1
    }
       track_script {
      chk_nginx
    }

}
[root@e7 ~]#
[root@e7 ~]# cat  /etc/keepalived/check_nginx.sh 
#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
    /usr/sbin/nginx
    echo "nginx 1 start"
    sleep 2
    counter=$(ps -C nginx --no-heading|wc -l)
    if [ "${counter}" = "0" ]; then
        echo "keepalived stop"
#        /etc/init.d/keepalived stop
systemctl stop keepalived
    fi
fi


[root@e7 ~]#


本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1928647

keepalived 非抢占模式 以及nginx状态监控

标签:keepalived

原文地址:http://wsxxsl.blog.51cto.com/9085838/1928647

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!