zoukankan      html  css  js  c++  java
  • 记一次Nginx+Keepalived高可用故障转移

     Master端:192.168.2.156

    ! 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 192.168.2.156
       smtp_connect_timeout 30
       router_id LVS_DEVEL
    }
    vrrp_script check_nginx {
      script "/data/sh/check_nginx.sh"
      interval 2
      weight 2
    }
    vrrp_instance VI_1 {
        state BACKUP
        interface eth0
        virtual_router_id 51
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.2.100
        }
     track_script {
      check_nginx
    }
    }

     slave端:192.168.2.157

    ! 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 192.168.2.156
       smtp_connect_timeout 30
       router_id LVS_DEVEL
    }
    vrrp_script check_nginx {
      script "/data/sh/check_nginx.sh"
      interval 2
      weight 2
    }
    vrrp_instance VI_1 {
        state BACKUP
        interface eth0
       mcast_src_ip 192.168.2.157
        virtual_router_id 51
        priority 90
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.2.100
        }
    
     track_script {
      check_nginx
    }
    }

     故障转移脚本

    #vim  /data/sh/check_nginx.sh 

    #!/bin/bash 
    COUNT=$(ps -C nginx --no-header |wc -l)
    if [ "${COUNT}"  =  "0" ];then
            echo "重启nginx"
            sleep 2
         COUNT=$(ps -C nginx --no-header |wc -l)
            if [ "${COUNT}" = "0" ];then
                 systemctl  stop  keepalived
            fi
    fi

     # chmod a+x /data/sh/check_nginx.sh 

    [root@localhost ~]# crontab -e

    */1 * * * * /data/sh/check_nginx.sh >> /var/log/check_nginx.log

     测试:当我们尝试停止nghinx时,当手动停止nginx约2秒之后,此时会关闭keepalived,实现vip转移

    浏览器访问浏览:VIP192.168.2.100即可

  • 相关阅读:
    CSS清浮动处理(Clear与BFC)
    站点的排名对于站点非常重要
    Jquery插件placeholder的用法
    怎样将程序猿写出来的程序打包成安装包(最简单的)
    几种常见模式识别算法整理和总结
    数组中的跳跃问题
    基于各种浏览器的写法兼容
    cisco(思科)交换机配置篇【两】
    怎么样excel其产生的条形码(10分钟的时间excel)从而出现了条形码
    iOS随机颜色
  • 原文地址:https://www.cnblogs.com/bixiaoyu/p/9743825.html
Copyright © 2011-2022 走看看