您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
corosync资源及约束
发布时间:2019-05-02 18:52:52编辑:雪饮阅读()
上回讲到corosync与hearbeatv3实现了集群的搭建。今天就来看看基于该集群的资源的管理。
准备工作
我们这里并没有stonith,所以就先关闭了,看到他的错误提示就很不爽。
[root@node1 ~]# crm
crm(live)# configure
crm(live)configure# property stonith-enabled=false
crm(live)configure# commit
crm(live)configure# show
node node1.magedu.com
node node2.magedu.com
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false"
上面的语法结构特点其实就是crm的子命令方式。
vip资源添加
添加vip资源
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.2.139 nic=eth0 cidr_netmask=24
crm(live)configure# commit
资源迁移
查看当前webip资源挂载到了节点1上
[root@node1 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 01:22:22 2019
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node1.magedu.com
将vip资源迁移
[root@node1 ~]# crm resource migrate webip
WARNING: Creating rsc_location constraint 'cli-standby-webip' with a score of -INFINITY for resource webip on node1.magedu.com.
This will prevent webip from running on node1.magedu.com until the constraint is removed using the 'crm_resource -U' command or manually with cibadmin
This will be the case even if node1.magedu.com is the last node in the cluster
This message can be disabled with -Q
然后在看看vip资源又跑到节点2上了
[root@node1 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 01:27:27 2019
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node2.magedu.com
添加web资源
各个节点需要先准备好httpd服务,并且关闭开机自启并且服务当前也没有启动。
[root@node1 ~]# yum --nogpgcheck localinstall /test/Server/httpd-2.2.3-63.el5.i386.rpm
[root@node1 ~]# service httpd status
httpd is stopped
[root@node1 ~]# chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# primitive httpd lsb:httpd
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure#
资源添加ok
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 01:38:38 2019
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node2.magedu.com
httpd (lsb:httpd): Started node1.magedu.com
添加资源组
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# group webservice webip httpd
INFO: resource references in location:cli-standby-webip updated
crm(live)configure# verify
crm(live)configure# commit
添加ok
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 01:41:57 2019
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr): Started node2.magedu.com
httpd (lsb:httpd): Started node2.magedu.com
节点转备
[root@node2 ~]# crm node standby
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 01:44:56 2019
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Node node2.magedu.com: standby
Online: [ node1.magedu.com ]
我们会发现当已启动节点数没有达到法定票数,则资源就不启动了。
启用即使没有达到法定票数依然让资源启动
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# verify
crm(live)configure# commit
注意,这样配置后还要在crm->configure->edit中编辑如下:
node node1.magedu.com \
attributes standby="off"
node node2.magedu.com \
attributes standby="on"
primitive httpd lsb:httpd
primitive webip ocf:heartbeat:IPaddr \
params ip="192.168.2.139" nic="eth0" cidr_netmask="24"
group webservice webip httpd
location cli-standby-webip webservice \
rule $id="cli-standby-rule-webip" -inf: #uname eq node1.magedu.com
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
的标红部分都去除。
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# edit
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node node1.magedu.com
node node2.magedu.com
primitive httpd lsb:httpd
primitive webip ocf:heartbeat:IPaddr \
params ip="192.168.2.139" nic="eth0" cidr_netmask="24"
group webservice webip httpd
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
crm(live)configure# Ctrl-C, leaving
达成
[root@node2 ~]# crm node standby
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 02:04:50 2019
Stack: openais
Current DC: node2.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Node node2.magedu.com: standby
Online: [ node1.magedu.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr): Started node1.magedu.com
httpd (lsb:httpd): Started node1.magedu.com
注意:如果此时我们操作了资源转移,那么我们也要crm->configure->edit然后处理:
node node1.magedu.com
node node2.magedu.com \
attributes standby="on"
primitive httpd lsb:httpd
primitive webip ocf:heartbeat:IPaddr \
params ip="192.168.2.139" nic="eth0" cidr_netmask="24"
group webservice webip httpd
location cli-standby-webservice webservice \
rule $id="cli-standby-rule-webservice" -inf: #uname eq node1.magedu.com
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
标红的部分
排列约束、顺序约束、位置约束、资源粘性
[root@node2 ~]# crm
crm(live)# resource
crm(live)resource# stop webservice
crm(live)resource# cleanup webservice
Cleaning up webip on node1.magedu.com
Cleaning up webip on node2.magedu.com
Cleaning up httpd on node1.magedu.com
Cleaning up httpd on node2.magedu.com
Waiting for 5 replies from the CRMd..... OK
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# delete webservice
crm(live)configure# verify
crm(live)configure# commit
资源又分散了
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 02:27:31 2019
Stack: openais
Current DC: node2.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node1.magedu.com
httpd (lsb:httpd): Started node2.magedu.com
建立排列约束与顺序约束
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# colocation httpd_with_webip inf: webip httpd
crm(live)configure# order webip_before_httpd mandatory: webip httpd
crm(live)configure# verify
crm(live)configure# commit
资源又重新集结到一个节点了,都在节点2上
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 02:33:00 2019
Stack: openais
Current DC: node2.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node2.magedu.com
httpd (lsb:httpd): Started node2.magedu.com
添加位置约束
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# location webip_on_nodel webip rule 100: #uname eq node1.magedu.com
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# Ctrl-C, leaving
资源又全部集结到节点1了
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 02:37:06 2019
Stack: openais
Current DC: node2.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node1.magedu.com
httpd (lsb:httpd): Started node1.magedu.com
建立资源粘性
[root@node2 ~]# crm
crm(live)# configure
crm(live)configure# rsc_defaults resource-stickiness=200
crm(live)configure# verify
crm(live)configure# commit
资源又全部集结到节点1了
[root@node2 ~]# crm_mon --one-shot
============
Last updated: Sun Apr 28 02:40:38 2019
Stack: openais
Current DC: node2.magedu.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node1.magedu.com node2.magedu.com ]
webip (ocf::heartbeat:IPaddr): Started node1.magedu.com
httpd (lsb:httpd): Started node1.magedu.com
关键字词:corosync,资源,约束
下一篇:分布式复制块设备drbd