keepalived+nginx-upstream部署高可用反向代理

keepalived+nginx-upstream部署高可用反向代理

实验拓扑

keepalived+nginx-upstream部署高可用反向代理

实验要求

  1. 两个web server提供httpd服务,ip地址分别是172.18.27.201、202,掩码是16
  2. 两个nginx proxy提供高可用反向代理,ip地址分别是172.18.27.102、200,掩码是16.
  3. client能够访问web server,使用dr模型反向代理。

实验步骤

  1. 各主机安装软件

    ##web server安装httpd
    yum install -y httpd
    ##nginx proxy安装nginx和keeplived.
    yum install -y keepalived nginx
  2. 配置web server

    ##两台web server配置,两台都为centos7.2
    #RS1配置
    vim /var/www/html/index.html
    <h1/>RS1:172.18.27.201</h1>
    #RS2配置
    vim /var/www/html/index.html
    <h1/>RS2:172.18.27.202</h1>
    #RS1和RS2启动httpd服务
    systemct start httpd
  3. 配置nginx proxy

    ##配置nginx proxy服务器
    #配置nginx upstream
    vim /etc/nginx/nginx.conf
    http {
         .....
      upstream httpdserver{
         server 172.18.27.201:80 weight=2;
         server 172.18.27.202:80 weight=1;
         server 127.0.0.1:8080 backup;
     }
    }
    #配置keeplived
    vim /etc/keepalived/keepalived.conf
    global_defs {
    vrrp_mcast_group4 224.100.27.1
    }
    vrrp_script chk_down {
                 script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
                 interval 1
                 weight -5
                         }
    vrrp_script chk_nginx {
                 script "killall -0 nginx && exit 0 || exit 1"
                 interval 1
                 weight -5
                 fall 2
                 rise 1
    }
    vrrp_instance VI_1 {
     state MASTER
     interface eth1
     virtual_router_id 51
     priority 100
     advert_int 1
     nopreempt
     authentication {
         auth_type PASS
         auth_pass 1111
     }
     virtual_ipaddress {
         172.18.27.254/16 dev eth1 label eth1:0
     }
     track_script {
         chk_down
         chk_nginx
     }
     track_interface{
         eth1
     }
    }
    #启动服务
    service nginx start
    service keepalived start

    配置另一台nginx proxy

    #配置nginx upstream
    vim /etc/nginx/nginx.conf
    http {
         .....
      upstream httpdserver{
         server 172.18.27.201:80 weight=2;
         server 172.18.27.202:80 weight=1;
         server 127.0.0.1:8080 backup;
     }
    }
    #配置keeplived
    vim /etc/keepalived/keepalived.conf
    global_defs {
    vrrp_mcast_group4 224.100.27.1
    }
    vrrp_script chk_down {
                 script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
                 interval 1
                 weight -5
                         }
    vrrp_script chk_nginx {
                 script "killall -0 nginx && exit 0 || exit 1"
                 interval 1
                 weight -5
                 fall 2
                 rise 1
    }
    vrrp_instance VI_1 {
     state BACKUP
     interface eno16777736
     virtual_router_id 51
     priority 98
     advert_int 1
     nopreempt
     authentication {
         auth_type PASS
         auth_pass 1111
     }
     virtual_ipaddress {
         172.18.27.254/16 dev een016777736 label eno16777736:0
     }
     track_script {
         chk_down
         chk_nginx
     }
     track_interface{
         eno16777736
     }
    }
    #启动服务
    systemctl start nginx keepalived

    试验效果

    正常状态

    keepalived+nginx-upstream部署高可用反向代理

    一个web server 宕机了

    keepalived+nginx-upstream部署高可用反向代理

    一个nginx proxy服务器宕机了

    keepalived+nginx-upstream部署高可用反向代理
    keepalived+nginx-upstream部署高可用反向代理
    能够正常运行

原创文章,作者:oranix,如若转载,请注明出处:http://www.178linux.com/75809

(0)
oranixoranix
上一篇 2017-05-15 19:29
下一篇 2017-05-15 20:31

相关推荐

  • 一. DHCP,TFTP, DNS 配置

    练习在CentOS6上配置DHCP, TFTP, DNS服务 1. 首先按下图所示搭建网络拓扑图 2017-07-11 151425-001.png Server1 服务器IP: 192.168.20.101/24GATEWAY: 192.168.20.2DNS: 192.168.20.2 Server2 服务器IP: 192.168.20.102/24GA…

    Linux干货 2017-07-11
  • vim编辑器及shell基础

    1、复制/etc/rc.d/rc.sysint文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#cp /etc/rc.d/rc.sysint /tmpvim /tmp/rc.sysint:%s@^[[:space:]]\+@#&@g 2、复制/boot/grub/grub.conf至/tmp目录中,删除/…

    Linux干货 2017-12-08
  • N25第二周作业

    第二周作业 一、Linux上的文件管理类命令有哪些,其常用的使用方法以及相关实例演示 演示用结构  [root@centos01 yanshi]# tree -a /tmp/yanshi/   /tmp/yanshi/ ├── a │   └── 1…

    Linux干货 2016-12-14
  • LINUX下的RPM应用

    一 前言 在进入RPM的应用前,关于可执行程序的一些基本知识有必要说明一下: 1 ABI:application binary interface,这是应用程序与系统间的协议,大家都知道同一个程序在不同的操作系统平台可能会无法执行,很大程度上就是因为ABI的不同,因此,对于可执行程序,选择对应操作系统平台是第一步 2 API:application prog…

    Linux干货 2017-04-17
  • 2016-10-17作业

    1 生产环境发现一台服务器系统时间产生偏差,造成服务异常,请帮忙校正。 答:hwclock -s 2 生产有一个数据同步脚本需要执行很长时间,怎样做到无人值守,在管理工具退出的情况下,脚本依然能正常运行。 答:screen -S work  进去后开始做工作,暂时离开时可使用 ctrl+a,d 剥离当前会话。 3 Linux系统中命令共分为内建命令…

    Linux干货 2016-10-18
  • http://www.jianshu.com/p/aac6076e4ca2

    Linux干货 2017-07-29