pacemaker实现apache高可用

Pacemaker实现apache高可用集群部署

Pacemaker集群搭建参考以下链接:

http://blog.csdn.net/abel_dwh/article/details/78475630

查看集群状态

[root@node2 ~]# pcs status
Cluster name: abel_cluster
Stack: corosync
Current DC: node2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Nov  8 16:48:19 2017
Last change: Wed Nov  8 16:44:57 2017 by root via cibadmin on node2
2 nodes configured
2 resources configured
Online: [ node1 node2 ]
Full list of resources:

添加VIP

首先要做的是配置一个IP地址,不管集群服务在哪运行,我们要一个固定的地址来提供服务。在这里我选择 192.168.122.20作为浮动IP,给它取一个好记的名字 ClusterIP 并且告诉集群每30秒检查它一次。

[root@node1 ~]# pcs resource create ClusterIP ocf:heartbeat:IPaddr2 ip=192.168.122.20 cidr_netmask=24 op monitor interval=30s
查看我们已经创建好的资源,一个vip现在已经在node12上运行

[root@node1 ~]# pcs status

Cluster name: abel_cluster
Stack: corosync
Current DC: node2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Nov  8 16:52:05 2017
Last change: Wed Nov  8 16:44:57 2017 by root via cibadmin on node2


2 nodes configured
2 resources configured


Online: [ node1 node2 ]


Full list of resources:


 ClusterIP	(ocf::heartbeat:IPaddr2):	Started node2
安装httpd(apache) 2节点

[root@node1 ~]# yum -y install httpd
给apache写一个默认首页

[root@node1 ~]# echo "This is node1 test" >/var/www/html/index.html
[root@node2 ~]# echo "This is node2 test" >/var/www/html/index.html
开启httpd的访问链接

[root@node1 ~]# vim /etc/httpd/conf/httpd.conf 
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
将apache添加到集群中

[root@node1 ~]# pcs resource create Web ocf:heartbeat:apache  configfile=/etc/httpd/conf/httpd.conf statusurl="http://127.0.0.1/server-status" op monitor interval=1min
确保资源在同一个节点运行

[root@node2 ~]# pcs constraint colocation add Web ClusterIP INFINITY
控制资源的启停顺序(先启ClusterIP再启动Web)

[root@node2 ~]# pcs constraint order ClusterIP then Web
最后我们访问测试


停止node2再次访问

[root@node1 ~]# pcs cluster stop node2
node2: Stopping Cluster (pacemaker)...
node2: Stopping Cluster (corosync)...


ok


猜你喜欢

转载自blog.csdn.net/abel_dwh/article/details/78479546
今日推荐