三、安装HeartBeat
通过yast2工具添加heartbeat,如图片2
图2 heartbeat安装
1)安装HeartBeat软件包。可以通过SuSE的光盘进行安装,安装命令如下:
#rpm -Uvh heartbeat-1.2.2-0.6.i586.rpm libnet-1.1.1-42.1.i586.rpm heartbeat-pils-1.2.2-0.6.i586.rpm heartbeat-stonith-1.2.2-0.6.i586.rpm
2)修改HeartBeat的配置文件
① 主配置文件/etc/ha.d/ha.cf
将/usr/share/doc/packages/heartbeat/目录下ha.cf、authkeys、haresources 三个文件考入/etc/ha.d/目录下,再将主配置文件/etc/ha.d/ha.cf修改如下:
node linux1
node linux2
keepalive 2
deadtime 30
warntime 10
initdead 120
auto_failback on
bcast eth1
ping 10.1.1.1
ping 10.1.1.2
respawn hacluster /usr/lib/heartbeat/ipfail
② 认证方式文件/etc/ha.d/authkeys
修改认证方式文件/etc/ha.d/authkeys如下:
auth 2
2 crc
③ 资源配置文件/etc/ha.d heresources
假设现在正在进行Apache服务的HA系统,这里设置的服务必须在/etc/ha.d/resource.d和/etc/rc.d/init.d下有响应的脚本。修改资源配置文件/etc/ha.d/haresources如下:
linux1 192.168.8.112 apache2
④ 拷贝配置文件到linux2
#scp /etc/ha.d/ha.cf 10.1.1.2:/etc/ha.d
#scp /etc/ha.d/authkeys 10.1.1.2:/etc/ha.d
#scp /etc/ha.d/haresources 10.1.1.2:/etc/ha.d
3)启动HeartBeat服务:
#chkconfig -s heartbeat on
#chmod 600 /etc/ha.d/authkeys
#/etc/init.d/heartbeat start
系统显示信息如下:
Starting High-Availability servicesheartbeat:2010/4/01_23:05:19 info: Neither logfile nor logfacility found.
heartbeat: 2010/4/01_23:05:19 info: Logging defaulting to /var/log/ha-log
heartbeat: 2010/4/01_23:05:19 info:**************************
heartbeat: 2010/4/01_23:05:19 info:Configuration validated.Starting heartbeat 1.2.2
done
通过运行"ps -ef|grep heartbeat"命令来查看进程:
root 4240 1 0 23:25 ? 00:00:01 heartbeat:heartbeat:master control process
nobody 4242 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:FIFO reader
nobody 4243 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:write:bcast eth1
nobody 4244 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:bcast eth1
nobody 4245 4240 0 23:05 ?00:00:00 heartbeat:heartbeat:write:ping 10.1.1.1
nobody 4246 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:ping 10.1.1.1
nobody 4247 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:write:ping 10.1.1.2
nobody 4248 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:ping 10.1.1.2
haclust 4254 4240 0 23:07 ? 00:00:00 /usr/lib/heartbeat/ipfail
1 安装Apache
1)安装Apache和相关软件包如下:
#rpm -Uvh apahe2-2.0.49-27.8.i586.rpm apache2-prefork-2.0.49-27.8.i586.rpm libapr0-2.0.49-27.8.i586.rpm
#SuSEconfig --module apache2
2)启动Apache:
/etc/init.d/apache2 start
并运行"ps -ef|grep apache"查看进程:
root 4387 1 10 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
wwwrun 4388 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
wwwrun 4389 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
wwwrun 4390 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
wwwrun 4391 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
wwwrun 4392 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
3)创建并编辑一个index.html文件:
#vi /srv/www/htdocs/index.html
在其中输入"linux ha"的字样,并保存退出。通过Client端访问浮动IP:192.168.8.112,在linux1上成功安装Apache服务后,在linux2上执行以上操作,并且同样测试其结果如图3。
图3 linux上的测试结果