• nginx 加 keepalived 高可用


    nginx 加keepalived高可用
    防火墙全关
    开两台nginx

    ----------------修改主配置文件 -------------------------
    在server上写入
    upstream httpd1 {
     server 192.168.200.113:80 weight=1;
     server 192.168.200.114:80 weight=1;
    }
    在location里写入
     proxy_pass http://httpd1;
     proxy_set_header Host $host;
    ----------------------------------------------------------------
    启动nginx 
    再分别安装  keepalived
    yum -y install keepalived

    另外两台 安装 httpd 并开启  systemctl start httpd
    -------------------------------------------
    分别配置keepalived 主(从)文件
    vim /etc/keepalived/keepalived.conf
    引入脚本文件
    修改
    ! Configuration File for keepalived
     
    vrrp_script check_nginx {
    script "/shell/nginx_check.sh"     // 加上脚本
    interval 2
     weight -20
    global_defs {
    router_id LVS_DEVEL
    }
    vrrp_instance VI_1 {
    state MASTER(BACKUP)
    interface eth0    (..)
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
     
    track_script {
    chk_http_port                           //指定脚本
    }
     
    virtual_ipaddress {
    192.168.200.254                      //虚拟网IP  (访问的网)
    }
    }
    }
    -----------------------------------------------------------------
    分别创建对应脚本   vim /shell/nginx_check.sh
    #!/bin/bash
    count="$(ps -C nginx --no-header|wc -l)"
    if [ $count -eq 0 ];then
     /usr/local/nginx/sbin/nginx -s restart
     sleep 2
     if [ ps -C nginx --no-header|wc -l -eq 0 ];then
      systemctl stop keepalived
     fi
    fi
    ------------------------------------------------------------------------
    加权限给脚本   chmod +x /shell/nginx_check.sh
    启动Keepalived  nginx
    systemctl start keepalived
    重启nginx
  • 相关阅读:
    迷你图标集大集合:5000+ 30套免费的图标(不得不下,设计必备)
    Github简介
    Sublime Text 3 文本编辑器
    FusionCharts V3图表导出图片和PDF属性说明(转)
    FusionCharts参数的详细说明和功能特性(转)
    SQL 数据结构操作语句
    SQL Server 2008 各种DateTime的取值范围
    Datagrid数据导出到excel文件的三种方法
    开发环境
    如何利用ThoughtWorks.QRCode 生成二维码
  • 原文地址:https://www.cnblogs.com/123456likun/p/11639852.html
Copyright © 2020-2023  润新知