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
watch server1
service webcache
interval 10s
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
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 10s
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
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 10s
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
alertevery 1h
upalert lvs.alert -P tcp -V 10.144.43.185:8080 -R 10.144.43.187 -W 5 -F dr -u 1
3.编辑lvs.alert同前面提过的lvs.alert档案,放在/usr/lib/mon/alert.d/中。记得
chmod 755 lvs.alert
4.设定Heartbeat套件(High Availability)。
4.1 利用rpm –q heartbeat –d 将Heartbeat三个重要的设定档案(ha.cf、authkeys、haresources),copy到/etc/ha.d目录下。
[root@linux142 conf]# rpm -q heartbeat -d
/usr/share/doc/heartbeat-1.0.3/authkeys
/usr/share/doc/heartbeat-1.0.3/ha.cf
/usr/share/doc/heartbeat-1.0.3/haresources
[root@linux142 conf]#
4.2 修改/etc/hosts内容如下:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
10.144.43.142 linux142
10.144.43.187 Linux187
10.144.43.175 nb8048
4.3修改/etc/ha.d/authkeys内容如下:
auth 1
1 sha1 doss123
其中doss123为重要的key。然后
# chmod 600 authkeys
4.4修改/etc/ha.d/ha.cf内容如下:
logfacility local0 # 使用syslogd
keepalive 2 # 每隔几秒送一次heartbeat讯号
deadtime 40 # 多长时间就认定Primary Server Dead
initdead 240
# hopfudge maximum hop count minus number of nodes in config
nice_failback on # 如果Service转移到Secondary,就不要再转移回Primary
hopfudge 1 # ???
udpport 1001 # 使用哪一个udp port
ucast eth0 10.144.43.142 # Primary用unicast送给Secondary,如果在 Secondary则送给Primary
node Linux187 # 给定cluster中的节点
node linux142 # 给定cluster中的节点
4.5修改/etc/ha.d/haresources内容如下:
Linux187 10.144.43.185 lvs mon
这里设定Linux187在/etc/hosts里面要有设定,否则会找不到。且名称必须等于「uname –n」的内容。上面的意思是说,当heartbeat两边启动时,Linux187与linux142都启动时,会有linux187取得LVS VIP的控制权。而他会启动后面两个Service,lvs(我们皆下来要写的启动Daemon 的shell script),而mon则是先前我们已经设定的好的mon daemon。
4.6 编写/etc/init.d/lvs(启动lvs daemon)内容如下:
#!/bin/sh
# /etc/init.d/lvs
# 当LVS Server启动时,也就是透过High Availability启动LVS程式时,
# 1.将Lo的hidden属性取消
# 2.将lo:0 down下来,将lo:0删除
# 3.设定相关LVS设定档案
PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH
IPVSADM=/sbin/ipvsadm
case "$1" in
start)
if [ -x $IPVSADM ]
then
# 因为我们有设定lo:0的loopbback 的subinterface所以要先将相关设定移除
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/hidden
echo 0 > /proc/sys/net/ipv4/conf/lo/hidden
route del -host 10.144.43.185 dev lo:0
ifconfig lo:0 down
# 建立Subinterface eth0:0
ifconfig eth0:0 10.144.43.185 netmask 255.255.255.255 broadcast 10.144.43.185
# 设定LVS/DR相关设定,建立8080 Port的Service
$IPVSADM -A -t 10.144.43.185:8080 -s rr
阅读(2076) | 评论(0) | 转发(0) |