corosync和pacemaker使用pcs构建高可用集群
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了corosync和pacemaker使用pcs构建高可用集群相关的知识,希望对你有一定的参考价值。
pcs构建高可用集群(基于crm管理)
一、实验环境
系统版本:centos7
实验机器:
pcs1:192.168.163.174
pcs2:192.168.163.175
软件源:阿里云
二、安装过程
配置集群的前提:
1、时间同步(将时间同步写入计划任务)
2、主机名互相访问(hosts文件,主机名都要设置,我设置的是pcs1、pcs2)
现在两个节点上执行:
[[email protected] ~]# yum install -y pacemaker pcs psmisc policycoreutils-python
启动 pcs 并且开机启动:
[[email protected] ~]# systemctl start pcsd
[[email protected] ~]# systemctl enable pcsd
修改用户 hacluster 的密码:
[[email protected] ~]# echo redhat | passwd --stdin hacluster
注册pcs集群主机(默认使用用户名 hacluster 和 密码)
[[email protected] ~]# pcs cluster auth pcs1 pcs2
在集群上注册两台主机:
[[email protected] ~]# pcs cluster setup --name mycluster pcs1 pcs2 --force
启动集群
[[email protected] ~]# pcs cluster start --all
查看服务
[[email protected] ~]# ps -ef |grep corosync
[[email protected] ~]# ps -ef |grep pacemaker
查看集群相关的子节点的状态
[[email protected] ~]# corosync-cfgtool -s
[[email protected] ~]# corosync-cmapctl |grep members
查看当前集群的描述信息
[[email protected] ~]# pcs status
查看有没有报错
[[email protected] ~]# crm_verify -L -V
因为我们没有配置STONITH,下面我们要关闭
[[email protected] ~]# pcs property set stonith-enabled=false
[[email protected] ~]# crm_verify -L -V
[[email protected] ~]# pcs property list
安装crm来管路集群
解压进入目录执行 python setup.py install
查看集群状态
[[email protected] ~]# crm
crm(live)crm status
先创建一个文件夹,并通过nfs共享挂载
[[email protected] ~]# mkdir /nfs
[[email protected] ~]# cat /etc/exports
/nfs *(rw)
重启一下服务
[[email protected] ~]# systemctl restart nfs
[[email protected] ~]# 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
正常访问网页
[[email protected] 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
正常访问网页
[[email protected] nfs]# curl 192.168.163.100
nfs
本文出自 “xhk777” 博客,请务必保留此出处http://xhk777.blog.51cto.com/13405744/1975960
以上是关于corosync和pacemaker使用pcs构建高可用集群的主要内容,如果未能解决你的问题,请参考以下文章
LINUX集群学习二——pacemaker+corosync+pcs实验
pcs+pacemaker+corosync+nfs配置高可用
http高可用+负载均衡 corosync + pacemaker + pcs
http高可用+负载均衡 corosync + pacemaker + pcs