Heartbeat实现web服务高可用
在之前的部署过程中,成功的部署并配置了heartbeat,而且也能实现两节点之间VIP的高可用,这里来配置并实现httpd服务的高可用。一、安装Apache
两台heartbeat节点服务器都先停止heartbeat服务。
/etc/init.d/heartbeat stop
分别在heartbeat01和heartbeat02上安装httpd服务
yum -y install httpd
分别在两个节点上执行
echo $HOSTNAME >>/var/www/html/index.html
chown -R apache:apache /var/www/html
/etc/init.d/httpd start
在浏览器中查看一下web服务
http://s3.运维网.com/wyfs02/M01/87/F8/wKiom1fk9o7CGDRHAAB2xla7bsM134.png-wh_500x0-wm_3-wmp_4-s_1879953107.png
http://s3.运维网.com/wyfs02/M00/87/F8/wKiom1fk9o6ALLBVAABvqvTxR00451.png-wh_500x0-wm_3-wmp_4-s_4236257510.png
二、配置heartbeat资源
定义资源:在资源管理器的配置文件中定义;/etc/ha.d/haresources,在/etc/ha.d/resource.d下有各种资源类型,当在资源配置文件中定义时就会调用这里的资源类型来运行相应的程序;
Heartbeat控制的脚本要求:
1)脚本路径要放入/etc/init.d/或/etc/ha.d/resource.d/目录下。
2)脚本执行需要以/etc/init.d/脚本名 stop|start方式。
3)脚本需要具备可执行权限
4)脚本的名称要和haresources中的名称一致(如:heartbeat01.contoso.com IPaddr::172.16.49.100/24/eth1 httpd)
这里把两个节点的haresources都修改为如下内容:
heartbeat01.contoso.comIPaddr::172.16.49.100/24/eth1 httpd
三、启动heartbeat并测试故障切换
分别在两个节点上执行
echo $HOSTNAME >>/var/www/html/index.html
然后,因为没有配置DNS服务器,所以在客户端windows的hosts文件中,添加如下内容:
172.16.49.100 www.contoso.com
http://s1.运维网.com/wyfs02/M00/87/F5/wKioL1fk-BjDhl57AACBZrO4qco056.png-wh_500x0-wm_3-wmp_4-s_558871368.png
下面的操作需要同时在两个heartbeat节点上进行:
/etc/init.d/httpd stop
/etc/init.d/heartbeat stop
检查一下服务的状态:
http://s1.运维网.com/wyfs02/M02/87/F5/wKioL1fk9uOzNOdiAAAc7_yQ9nk494.png-wh_500x0-wm_3-wmp_4-s_166335717.png
http://s1.运维网.com/wyfs02/M01/87/F8/wKiom1fk9uPh1lPXAAAZhIBk5yk825.png-wh_500x0-wm_3-wmp_4-s_2461467958.png
可以看到,两个节点上的httpd服务和heartbeat服务都是停止的状态。
然后同时执行/etc/init.d/heartbeat start命令,启动两个节点上的heartbeat服务。
http://s3.运维网.com/wyfs02/M00/87/F5/wKioL1fk9w2grN8uAAAtgGOCnHc781.png-wh_500x0-wm_3-wmp_4-s_4178055204.png
这里可以看到VIP在节点1 heartbeat01上,而且heartbeat01上的httpd服务也已经启动了。
http://s3.运维网.com/wyfs02/M02/87/F8/wKiom1fk9w3jUg2VAAAfBpmeF7I375.png-wh_500x0-wm_3-wmp_4-s_2728530989.png
而heartbeat02上没有VIP,且httpd服务出于关闭状态。
Windows客户端访问:
http://s1.运维网.com/wyfs02/M01/87/F5/wKioL1fk-GWRTwVIAACKToh2vJM617.png-wh_500x0-wm_3-wmp_4-s_1002673800.png
这时候我手动关闭heartbeat01上的heartbeat服务,再次查看两个节点的状态:
节点1:
# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
# ip addr |grep 172.16.49
inet 172.16.49.133/24 brd 172.16.49.255 scope global eth1
# service httpd status
httpd is stopped
节点2:
# ip a|grep 172.16.49
inet 172.16.49.134/24 brd 172.16.49.255 scope global eth1
inet 172.16.49.100/24 brd 172.16.49.255 scope global secondary eth1
# service httpd status
httpd (pid13469) is running...
#
Windows客户端访问:
http://s5.运维网.com/wyfs02/M02/87/F8/wKiom1fk9kjiE09SAABymRSQhf8612.png-wh_500x0-wm_3-wmp_4-s_2330188371.png
在heartbeat01停止服务后,heartbeat02成功的接管资源,并能提供服务。
下面再重新启动heartbeat01上的heartbeat服务,再分别查看一下两个节点的状态:
节点1:
# /etc/init.d/heartbeat status
heartbeat is stopped. No process
# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:Resource is stopped
Done.
# ip addr |grep 172.16.49
inet 172.16.49.133/24 brd 172.16.49.255 scope global eth1
inet 172.16.49.100/24 brd 172.16.49.255 scope global secondary eth1
# service httpd status
httpd (pid15545) is running...
节点2:
# ip a|grep 172.16.49
inet 172.16.49.134/24 brd 172.16.49.255 scope global eth1
# service httpd status
httpd is stopped
Windows客户端访问:
http://s1.运维网.com/wyfs02/M00/87/F8/wKiom1fk-YnC3TYPAABuzrTskEA833.png-wh_500x0-wm_3-wmp_4-s_1064086107.png
heartbeat01恢复之后,重新接管原有的服务,heartbeat02将资源交还给heartbeat01,并在同时关闭web服务。至此,heartbeat实现web服务高可用性完成。
页:
[1]