封云亭 发表于 2018-12-31 10:39:26

nginx+keepalived双主负载均衡

  环境请看 〉〉Nginx+keepalived主备切换_2
  主要区别如下:
  //蓝色与红色仔细观察
  192.168.10.1主服务器的keepalived配置
  ! Configuration File for keepalived
  global_defs {
  notification_email {
  Xxx@qq.com
  }
  notification_email_from Keepalived@chtopnet.com
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  }
  vrrp_script chk_http_port {
  script "/etc/keepalived/chk_nginx_pid.sh"
  interval 2
  weight 2
  }
  vrrp_instance VI_1 {
  state MASTER
  interface eth0
  virtual_router_id 51      //VI_2 为 52
  priority 100            //备用是99
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 1111
  }
  track_script {
  chk_http_port
  }
  virtual_ipaddress {
  192.168.10.6         //VIP 1
  }
  }
  vrrp_instance VI_2 {
  state BACKUP
  interface eth0
  virtual_router_id 52   // VI_1 是51
  priority 99            //主是100
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 1111
  }
  track_script {
  chk_http_port
  }
  virtual_ipaddress {
  192.168.10.5       //VIP 2
  }
  }
  192.168.10.2主服务器的keepalived配置
  ! Configuration File for keepalived
  global_defs {
  notification_email {
  Xxx@qq.com
  }
  notification_email_from Keepalived@chtopnet.com
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  }
  vrrp_script chk_http_port {
  script "/etc/keepalived/chk_nginx_pid.sh"
  interval 2
  weight 2
  }
  vrrp_instance VI_1 {
  state BACKUP
  interface eth3
  virtual_router_id 51
  priority 99
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 1111
  }
  track_script {
  chk_http_port
  }
  virtual_ipaddress {
  192.168.10.6
  }
  }
  vrrp_instance VI_2 {
  state MASTER
  interface eth3
  virtual_router_id 52
  priority 100
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 1111
  }
  track_script {
  chk_http_port
  }
  virtual_ipaddress {
  192.168.10.5
  }
  }
  测试
  停止192.168.10.1的nginx服务 访问http://192.168.10.5 与http://192.168.10.6 刷新也正常
  启动192.168.10.1的nginx服务与keepalived服务(因为脚本写为nginx服务停止了,keepalived也停止)
  停止192.168.10.4的nginx服务 访问http://192.168.10.5 与http://192.168.10.6 刷新也正常
  
  查看ip a
  会发现停掉10.4之后10.1eth0 会出现192.168.10.5与192.168.10.6
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif
  同理如此停掉10.1之后10.4eth3也会出现如图

页: [1]
查看完整版本: nginx+keepalived双主负载均衡