设为首页 收藏本站
查看: 650|回复: 1

[经验分享] corosync和pacemaker使用pcs构建高可用集群

[复制链接]

尚未签到

发表于 2017-10-26 10:53:44 | 显示全部楼层 |阅读模式
一、实验环境

系统版本:centos7
实验机器:
    pcs1:192.168.163.174

    pcs2:192.168.163.175

软件源:阿里云

二、安装过程

配置集群的前提:
1、时间同步(将时间同步写入计划任务)
2、主机名互相访问(hosts文件,主机名都要设置,我设置的是pcs1、pcs2)

现在两个节点上执行:
[iyunv@pcs1 ~]# yum install -y pacemaker pcs psmisc policycoreutils-python

启动 pcs 并且开机启动:
[iyunv@pcs1 ~]# systemctl start pcsd
[iyunv@pcs1 ~]# systemctl enable pcsd

修改用户 hacluster 的密码:
[iyunv@pcs1 ~]# echo redhat | passwd --stdin hacluster

注册pcs集群主机(默认使用用户名 hacluster 和 密码)
[iyunv@pcs1 ~]# pcs cluster auth pcs1 pcs2

在集群上注册两台主机:
[iyunv@pcs1 ~]# pcs cluster setup --name mycluster pcs1 pcs2 --force

启动集群

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

查看服务
[iyunv@pcs1 ~]# ps -ef |grep corosync
[iyunv@pcs1 ~]# ps -ef |grep pacemaker

查看集群相关的子节点的状态
[iyunv@pcs1 ~]# corosync-cfgtool -s
[iyunv@pcs1 ~]# corosync-cmapctl |grep  members

查看当前集群的描述信息
[iyunv@pcs1 ~]# pcs status

查看有没有报错
[iyunv@pcs1 ~]# crm_verify -L -V

因为我们没有配置STONITH,下面我们要关闭
[iyunv@pcs1 ~]# pcs property set stonith-enabled=false
[iyunv@pcs1 ~]# crm_verify -L -V
[iyunv@pcs1 ~]# pcs property list

安装crm来管路集群
解压进入目录执行 python setup.py install

查看集群状态
[iyunv@pcs1 ~]# crm
crm(live)crm status

先创建一个文件夹,并通过nfs共享挂载
[iyunv@pcs1 ~]# mkdir /nfs

[iyunv@pcs1 ~]# cat /etc/exports
/nfs *(rw)

重启一下服务
[iyunv@pcs1 ~]# systemctl restart nfs
[iyunv@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

三、测试

查看当前状态

1
2
3
4
5
6
7
8
9
10
11
12
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




正常访问网页
[iyunv@pcs1 nfs]# curl 192.168.163.100
nfs

现在将pcs1停掉
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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




接下来可以发现,其服务开启顺序是按照我们所设置的顺序开启
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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




正常访问网页
[iyunv@pcs1 nfs]# curl 192.168.163.100
nfs



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-405955-1-1.html 上篇帖子: oneproxy出现2103错误代码解决方案 下篇帖子: [linux] /proc/diskstats各列含义介绍以及磁盘使用率计算方式说明
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表