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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived 非抢占模式 以及nginx状态监控相关的知识,希望对你有一定的参考价值。

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   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
    }

}


[[email protected] ~]# cat  /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   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
    }

}
[[email protected] ~]#
[[email protected] ~]# 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


[[email protected] ~]#


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

以上是关于keepalived 非抢占模式 以及nginx状态监控的主要内容,如果未能解决你的问题,请参考以下文章

keepalived的抢占与非抢占模式

Keepalived非抢占模式配置

Keepalived的不(非)抢占模式#yyds干货盘点#

【keepalived】keepalived的非抢占模式与单播模式

Keepalived+Nginx实现高可用(HA)

Keepalived+Nginx实现高可用(HA)