xiaowei8782088 发表于 2018-12-31 09:20:44

nginx + keepalived 高可用负载均衡

  虚拟IP:    192.168.2.52
  nginx-1:   192.168.2.50
  nginx-2:   192.168.2.51
  

  关闭/etc/sysconfig/selinux
  SELINUX=disabled
  nginx-1
  yum install keepalived
  vim /etc/keepalived/keepalived.conf
---------------------------------------------------
  ! Configuration File for keepalived
global_defs {                     
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER               //定义为MASTER主机
    interface eth0
    virtual_router_id 51      //虚拟id
    priority 100          //优先级
advert_int 1                   //检测间隔
    authentication {
      auth_type PASS          //认证方式
      auth_pass abcd          //认证密码
    }
    virtual_ipaddress {
      192.168.2.52          //虚拟ip,即VIP
}
  -------------------------------------------------
  chkconfig keepalived on
  service keepalived start
  nginx-2
  yum install keepalived
vim /etc/keepalived/keepalived.conf
--------------------------------------------------只改动如下
state BACKUP       //定义为BACKUP
priority 99         //优先级
  virtual_ipaddress {
      192.168.2.52
}
-------------------------------------------------
chkconfig keepalived on
service keepalived start
ip a
https://s2.运维网.com/wyfs02/M02/99/71/wKioL1lIhtmjJmYGAAAoS4vureg933.png-wh_500x0-wm_3-wmp_4-s_4071887930.png                  https://s4.运维网.com/wyfs02/M01/99/71/wKiom1lIh5HDHH7rAAAmea8hp3c298.png-wh_500x0-wm_3-wmp_4-s_1852228557.png
  已经绑定成功
  

  检测keepalived自动切换
  客户机:
  ping 192.168.2.52 -t
  nginx-1: 关闭keepalived服务
  service keepalived stop
  客户机是否正常ping

  

  

  安装nginx
  因为centos 没有nginx,先安装第三方epel-release源
  yum install -y epel-release
  yum install -y nginx
  负载均衡
  vi /etc/nginx/nginx.conf
  添加以下内容
  ------------------------
  # for more information.
  include /etc/nginx/conf.d/*.conf;
  

   upstream zhizhimao.com {
      server192.168.2.101:80;    #web服务器
      server192.168.2.100:80;    #web服务器
   }
  }
  ------------------------

  反向代理
  vi /etc/nginx/conf.d/default.conf
  --------------------------------------------
  server {
  listen       80;
  listen       [::]:80default_server;
  server_name   zhizhimao.com;             #如只做代理填写IP
  root      /usr/share/nginx/html;
  #Load configuration files for the default server block.
  include /etc/nginx/default.d/*.conf;
  location / {
  proxy_pass http://zhizhimao.com;          #如只做代理填写IP
  }
  error_page 404 /404.html;
  location = /40x.html {
  }
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
  }
  }
  -----------------------------------------------------
  chkconfig nginx on
  service nginx start
  防火墙打开80端口



页: [1]
查看完整版本: nginx + keepalived 高可用负载均衡