zoukankan      html  css  js  c++  java
  • keepalive配置

    安装

    yum install -y keepalived

    环境:

    10.3.196.31 ap01  
    10.3.196.32 ap02  
    10.3.196.33 vip  

    ap01配置:

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 10.3.196.31
       smtp_connect_timeout 30
       router_id zjjg01
    script_user root
    enable_script_security
    
    }
    
    vrrp_script chk_nginx {
        script "/etc/keepalived/nginx_check.sh"    ## 检测nginx状态的脚本路径
        interval 2    ## 检测时间间隔
        weight -20    ## 如果条件成立,权重-20 
    }
    
    
    vrrp_instance VI_1 {
        state MASTER
        interface bond4
        virtual_router_id 33
        mcast_src_ip 10.3.196.31
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1234
        }
    
    ## 将track_script块加入instance 配置块
        track_script {
            chk_nginx    ## 执行Nginx监控的服务
    }
    
        virtual_ipaddress {
            10.3.196.33
        }
    }

    ap02配置:

      

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 10.3.196.32
       smtp_connect_timeout 30
       router_id zjjg02
       script_user root
    enable_script_security
    } vrrp_script chk_nginx { script "/etc/keepalived/nginx_check.sh" ## 检测nginx状态的脚本路径 interval 2 ## 检测时间间隔 weight -20 ## 如果条件成立,权重-20 } vrrp_instance VI_1 { state SLAVE interface bond4 virtual_router_id 33 mcast_src_ip 10.3.196.32 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1234 } ## 将track_script块加入instance 配置块 track_script { chk_nginx ## 执行Nginx监控的服务 } virtual_ipaddress { 10.3.196.33 } }

    nginx_check.sh  

    #!/bin/bash
    A=`ps -C nginx --no-header |wc -l`
    if [ $A -eq 0 ];then
        /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  
        sleep 2
        if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
            killall keepalived
        fi
    fi

    启动

    systemctl start keepalived
    systemctl enable keepalived
  • 相关阅读:
    java: Runtime和Process调用本机程序
    phalcon: 多模块多表查找,多表sql
    php: 不能嵌套try-catch-fnally,否则执行时间过长
    什么是数据埋点?
    git 上传本地代码到远程仓库
    Chrome调试模式获取App混合应用H5界面元素
    移动端Web开发调试之Chrome远程调试(Remote Debugging)
    java调用执行cmd命令
    maven项目乱码以及项目名出现红叉
    Maven项目settings.xml的配置
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15562399.html
Copyright © 2011-2022 走看看