pcs构建高可用集群(基于crm管理)


一、实验环境


系统版本:centos7

实验机器:

    pcs1:192.168.163.174

    pcs2:192.168.163.175

软件源:阿里云


二、安装过程


配置集群的前提:

1、时间同步(将时间同步写入计划任务)

2、主机名互相访问(hosts文件,主机名都要设置,我设置的是pcs1、pcs2)


现在两个节点上执行:

[root@pcs1 ~]# yum install -y pacemaker pcs psmisc policycoreutils-python


启动 pcs 并且开机启动:

[root@pcs1 ~]# systemctl start pcsd

[root@pcs1 ~]# systemctl enable pcsd


修改用户 hacluster 的密码:

[root@pcs1 ~]# echo redhat | passwd --stdin hacluster


注册pcs集群主机(默认使用用户名 hacluster 和 密码)

[root@pcs1 ~]# pcs cluster auth pcs1 pcs2


在集群上注册两台主机:

[root@pcs1 ~]# pcs cluster setup --name mycluster pcs1 pcs2 --force


启动集群


[root@pcs1 ~]# pcs cluster start --all


查看服务

[root@pcs1 ~]# ps -ef |grep corosync

[root@pcs1 ~]# ps -ef |grep pacemaker


查看集群相关的子节点的状态

[root@pcs1 ~]# corosync-cfgtool -s

[root@pcs1 ~]# corosync-cmapctl |grep  members


查看当前集群的描述信息

[root@pcs1 ~]# pcs status


查看有没有报错

[root@pcs1 ~]# crm_verify -L -V


因为我们没有配置STONITH,下面我们要关闭

[root@pcs1 ~]# pcs property set stonith-enabled=false

[root@pcs1 ~]# crm_verify -L -V

[root@pcs1 ~]# pcs property list


安装crm来管路集群

解压进入目录执行 python setup.py install


查看集群状态

[root@pcs1 ~]# crm

crm(live)crm status


先创建一个文件夹,并通过nfs共享挂载

[root@pcs1 ~]# mkdir /nfs


[root@pcs1 ~]# cat /etc/exports

/nfs *(rw)


重启一下服务

[root@pcs1 ~]# systemctl restart nfs

[root@pcs1 ~]# systemctl restart rpcbind

配置

crm(live)# configure 

crm(live)configure# 

crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.163.100


##配置好之后用show查看

crm(live)configure# show


#检查脚本是否有错,或者提交

crm(live)configure# verify

crm(live)configure# commit


绑定http(http要设置为开机启动)

primitive webserver system:httpd


绑定资源在同一个节点

group webservice webip webserver


创建一个nfs挂载

primitive nfs ocf:heartbeat:Filesystem device:pcs1/nfs directory:/var/www/html fstype:nfs


绑定资源在同一节点

colocation webservice inf: webip webserver nfs


按照顺序启动

order webip_nfs_webserver Mandatory: webip webserver nfs


三、测试


查看当前状态

crm(live)# status
Stack: corosync
Current DC: pcs2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 01:00:42 2017
Last change: Wed Oct 25 01:00:22 2017 by root via crm_attribute on pcs2
2 nodes configured
3 resources configured
Online: [ pcs1 pcs2 ]
Full list of resources:
 webip(ocf::heartbeat:IPaddr):Started pcs1
 webserver(systemd:httpd):Started pcs1
 nfs(ocf::heartbeat:Filesystem):Started pcs1


正常访问网页

[root@pcs1 nfs]# curl 192.168.163.100

nfs


现在将pcs1停掉

crm(live)# node standby
crm(live)# status
Stack: corosync
Current DC: pcs2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 01:01:56 2017
Last change: Wed Oct 25 01:01:52 2017 by root via crm_attribute on pcs1

2 nodes configured
3 resources configured

Node pcs1: standby
Online: [ pcs2 ]

Full list of resources:

 webip	(ocf::heartbeat:IPaddr):	Stopped
 webserver	(systemd:httpd):	Stopped
 nfs	(ocf::heartbeat:Filesystem):	Stopped


接下来可以发现,其服务开启顺序是按照我们所设置的顺序开启

crm(live)# status
Stack: corosync
Current DC: pcs2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 01:01:58 2017
Last change: Wed Oct 25 01:01:52 2017 by root via crm_attribute on pcs1

2 nodes configured
3 resources configured

Node pcs1: standby
Online: [ pcs2 ]

Full list of resources:

 webip	(ocf::heartbeat:IPaddr):	Started pcs2
 webserver	(systemd:httpd):	Stopped
 nfs	(ocf::heartbeat:Filesystem):	Started pcs2
crm(live)# status
Stack: corosync
Current DC: pcs2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 01:02:01 2017
Last change: Wed Oct 25 01:01:52 2017 by root via crm_attribute on pcs1

2 nodes configured
3 resources configured

Node pcs1: standby
Online: [ pcs2 ]

Full list of resources:

 webip	(ocf::heartbeat:IPaddr):	Started pcs2
 webserver	(systemd:httpd):	Started pcs2
 nfs	(ocf::heartbeat:Filesystem):	Started pcs2


正常访问网页

[root@pcs1 nfs]# curl 192.168.163.100

nfs