zoukankan      html  css  js  c++  java
  • Nginx 之 Nginx配置高可用的集群

    一、Nginx 搭建高可用集群

      1、什么是 nginx 高可用

        

           (1)需要两台 nginx 服务器

        (2)需要 keepalived

        (3)需要虚拟 ip

      2、配置高可用的准备工作

        (1)需要两天服务器 192.168.17.129 和 192.168.17.131

        (2)在两台服务器上安装 nginx

        (3)在两台服务器安装 keepalived

      3、在两台服务器安装 keepalived

        (1)使用 yum 命令进行安装

    yum install -y keepalived
    

            

        (2)安装之后,在 etc 里面生成目录 Keepalived,有文件 Keepalived.conf

      4、完成高可用配置(主从配置)

        (1)修改 /etc/keepalived/keepalived.conf 配置文件

    global_defs {
        notification_email {
            acassen@firewall.loc
            failover@firewall.loc
            sysadmin@firewall.loc
        }
        
        notification_email_from Alexandre.Cassen@firewall.loc
        smtp_server 192.168.17.129
        smtp_connect_timeout 30
        router_id LVS_DEVEL
    }
    
    vrrp_script chk_http_port {
        script "/usr/local/src/nginx_check.sh"
        interval 2 #(检测脚本执行的间隔)
        weight 2
    }
    
    vrrp_instance VI_1 {
        state BACKUP # 备份服务器上将 MASTER 改为 BACKUP
        interface ens33 //网卡
        virtual_router_id 51 # 主、备机的 virtual_router_id 必须相同
        priority 90 # 主、备机取不同的优先级,主机值较大,备份机值较小
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.17.50 // VRRP H 虚拟地址
        }
    }

        (2)在/usr/local/src 添加检测脚本:nginx_check.sh

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

      

        (3)把两台服务器上 nginx 和 Keepalived 启动

    启动 nginx: ./nginx
    启动 keepalived: systemctl start keepalived.service
    

      

      5、最终测试

        (1)在浏览器地址栏输入 虚拟 ip 地址 192.168.17.50

          

              

        (2)把主服务器(192.168.17.129)nginx 和 Keepalived 停止,再输入 192.168.17.50

          

             

     

  • 相关阅读:
    codeforces 37 E. Trial for Chief【spfa】
    bzoj 1999: [Noip2007]Core树网的核【树的直径+单调队列】
    codehunter 「Adera 6」杯省选模拟赛 网络升级 【树形dp】
    codeforces GYM 100781A【树的直径】
    bzoj 2878: [Noi2012]迷失游乐园【树上期望dp+基环树】
    bzoj 1791: [Ioi2008]Island 岛屿【基环树+单调队列优化dp】
    codeforces 949C
    codeforces 402E
    poj 3613 Cow Relays【矩阵快速幂+Floyd】
    bzoj 2097: [Usaco2010 Dec]Exercise 奶牛健美操【二分+树形dp】
  • 原文地址:https://www.cnblogs.com/niujifei/p/15185065.html
Copyright © 2011-2022 走看看