buser 发表于 2018-12-29 12:26:27

keepalived与lvs结合使用配置实例

  keepalived可以实现两大功能是:健康检测和故障转移
  keepalived.conf的配置
global_defs {
   notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      10.0.22.245
    }
}
virtual_server 10.0.22.245 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 10.0.22.248 80 {
      weight 1
      TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
    real_server 10.0.22.249 80 {      
      weight    1                  
      TCP_CHECK {
            connect_timeout 8
            nb_get_retry 3
            delay_before_retry 3
            #connect_port 80
      }
   }
}  vrrp_instance相关参数说明:
  state:当时服务器的角色,为主或者为备
  interface:在哪个网卡进行设置
  virtual_router_id:虚拟路由id,多个keepalived通信时,此id要一致
  priority:当前服务器的优先级
  advert_int:探测间隔时间
  authentication:设置多个keepalived间的通信方式及密码
  virtual_ipaddress:需要虚拟的IP
  nopreempt:设置为非抢占模式,默认为抢占模式;即当MASTER故障恢复后,从BACKUP再抢回来

  virtual_server相关参数说明:
  delay_loop:
  lb_algo:定义lvs的轮询算法,相当于ipvsadm中的-s参数
  lb_kind:定义lvs的工作模式,相当于ipvsadm中的-g|-m|-i参数

  net_mask:指定VIP(虚拟IP)的子网掩码
  persistence_timeout:定义lvs的会话保持时间,相当于ipvsadm中的-p选项
  protocol:定义lvs使用什么协议,相当于ipvsadm中的-t|-u选项
  real_server相关参数说明:
  weight:设置RS的权重,相当于ipvsadm中的-w参数
  TCP_CHECK:当protocol为TCP时,为TCP_CHECK
  connect_timeout:后端主机的超时时长
  nb_get_retry:后端主机的重试次数
  delay_before_retry:每次重试之间的间隔时间
  connect_port:连接后端主机的端口,当real_server指定端口后,此参数可以省略



页: [1]
查看完整版本: keepalived与lvs结合使用配置实例