zoukankan      html  css  js  c++  java
  • Keepalibed监控nginx

    配置Keepalived监控nginx

    --wang

    目的:

    通过Keepalived实现对nginx的监控,每两秒扫描一次,如果nginx关闭,尝试重启nginx,两秒后检查nginx是否启动,如果还没有启动,就关闭Keepalived

    配置文件: 

    /etc/keepalived/keepalived.conf

    注意事项:

    脚本一定要开启执行权限chmod  +x  /root/shell/nginx_check.sh

    脚本内容:

    [root@CRS_LH_LoadB ~]# vim /root/shell/nginx_check.sh

    #!/bin/bash

    time=`date '+%Y%m%d %H%M%S'`

    #echo "${time}test script">>/root/shell/test.txt #用于判断脚本是否正常执行,可以注释掉

    systemctl status nginx>>/dev/null

    if [ $? -ne 0 ] ; then

            systemctl start nginx

            sleep 2

            if [ $? -ne 0 ] ; then

                    systemctl stop keepalived>>/dev/null

            fi

    fi

    实际配置文件:

    主:

    global_defs {

            router_id Haproxy_HA_m

    }

    vrrp_script chk_nginx {

            script "/root/shell/nginx_check.sh"

            interval 2

    }

    vrrp_instance VI_1 {

        state MASTER

        interface ens160

        virtual_router_id 58

        priority 100

        advert_int 1

        nopreempt

        authentication {

            auth_type PASS

            auth_pass 1111

        }

        virtual_ipaddress {

            192.168.100.180

    }

    track_script {     #调用脚本

           chk_nginx

        }

    }

    备:

    global_defs {

            router_id Haproxy_HA_b

    }

    vrrp_script chk_nginx {

            script "/root/shell/nginx_check.sh"

            interval 2

    }

    vrrp_instance VI_1 {

        state BACKUP

        interface ens160

        virtual_router_id 58

        priority 80

        advert_int 1

        nopreempt

        authentication {

            auth_type PASS

            auth_pass 1111

        }

        virtual_ipaddress {

            192.168.100.180

    }

    track_script {     #调用脚本

           chk_nginx

        }

    }

  • 相关阅读:
    异常日志以及非异常日志记录方法
    oracle 监测数据库是否存在指定字段
    listview禁止双击一条之后选中复选框按钮的方法
    oracle 的rowid和rownum
    修改文件的名字的写法
    使用C#读取XML节点,修改XML节点
    BZOJ 1004: [HNOI2008]Cards
    P5022 旅行 (NOIP2018)
    P5021 赛道修建 (NOIP2018)
    P5020 货币系统 (NOIP2018)
  • 原文地址:https://www.cnblogs.com/szy2018/p/10563656.html
Copyright © 2011-2022 走看看