A-A+

heartbeat+LVS-ipvsadm+ldirectord搭建lvs DR集群

2008年11月25日 学习随笔 暂无评论 阅读 1 次

 
 
 
heartbeat:用于搭建双机热备环境,可以通过专门的心跳线来连接双机,也可以通过普通的网线来连接。
LVS-ipvsadm:负载均衡软件
ldirector:有两个主要功能,一是调用ipvsadm命令生成lvs的策略,二是对realserver进行健康检测

一、安装环境:
系统:
centos5.2 32位(自带内核默认支持lvs,不需要重新编译内核)
lvs:
VIP:10.129.60.199
主:eth0:10.129.60.188 eth1:192.168.23.128
从:eth0: 10.129.60.185 eth1:192.168.23.129
realserver:
10.129.60.197
10.129.60.198

二、安装
2.1 lvs服务器软件安装
#yum install ipvsadm
#yum install heartbeat
#yum install heartbeat-ldirectord
2.1 realserver软件安装
使用系统自带的apache测试
#yum install httpd
2.2 编辑LVS服务器配置文件
两台lvs服务器除了ha.cf中的ucast配置不同外,其余配置文件完全相同
#vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 30
warntime 10
initdead 120
#udpport        694
ucast eth1 192.168.23.129 #从LVS配192.168.23.128
auto_failback off
node    l1 #主要node的名字必须和uname -a看到的名字一致
node    l2
ping 10.129.60.129 #网关
respawn hacluster /usr/lib/heartbeat/ipfail

#vi /etc/ha.d/haresources
l1 IPaddr::10.129.60.199/25/eth0:0 ldirectord::ldirectord.cf LVSSyncDaemonSwap::master
l2

#vi /etc/ha.d/authkeys
auth 3
3 md5 J2hjS2rf9M4j#la[wue$vxGw&h(m3T6No$f

#mkdir /etc/ha.d/conf
#vi /etc/ha.d/conf/ldirectord.cf
checktimeout=3
checkinterval=1
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
emailalert="admin@domain.com"
emailalertfreq=3600
emailalertstatus=all
quiescent=no

virtual=10.129.60.199:80
        real=10.129.60.197:80 gate
        real=10.129.60.198:80 gate
        fallback=127.0.0.1:80 gate #realserver全部失败,vip指向本机80端口。在VIP维护的时候非常有用
        service=http
        request="hb.html" #用于健康检测的url,realserver上需要建立此文件,内容需要包含work
        receive="work"    #用于健康检测的url包含的关键字
        scheduler=rr
        persistent=600
        #netmask=255.255.255.255
        protocol=tcp
        checktype=negotiate
        checkport=80
        request="hb.html"
        receive="work"
2.3、realserver配置文件
#vi /etc/rc.local     #rc.local可以随系统一起启动
echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
/sbin/ifconfig lo:0 10.129.60.199 netmask 255.255.255.255 up

三、启动
3.1 lvs服务器
#/etc/init.d/heartbeat start
3.2 realserver
#source /etc/rc.local
#/etc/init.d/httpd start

四、测试
主从lvs的切换命令
#/usr/lib/heartbeat/hb_takeover
有问题注意查看heartbeat的日志文件:/var/log/ha-log

 

给我留言

Copyright © 浩然东方 保留所有权利.   Theme  Ality 07032740

用户登录