TCM-caleng

简单、专注、优雅、快乐

基于VMware环境Linux服务器集群方案--LVS+Keepalived (2)

在上文中《基于VMware环境Linux服务器集群方案--LVS+Keepalived (1)》,其实仅使用了三台服务器(1LB+2Real Server),一旦LB挂掉,则整个服务瘫痪。或者Real Server的某台服务器挂掉,LB依然会将部分用户分配到这个服务器而使该用户无法访问。如何保证LVS服务器集群的高可用性呢?

本文将采用LVS+Keepalived,并增加一台Backup 服务器以备LB无法提供服务时自动接管负载均衡工作的方案。当然你也可以采用LVS+Heartbeat+Ldirectord方案,不过该方案配置比Keepalived稍显复杂(可参考文章:双机热备份及高密度集群)。

 

一、服务器设置及IP分配:(详细拓扑图请查看上文)

Virtual IP:192.168.195.10 -- 虚拟服务器IP,用户通过该IP入口

Load Balancer(Active Router):192.168.195.3 -- 真实服务器IP

Backup Router:192.168.195.4 -- 备份服务器IP

Real Server 1:192.168.195.5 -- WEB服务器IP

Real Server 2:192.168.192.6 -- WEB服务器IP

 

二、安装配置Keepalived

1、下载Keepalived最新版本,下载地址:http://www.keepalived.org/download.html,eg:keepalived-1.1.20.tar.gz,在Load Balancer和Backup Router均需安装Keepalived,安装过程如下:

#tar -zvxf keepalived-1.1.20.tar.gz

#cd keepalived-1.1.20

#./configure

#make && make install

#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/
#service keepalived start|stop #做成系统启动服务方便管理

 

2、配置Keepalived,#vim /etc/keepalived/keepalived.conf,内容如下:

! Configuration File for keepalived

global_defs {
   notification_email {
     admin@admin.com #接收Real Server 失效通知信息
   }
   notification_email_from lvs@admin.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL_1 #Backup服务器将此项改为LVS_DEVEL_2
}

vrrp_instance VI_1 {
    state MASTER #Backup服务器将此项改为BACKUP
    interface eth0
    virtual_router_id 51
    priority 150 #Backup服务器将此项改为100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.195.10 #VIP
    }
}

virtual_server 192.168.195.10 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.195.5 80 { #Real Server 1
        weight 3
        TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
    }
    }

    real_server 192.168.195.6 80 { #Real Server 2
    weight 3
    TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
    }
    }
}

 

3、运行Keepalived,在运行Keepalived之前,请先把上文中"lvsDR"脚本删除或停止运行。在Load Balancer和Backup Router分别执行:#service keepalived start。在浏览器输入http://192.168.195.10即可查看效果。关闭Load Balancer服务器,LVS将会自动切换至Backup Router。

 

三、错误调试

1、 keepalived的日志可以查看/var/log/messages中,命令:#tail -f /var/log/messages
2、在同一网段内virtual_router_id 值不能相同,如果相同会在messages中收到VRRP错误包,如下所示:
Mar 9 07:32:52 keepalivet2 Keepalived_vrrp: VRRP_Instance(VI_1) Dropping received VRRP packet...
Mar 9 07:32:53 keepalivet2 Keepalived_vrrp: ip address associated with VRID not present in received packet : 1992032266
Mar 9 07:32:53 keepalivet2 Keepalived_vrrp: one or more VIP associated with VRID mismatch actual MASTER advert
Mar 9 07:32:53 keepalivet2 Keepalived_vrrp: bogus VRRP packet received on eth0 !!!

解决办法:修改virtual_router_id的值,记住MASTER和BACKUP服务器的virtual_router_id值要相同,重启服务即可。

 

 

 

参考文档:

Keepalived手册:http://www.sanotes.net/html/y2009/331.html

CentOS5.2上配置Keepalived+LVS集群(DR模式):http://hi.baidu.com/lanbo0829/blog/item/b308f38a04614498a4c272de.html

 

 

如需转载,请注明:本文来自感染源博客http://blog.csdn.net/caleng ]

阅读更多
个人分类: 系统架构
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭