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

        }

    }

  • 相关阅读:
    MVC 网页制作
    Mvc 中国直辖市下拉列表(三级联动)
    MVC 登陆注册页面
    MVC 数据库增删改查(Razor)视图(2)
    MVC 数据库增删改查(Razor)方法(1)和数据库
    winform网页抓取邮箱单发群发并有附件
    winform截取网页邮箱
    winform 图标表chart
    winform图片读取存储于数据库SQL
    winform计算器
  • 原文地址:https://www.cnblogs.com/szy2018/p/10563656.html
Copyright © 2011-2022 走看看