|
1.编辑/etc/hosts文件
vi /etc/hosts
192.168.203.57 fca-vm-search-apache1.synnex.org 主server主机名
192.168.203.58 fca-vm-search-apache2.synnex.org 备用server主机名
2. 在主备servers都安装libnet
wget http://www.ultramonkey.org/download/2.0.1/source/libnet/libnet.tar.gz
tar -zxvf libnet.tar.gz -C /usr/local/src/
cd /usr/local/src/libnet
./configure
make
make install
3. 在主备servers都安装heartbeat
wget http://www.ultramonkey.org/download/heartbeat/2.1.3/heartbeat-2.1.3.tar.gz
tar -zxvf heartbeat-2.1.3.tar.gz -C /usr/local/src
cd /usr/local/src/heartbeat-2.1.3
./configure
groupadd haclient
useradd -g haclient hacluster
make
make install
heartbeat安装完成后,自动在/etc/rc.d/init.d/目录下生成启动脚本heartbeat,启动heartbeat可以使用命令:
/etc/rc.d/init.d/heartbeat start
4.在主备servers上,将heartbeat作为系统服务
chkconfig --add heartbeat
chkconfig heartbeat on 开机自动启动
cd /usr/local/src/heartbeat-2.1.3/doc/
cp {ha.cf,haresources,authkeys} /usr/local/etc/ha.d/
5. 编辑ha.cf文件
#vi ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
ucast eth0 192.168.203.57 双机中对方节点的真实IP地址,非虚拟IP
auto_failback on 当主节点恢复时,是否切换回主节点,on 切换,off 不切换
node fca-vm-search-apache1.synnex.org 主节点uname -n
node fca-vm-search-apache2.synnex.org 备用节点uname -n
6.编辑authkeys文件 主备节点上这个文件必须是相同的
#vi authkeys
auth 1
1 crc
#chmod 600 authkeys
7.编辑haresources文件
#vi haresources 在主备节点上这个文件必须是相同的
fca-vm-search-apache1.synnex.org 192.168.203.76 httpd
(主节点名称) (虚拟IP地址) (需要高可用的服务(httpd),需要将这个服务配置为系统服务)
8.将apache作为系统服务
cp $apache_home/bin/apachectl /etc/init.d/httpd
例如:cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
chkconfig --add httpd
chkconfig --level 2345 httpd on
9.修改apache服务的httpd.conf
将Listen地址改为 虚拟IP:80, 本例中的虚拟IP为192.168.203.76
Listen 192.168.203.76:80
10.启动heartbeat服务,看否能访问apache服务,停掉heartbeat服务,看是否能访问apache服务
11. 在主节点上添加一个监控httpd服务的脚本,或者使用heartbear的crm(cluster resource manager)功能,监控http服务是否存活,如果已经停掉,则关闭heartbeat服务,从而将服务转移到备用server,并且发邮件通知管理员,我们使用的是脚本的方式,CRM如何配置,请看以下连接
http://blog.iyunv.com/kobeyan/article/details/7587899
#vi check_httpd_heartbeat.sh
#!/bin/sh
vip=192.168.203.76
touch /var/log/loe-ha.log #此文件记录apache正常运行的时间点
while :
do
status=`netstat -tln|grep $vip:80`
sleep 1 #设置监听周期,约1s
echo "`date`: Chief node's server is running normally." >> /var/log/loe-ha.log
if [ "$status"="" ];then
echo "Server is not running , please wait " >> /var/log/loe-ha.log
/etc/init.d/heartbeat stop
wait
mutt -e "my_hdr from:leeyleey@afd.com" -s "master httpd server is down, please check it ASAP" leey@afd.com < /var/log/loe-ha.log
fi
done |
|