实验环境
vmware workstation 虚拟机
四台linux虚拟机均使用redhat 5.4 内核版本号为:2.6.18-164.el5
使用192.168.10.0
实验拓扑
实验配置
分发器上 a.abc.com与分发器上 b.abc.com 的操作相同,如下:
设置本地的dns指向
[root@a ha.d]# vim /etc/resolv.conf
nameserver 192.168.10.101
修改服务器的名称
[root@a ha.d]# hostname a.abc.com
[root@a ha.d]# vim /etc/sysconfig/network
3 HOSTNAME=a.abc.com
安装heartbeat相关的软件
[root@a ~]# ls *.rpm
heartbeat-2.1.4-9.el5.i386.rpm heartbeat-devel-2.1.4-9.el5.i386.rpm heartbeat-gui-2.1.4-9.el5.i386.rpm heartbeat-ldirectord-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm perl-MailTools-1.77-1.el5.noarch.rpmyum localinstall *.rpm -y --nogpgcheck
cp /usr/share/doc/heartbeat-2.1.4/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.4/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.4/haresources /etc/ha.d/设置分发器的验证方式及口令
[root@a ~]# cd /etc/ha.d
[root@a ha.d]# vim authkeys
27 auth 3
28 3 md5 123456[root@a ha.d]# chmod 600 authkeys
定义群集中的节点及探测网卡
[root@a ha.d]# vim ha.cf
95 bcast eth0
214 node a.abc.com
215 node b.abc.com定义群集中的资源及默认主节点
[root@a ha.d]# vim haresources
45 a.abc.com IPaddr::192.168.10.101/24/eth0/192.168.10.255 ldirectord::ldirectord.cf
[root@a ha.d]# vim ldirectord.cf
12 checktimeout=3 #检测的超时时间
13 checkinterval=1 #时间间隔15 autoreload=yes #自动加载配置
21 quiescent=no #静态模式
24 virtual=192.168.10.101:80 #数据包的访问目标地址及端口
25 real=192.168.10.200:80 gate #内部的真正的服务器 26 real=192.168.10.201:80 gate #内部的真正的服务器29 service=http #测试使用的服务类型
30 request=".test.html" #测试的请求网页 31 receive="ok" #请求的匹配内容33 scheduler=rr #调度算法
36 protocol=tcp #连接的类型
37 checktype=negotiate #使用的探测手段,发送基于该服务的数据请求检测服务的可用性319 virtual=192.168.10.101:53 #数据包的访问目标地址及端口
320 real=192.168.10.200:53 gate #内部的真正的服务器321 real=192.168.10.201:53 gate #内部的真正的服务器
323 service=dns #测试使用的服务类型
324 scheduler=rr #调度算法327 protocol=udp #连接的类型
328 checktype=connect #使用的探测手段,与服器之间建立tcp/ip连接然后从新启动heartbeat
使用命令 “service heartbeat restart”
后方的web与dns服务器的配置
web1.abc.com与web2.abc.com服务器上的配置:如下以web1.abc.com站点为例
[root@web1 ~]# hostname web1.abc.com
[root@web1 ~]# vim /etc/sysconfig/network
3 HOSTNAME=web1.abc.com[root@web1 ~]# mount /dev/cdrom /mnt/cdrom/
[root@web1 ~]# cd /mnt/cdrom/Server/
[root@web1 Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm bind-chroot-9.3.6-4.P1.el5.i386.rpm caching-nameserver-9.3.6-4.P1.el5.i386.rpm httpd-2.2.3-31.el5.i386.rpm
[root@web1 ~]# echo "ok" > /var/www/html/.test.html
[root@web1 ~]# echo "web1" > /var/www/html/index.html
配置named服务器 最好将dns 服务器一边设置成主的一边设置成辅助的dns服务器
[root@web1 etc]# pwd
/var/named/chroot/etc [root@web1 etc]# ll 总计 20 -rw-r--r-- 1 root root 405 10-05 19:18 localtime -rw-r----- 1 root named 1230 2009-07-30 named.caching-nameserver.conf -rw-r----- 1 root named 1224 10-14 02:12 named.conf -rw-r----- 1 root named 1040 10-14 04:32 named.rfc1912.zones -rw-r----- 1 root named 113 10-14 01:52 rndc.key[root@web1 ~]# cd /var/named/chroot/etc
[root@web1 etc]# vim named.conf
15 listen-on port 53 { any; };
27 allow-query { any; };
28 allow-query-cache { any; };37 match-clients { any; };
38 match-destinations { any; };[root@web1 etc]# vim named.rfc1912.zones
27 zone "abc.com" IN {
28 type master; 29 file "abc.com.zone"; 30 allow-update { none; }; 31 };[root@web1 named]# vim abc.com.zone
1 $TTL 86400
2 @ IN SOA ns.abc.com. root.abc.com ( 3 42 ; serial (d. a dams) 4 3H ; refresh 5 15M ; retry 6 1W ; expiry 7 1D ) ; minimum 9 @ IN NS ns.abc.com. 10 ns.abc.com. IN A 192.168.10.101 11 www IN A 192.168.10.101[root@web1 named]# vim /etc/resolv.conf
nameserver 192.168.10.101
[root@web1 named]# service named start
启动 named: [确定][root@web1 named]# chkconfig named on
此时测试的截图如图所示
关闭web1.abc.com上的httpd服务器
关闭web2.abc.com上的dns服务器
测试监控正常且访问正常
checktype = connect│external│negotiate│off│on│ping│checktimeoutN
Type of check to perform.
Negotiate sends a request and matches a receive string. Connect only attemts to make a TCP/IP connection, thus the request and receive strings may be omitted.
If check-type is a number then negotiate and connect is combined so that after each N connect attempts one negotiate attempt is performed. This is useful to check often if a service answers and in much longer intervalls a negotiating check is done.
Ping means that ICMP ping will be used to test the availabil-ity of real servers. Ping is also used as the connect check for UDP services.
Off means no checking will take place and no real or fallback servers will be activated. On means no checking will take place and real servers will always be activated. Default is negotiate.
这里使用的ping及connect仅仅用于检测一台主机是否存在。不能严格意义上的判断主机上的服务器的运行状态。
最好的用于检测后方服务运行状态的方式是 Negotiate 。但是我未能完成这样的测试工作。