一.初步了解pacemaker集群
1、什么是pacemaker集群
Pacemaker是一个集群资源管理器。它利用集群基础构件(OpenAIS 、heartbeat或corosync)提供的消息和成员管理能力来探测并从节点或资源级别的故障中恢复,以实现群集服务(亦称资源)的最大可用性。
二.如何配置一个pacemaker集群
1、准备好两台虚拟机用于测试
节点1:172.25.2.1,madao1
节点2:172.25.2.2,madao2
2、安装pacemaker需要的软件
命令 | 功能 |
---|
yum install pcs pacemaker corosync fence-agents-all -y | 安装pcs、pacemaker、corosync、fence-agents-all软件 |
systemctl start pcsd.service | 开启该服务 |
systemctl enable pcsd.servic | 设置该服务开机自启 |
passwd hacluster | 给该用户设置密码 |


3、在任意节点操作
命令 | 功能 |
---|
pcs cluster auth madao1 madao2 | 进行认证,username为hacluster,密码为设置的密码 |

4、配置集群
命令 | 功能 |
---|
pcs cluster setup --start --name abel_cluster madao1 madao2 | 将madao1、madao2加入集群 |
pcs cluster start --all | 开启集群中的所有节点 |
pcs cluster enable --all | 将集群中的节点都设为开机自启 |
pcs cluster status | 查看集群的状态 |
pcs property set stonith-enabled=false | 禁用stonith |
pcs property set no-quorum-policy=ignore | 将投票半数以上设置为忽视,因为我只有两个节点 |
crm_verify -L -V | |


三.配置该集群实现apache的高可用
1、添加vip
vip我使用的是:172.25.2.100
pcs resource create VirtualIP IPaddr2 ip=172.25.2.100 cidr_netmask=24 nic=eth0 op monitor interval=30s |添加172.25.2.100/24为vip
ip a |查看是否有vip添加成功
pcs resource delete VirtualIP |删除现有的vip


2、配置apache
命令 | 功能 |
---|
systemctl start httpd | 开启apache服务 |
echo This is madao1 page >/var/www/html/index.html | 将该提示语写入madao1节点中的默认发布页面 |
echo This is madao2 page >/var/www/html/index.html | 将该提示语写入madao2节点中的默认发布页面 |
pcs resource create Web ocf: heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl=“http://127.0.0.1/” op monitor interval=1min | 将apache添加到集群中,文件读/etc/httpd/conf/httpd.conf,访问地址为本机的默认发布页面 |

3、配置完成后测试
在真机测试
命令 | 功能 |
---|
172.25.2.100 | 此时看到的页面为This is madao1 page |

在madao1节点中配置
命令 | 功能 |
---|
pcs cluster stop madao1 | 停止运行madaoi1节点 |

再次在真机中测试
命令 | 功能 |
---|
172.25.2.100 | 此时看到的页面为This is madao2 page |
