Configuration example of using keepalived with lvs
Keepalived can achieve two major functions: health detection and failover
Configuration of 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 eth2 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 related parameters description:
State: the role of the server at that time, either as a master or as a backup
Interface: which network card should be set up?
Virtual_router_id: virtual routing id, this id should be consistent when multiple keepalived communicate
Priority: priority of the current server
Advert_int: probe interval
Authentication: set the communication mode and password between multiple keepalived
Virtual_ipaddress: virtual IP is required
Nopreempt: set to non-preemptive mode. Default is preemptive mode, that is, when the MASTER fault recovers, it will be snatched back from BACKUP.
Virtual_server related parameters description:
Delay_loop:
Lb_algo: defines the polling algorithm for lvs, which is equivalent to the-s parameter in ipvsadm
Lb_kind: defines the working mode of lvs, which is equivalent to-g |-m |-I parameter in ipvsadm.
Net_mask: specifies the subnet mask of VIP (virtual IP)
Persistence_timeout: defines the session persistence time for lvs, which is equivalent to the-p option in ipvsadm
Protocol: defines what protocol lvs uses, which is equivalent to the-t |-u option in ipvsadm
Real_server related parameters description:
Weight: sets the weight of RS, which is equivalent to the-w parameter in ipvsadm
TCP_CHECK: TCP_CHECK when protocol is TCP
Connect_timeout: the timeout of the backend CVM
Nb_get_retry: number of retries of backend hosts
Delay_before_retry: the interval between each retry
Connect_port: the port that connects to the backend CVM. When real_server specifies the port, this parameter can be omitted.