从事运维两年多以来一直没有去碰heartbeat,以前凡是牵扯到HA的应用一般都是用keepalived。原因是因为heartbeat太笨重,配置起来不不像keepalived那么简单,如果一个应用越是复杂,那么它的故障并发率必然也就越高,恢复故障时用的时间也就越长。这次接触heartbeat是被逼无奈,因为公司线上的集群环境是用LVS+heartbeat为后端应用做的分发。所以要血补一下heartbeat上的知识。搭建heartbeat时遇到一些小麻烦,在此分享一下lvs+heartbeat的部署过程和搭建时该注意细节
logfile /var/log/ha.log #日志文件放置路径
keepalive 2 #心跳频率,默认为秒
deadtime 10 #判断节点死亡时间
warntime 5 #警告时间
initdead 30 #deadtime的最少两倍
udpport 694 #监听端口
bcast eth1 #心跳使用的网络接口
auto_failback off #当主节点恢复正常后,是否切换到主节点
node master #主节点
node backup #备用节点
ping_group group1 192.168.1.103 192.168.1.104 #real server地址
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
|
checktimeout=5 #检测超时时间
checkinterval=1 #检测时间
autoreload=yes #配置文件改动时是否自动加载
logfile="/var/log/ldirectord.log" # ldirectord日志路径
quiescent=no #检测到real server异常后是否保留该real server的配置
virtual=192.168.1.100:80 #VIP
real=192.168.1.103:80 gate #real server
real=192.168.1.104:80 gate #real server
service=http
checkport=80
protocol=tcp
persistent=600 #连接会话保持时间
scheduler=wlc #LVS负载算法
checktype=negotiate #通过交互来判断服务是否正常
|
master IPaddr::192.168.1.100 ipvsadm ldirectord
|
auth 3
3 md5 test
|
-A -t 192.168.1.100:80 -s wlc -p 600
-a -t 192.168.1.100:80 -r 192.168.1.103:80 -g
-a -t 192.168.1.100:80 -r 192.168.0.104:80 -g
|
Every 2.0s: ipvsadm -ln Tue Apr 12 00:33:58 2011
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.100:80 wlc persistent 600
-> 192.168.1.104:80 Route 1 0 0
-> 192.168.1.103:80 Route 1 0 0
|
#!/bin/bash
#description : start realserver
VIP=192.168.1.100
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
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
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
|