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

        }

    }

  • 相关阅读:
    Python学习 5day__基础知识
    pycharm 2018.1 专业版激活 亲测可用!!!
    JQuery 中 find() 和 filter() 的区别
    React 事件处理
    React 数据传递
    js操作cookie的一些注意项
    html5的技术要点
    css背景设置,让套图中某张图片居中显示的例子
    js对象封装内部图片的相关代码,采用base64图片串
    针对网上很多抱怨的言论,写了一个EF中update对象时,通用的遍历赋值方法,以供参考
  • 原文地址:https://www.cnblogs.com/szy2018/p/10563656.html
Copyright © 2011-2022 走看看