-> linux142:webcache Route 5 0 0
-> nb8048:webcache Route 5 0 0
然后作些测试,将187的eth0 利用ifconfig eth0 down,看看有没有切换到142去。
6.设定至此看起来都没问题,但是每次Primary Diretcor设备如果网路突然断掉,然后Primary网路又突然恢复的时候,会造成Primary与Secondary Director上的LVS Server都同时启动。有兴趣的人可以在primary Diretcor上用
# ifconfig eth0 down
将Primary的网路卡down下来,等一会约一分钟,再用
#ifconfig eth0 up
#route add –net 0.0.0.0 gw 10.144.43.254
然后,你再连上linux142与linux187上,输入ipvsadm –l,就会发现两边的LVS/Direct Routing都启动了,这显然不是我们所希望的结果。
要解决这个问题,需要利用mon这个dameon,来做到。
想法如下:
(1).每隔一段时间,去ping 10.144.43.254(ping gateway),若发现GATEWAY在连续六次都没有反应后,就要将lvs的服务关闭(/etc/init.d/lvs stop),此时认定是自己网路卡已经故障,无法Ping出去。因为即便是Gateway死掉,此时整个网路对外边已经没有作用,启动lvs也没用,故需要关闭他。
(2).若发现Gateway突然又Ping的到了,此时要将heartbeat service给restart(取得主动权)(/sbin/service heartbeat start),如此经过一段时间,Primary的Director将会取得LVS Server的位置,而Slave Director会回复到RealServer与Backup Director的位置。
7.为了解决LVS server同时启动的困扰,我们需要在mon服务中再加入一个hostgroup,/etc/mon/mon.cf内容如下:
#
# Extremely basic mon.cf file
#
#
# global options
#
cfbasedir = /etc/mon
pidfile = /var/run/mon.pid
statedir = /var/run/mon/state.d
logdir = /var/run/mon/log.d
dtlogfile = /var/run/mon/log.d/downtime.log
alertdir = /usr/lib/mon/alert.d
mondir = /usr/lib/mon/mon.d
maxprocs = 20
histlength = 100
randstart = 60s
authtype = userfile
userfile = /etc/mon/userfile
#
# group definitions (hostnames or IP addresses)
#
hostgroup server1 10.144.43.175
hostgroup server2 10.144.43.142
hostgroup server3 10.144.43.187
# network gateway
hostgroup server4 10.144.43.254
watch server1
service webcache
interval 5s
monitor http.monitor -p 8080 -t 10
allow_empty_group
period wd {Sun-Sat}
alert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.175 -W 5 -F dr
alertevery 1h
alertafter 6
upalert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.175 –W 5 -F dr -u 1
watch server2
service webcache
interval 5s
monitor http.monitor -p 8080 -t 10
period wd {Sun-Sat}
alert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.142 -W 5 -F dr
alertafter 6
alertevery 1h
upalert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.142 -W 5 -F dr -u 1
watch server3
service webcache
interval 5s
monitor http.monitor -p 8080 -t 10
period wd {Sun-Sat}
alert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.187 -W 5 -F dr
alertafter 6
alertevery 1h
numalerts 24
upalert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.187 -W 5 -F dr -u 1
watch server4
service ping
interval 10s
# 使用哪一个monitor去作测试
monitor ping.monitor 10.144.43.254
period wd {Sun-Sat}
# 每个小时丢一个alert
alertevery 1h
# 连续测试六次失败才丢出第一个alert
alertafter 6
# 最多丢12个alert
numalerts 12
# alert时呼叫heartbeat.alert
alert heartbeat.alert
# upalert时呼叫heartbeat.alert -u
upalert heartbeat.alert -u
# See /usr/doc for the original example...
8.从上面/etc/mon/mon.cf中,可以发现我们要自己写一个alert发生时被呼叫的script,这里我用perl 写了一个简单的Script放在(/usr/lib/mon/alert.d/heartbeat.alert)。
#!/usr/bin/perl
# heartbeat.alert - Linux Virtual Server alert for mon
#
# It can be activated by mon to remove a real server when the
# service is down , or add the server when the service is up
阅读(2272) | 评论(0) | 转发(0) |