LVS + Keepalived 配置详解

Posted

tags:

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

LVS+Keepalived 配置

我们通过LVS-DR-MASTER,LVS-DR-BACKUP作为LVS负载均衡调度器,并且两者之间通过keepalived来两者之间的HAkeepalived本身就是为了LVS为开发的,所以说我们通过keepalived来进行LVS的配置就显得十分的方便。而且keepalived是直接操作ip_vs不用通过ipvsadm,所以更加方便。

 

实验拓扑图

 

技术分享

 

LVS节点1配置:

# yum install popt-devel openssl openssl-devel libnl-devel ipvsadm

# tar zxvf keepalived-1.2.7.tar.gz

# mkdir /usr/local/keepalived

# cd keepalived-1.2.7

# ./configure --prefix=/usr/local/keepalived/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/

# make && make install

# mkdir /etc/keepalived

# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

 

# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1       #虽然DR模式不需要开启此功能,但Keepalived 需要开启。

 

# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived 

global_defs { 

   notification_email { 

      [email protected]

   } 

   notification_email_from [email protected] 

   smtp_server mail.centaline.com.cn  #设置SMTP Server地址; 

   smtp_connect_timeout 30 

   router_id LVS_Node1            #备用节点名字不能相同:LVS_Node2

 

vrrp_instance VI_1 { 

    state MASTER            #备用节点可以改为:state BACKUP

    interface eth0   

    virtual_router_id 51       

    priority 100                #同组优先级不能相同

    advert_int 1 

    authentication { 

        auth_type PASS   

        auth_pass 1111   

    } 

    virtual_ipaddress { 

        10.6.2.195   

    } 

 

virtual_server 10.6.2.195 80 {   

    delay_loop 6         

    lb_algo wrr           

    lb_kind DR           

    nat_mask 255.255.255.0 

    persistence_timeout 50   

    protocol TCP         

    real_server 10.6.2.192 80 { 

        weight 1           

        TCP_CHECK { 

            connect_timeout 3      

            nb_get_retry 3         

            delay_before_retry 3   

        } 

    } 

    real_server 10.6.2.191 80 {   

        weight 1             

        TCP_CHECK { 

            connect_timeout 3        

            nb_get_retry 3           

            delay_before_retry 3     

        } 

    } 

 

然后把 keepalived.conf 配置文件复制到备用节点上即可。

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

Keepalived详解

集群部署LVS(dr模式)+Keepalived 高可用集群图文步骤详解

keepalived之vrrp_script详解

centos 7之keepalived双机热备理论+配置文件详解

搭建:LVS+Keepalived高可用Web服务群集环境

Keepalived配置文件详解(以Haproxy作为负载均衡器)