LVS + keepalived的实现

Posted 愤怒的绿萝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LVS + keepalived的实现相关的知识,希望对你有一定的参考价值。

! Configuration File for keepalived  
  
global_defs {  
   notification_email {  
         [email protected]
         [email protected]126.com  
   }  
   notification_email_from [email protected] 
   smtp_connect_timeout 3  
   smtp_server 127.0.0.1  
   router_id LVS_DEVEL  
}  
 
vrrp_script chk_schedown {
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
   interval 2
   weight -2
}
 
vrrp_instance VI_1 {  
    interface eth0  
    state MASTER  
    priority 101
    virtual_router_id 51 
    garp_master_delay 1 
 
    authentication {  
        auth_type PASS  
        auth_pass password  
    }  
 
    track_interface {  
       eth0    
    }  
 
    virtual_ipaddress {  
        172.16.100.1/16 dev eth0 label eth0:0
    }  
 
    track_script {  
        chk_schedown
    }    
} 
 
 
virtual_server 172.16.100.1 80 {
    delay_loop 6
    lb_algo rr 
    lb_kind DR
    persistence_timeout 50
    protocol TCP
 
#    sorry_server 192.168.200.200 1358
 
    real_server 172.16.100.11 80 {
        weight 1
        HTTP_GET {
            url { 
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
 
    real_server 172.16.100.12 80 {
        weight 1
        HTTP_GET {
            url { 
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}
 
 
如果要使用TCP_CHECK检测各realserver的健康状态,那么,上面关于realserver部分的定义也可以替换为如下内容:
virtual_server 172.16.100.1 80 {
    delay_loop 6
    lb_algo rr 
    lb_kind DR
    persistence_timeout 300
    protocol TCP
 
    sorry_server 127.0.0.1 80
 
    real_server 172.16.100.11 80 {
        weight 1
        TCP_CHECK {
        tcp_port 80
            connect_timeout 3
        }
    }
 
    real_server 172.16.100.12 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
            connect_timeout 3
          }
    }
}
 
说明:其中的sorry_server是用于定义所有realserver均出现故障时所用的服务器。

 

以上是关于LVS + keepalived的实现的主要内容,如果未能解决你的问题,请参考以下文章

初识keepalived——keepalived与LVS实现高可用

LVS基础及LVS+Keepalived实现双主高可用负载均衡

RedHat 7配置keepalived+LVS实现高可用的Web负载均衡

LVS(DR) + Keepalived 实现负载均衡

基于Keepalived实现LVS双主高可用集群

Lvs+keepalived+Nginx双机热备实现Nginx高可用