蔷薇525 发表于 2018-11-9 08:45:52

keepalived高可用LVS与Nginx

# cd /etc/keepalived/  
# vim keepalived.conf
  
! Configuration File for keepalived
  

  
global_defs {
  
   notification_email {
  root@localhost
  
   }
  
   notification_email_from kaadmin@localhost
  
   smtp_server 127.0.0.1
  
   smtp_connect_timeout 30
  
   router_id LVS_DEVEL
  
}
  
vrrp_script chk_mt {
  
    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
  
    interval 1
  
    weight -2
  
}
  
vrrp_instance VI_1 {
  
    state MASTER               #node1须修改为BACKUP
  
    interface eth0
  
    virtual_router_id 51
  
    priority 100               #node1降低优先级
  
    advert_int 1
  
    authentication {
  
      auth_type PASS
  
      auth_pass 71988d704dcae985
  
    }
  
    virtual_ipaddress {
  
      192.168.0.80/32
  
    }
  
    track_script {
  chk_mt
  
    }
  
    notify_master "/etc/keepalived/notify.sh master"
  
    notify_backup "/etc/keepalived/notify.sh backup"
  
    notify_fault "/etc/keepalived/notify.sh fault"
  
}
  

  
virtual_server 192.168.0.80 80 {
  
    delay_loop 6   #服务器轮询6次超时
  
    lb_algo rr       #LVS调度算法
  
    lb_kind DR       #LVS转发方法
  
    nat_mask 255.255.255.0   #掩码
  
    persistence_timeout 50   #长链接时间
  
    protocol TCP               #tcp协议
  
    ha_suspend               #在无vip情形下,不再进行健康状态检测
  
    sorry_server 127.0.0.1 80      #当RS全宕机时,sorry_server提供错误页面
  
    real_server 192.168.0.100 80 {          #RS的ip,端口
  
      weight 1                            #权重
  
      HTTP_GET {                        #检测类型,这里是HTTP_GET
  
            url {                           #检测请求的类型,这里是状态检测
  
            path /
  status_code 200
  
            }
  
            connect_timeout 3               #连接超时时间
  
            nb_get_retry 3                  #重试次数
  
            delay_before_retry 3            #重试前延迟时间
  
      }
  
    }
  
   real_server 192.168.0.101 80 {
  
      weight 2
  
      HTTP_GET {
  
            url {
  
            path /
  
            status_code 200
  
            }
  
            connect_timeout 3
  
            nb_get_retry 3
  
            delay_before_retry 3
  
      }
  
    }
  

  
}


页: [1]
查看完整版本: keepalived高可用LVS与Nginx