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

        }

    }

  • 相关阅读:
    C# 对Excel文档打印时的页面设置
    C# 对Excel 单元格格式, 及行高、 列宽、 单元格边框线、 冻结设置
    object does not contain a definition for get_range
    shell变一些小技巧
    Codeforces Round #277.5 (Div. 2)A——SwapSort
    ActiveMQ与RabbitMQ采用camel综合
    SAP ABAP规划 使用LOOP READ TABLE该方法取代双LOOP内部表的方法
    Object-c中间initialize 与 辛格尔顿
    队列——阵列实现
    左右GNU Linux企业加密文件系统 eCryptfs简介
  • 原文地址:https://www.cnblogs.com/szy2018/p/10563656.html
Copyright © 2011-2022 走看看