三、做DR router的Load Balance:
那如果今天我有一堆机器,而且在上面执行的服务都相当的重要,所以只有一部Director对这些重要工作来说,是非常危险的,万一这部Director死掉了,那我的服务不就毁了?因此在这儿要介绍「mon+heartbeat+fake+coda」的heartbeat与fake的安装与设定。
1、下载安装文件
从http://www.linux-ha.org/download/ 抓取下列RPM档案:
heartbeat-1.0.3-1.rh.8.0.1.i386.rpm
heartbeat-1.0.3-1.rh.8.0.1.src.rpm
heartbeat-ldirectord-1.0.3-1.rh.8.0.1.i386.rpm
heartbeat-pils-1.0.3-1.rh.8.0.1.i386.rpm
heartbeat-stonith-1.0.3-1.rh.8.0.1.i386.rpm
从http://rpmfind.net 抓取下列RPM档案:
libnet-1.1.0-1.rh.8.0.um.1.i386.rpm
perl-Authen-SASL-2.03-1.rh.8.0.um.1.noarch.rpm
perl-Convert-ASN1-0.16-2.rh.8.0.um.1.noarch.rpm
perl-IO-Socket-SSL-0.92-1.rh.8.0.um.1.noarch.rpm
perl-Mail-IMAPClient-2.2.7-1.rh.8.0.um.1.noarch.rpm
perl-Net-SSLeay-1.22-1.rh.8.0.um.1.i386.rpm
perl-Parse-RecDescent-1.80-8.noarch.rpm
perl-XML-NamespaceSupport-1.08-2.noarch.rpm
perl-XML-SAX-0.12-1.rh.8.0.um.1.noarch.rpm
从http://search.cpan.org抓取下列perl-ldap档案,目前最新版本是0.27版本,其实都无所谓,可以用就好了。
perl-ldap-0.25.tar.gz (我这儿用以前我抓的tar.gz档)
2、开始依照下列顺序安装:
# rpm -ivh perl-Convert-ASNI-0.16.2.rh.8.0.um.1.onarch.rpm
# perl -ivh perl-Authen-SASL-2.03-1.rh.8.0.um.1.noarch.rpm
# rpm -ivh perl-Net-SSLeay-1.22-1.rh.8.0.um.1.i386.rpm
# rpm -ivh perl-IO-Socket-SSL-0.92-1.rh.8.0.um.1.noarch.rpm
# rpm -ivh perl-Mail-IMAPClient-2.2.7-1.rh.8.0.um.1.noarch.rpm
# rpm -ivh perl-Parse-RecDescent-1.80-8.noarch.rpm
# rpm -ivh perl- NamespaceSupport-1.08-2.noarch.rpm
# rpm -ivh perl- XML-SAX-0.12-1.rh.8.0.um.1.noarch.rpm
# rpm -ivh libnet-1.1.0-1.rh.8.0.um.1.i386.rpm
# gzip -dc perl-ldap-0.25.tar.gz |tar xvf -
# cd perl-ldap-0.25
# perl Makefile
# make && make test && make install
# cd ..
需要的Perl module安装完毕,开始安装heartbeat的modules。
# rpm -ivh heartbeat-pils-1.0.3-1.rh.8.0.1.i386.rpm
# rpm -ivh heartbeat-stonith-1.0.3-1.rh.8.0.1.i386.rpm
# rpm -ivh heartbeat-1.0.3-1.rh.8.0.1.i386.rpm
下面这个module是一个整合所有功能的RPM,heartbeat官方网站有介绍。
# rpm -ivh --nodeps heartbeat-ldirectord-1.0.3-1.rh.8.0.1.i386.rpm
从http://www.linux-ha.org/这个网站上可以知道fake已经整合进heartbeat的功能里面,所以我们就不需要安装fake相关的程序了。
目前Linux-HA可以应用的方面如下:
o Web servers
o LVS director servers
o Mail servers
o Database servers
o Firewalls
o File servers
o DNS servers
o DHCP servers
o Proxy Caching servers
o etc.
我们这里的重点是要做LVS Director Servers的Failover机制,也就是要做HA(High availability)架构。所以对于heartbeat-ldirectord这个套件不作介绍,有兴趣的人请自行研究(http://www.linuxvirtualserver.org/HighAvailability.html)一文。
Linux-HA实验例子:
系统架构如同基本设置范例图形所示,只是这儿设置Primary Director为10.144.43.187 (linux187),而Secondary Director为10.144.43.142(linux142),而10.144.43.175(就是唯一的RealServer,但是事实上10.144.43.142与10.144.43.187上面还是有提供服务。简单的说就是Director可以互相备援,且Realserver失败的时候,会自动从Director上面将该笔资料自LVS的Routing Rule中消除。
1、在Linux142与Linux187上都将Mon与Heartbeat套件安装完成。且在/etc/rc.local中加入一个设定subinterface的shellscript(/root/conf/data)。
/root/conf/data 内容如下:
#!/bin/sh
# 开机时读取,设定LVS相关的设定值,此时扮演LVS中的RealServer的角色
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
ifconfig lo:0 10.144.43.185 netmask 255.255.255.255 broadcast 10.144.43.185
echo 1 >/proc/sys/net/ipv4/ip_forward
echo 1 >/proc/sys/net/ipv4/conf/all/hidden
echo 1 >/proc/sys/net/ipv4/conf/lo/hidden
route add -host 10.144.43.185 dev lo:0
/etc/rc.local内容如下:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don''t
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
# add subinterface
/root/conf/data
作这个动作的目的在于让Linux142、Linux187在开机的时候将lo:0这个subinterface加入在网络卡中,同时激活hidden避免ARP问题。记得chmod 755 data。
2、在Linux142与linux187中,接着设定Mon基本设定,修改/etc/mon/mon.cf,使其对nb8048、Linux187、linux142作监测。因为提供的服务是Port 8080,在/etc/services中的名称为(webcache)
#
# 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
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
http://netadmin.77169.com/HTML/20040615183600.html