service: name=corosync state=restarted
- hosts: corosync remote_user: root vars: crmsh: crmsh-1.2.6-4.el6.x86_64.rpm pssh: pssh-2.3.1-2.el6.x86_64.rpm tasks: - name: corosync installing yum: name=corosync state=present - name: pacemaker installing yum: name=pacemaker state=present - name: crmsh rpm packages copy: src=/ansible/corosync/packages/{{ crmsh }} dest=/tmp/{{ crmsh }} - name: pssh rpm packages copy: src=/ansible/corosync/packages/{{ pssh }} dest=/tmp/{{ pssh }} - name: crmsh installing command: yum -y install /tmp/{{ crmsh }} /tmp/{{ pssh }} - name: authkey configure file copy: src=/ansible/corosync/conf/authkey dest=/etc/corosync/authkey - name: authkey mode 400 file: path=/etc/corosync/authkey mode=400 notify: - restart corosync - name: corosync.conf configure file copy: src=/ansible/corosync/conf/corosync.conf dest=/etc/corosync/corosync.conf tags: - conf notify: - restart corosync - name: ensure the corosync service startup on boot service: name=corosync state=started enabled=yes handlers: - name: restart corosync service: name=corosync state=restarted
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.8.77 crm(live)configure# verify crm(live)configure# commit crm(live)configure# show node node2.chinasoft.com node node4.chinasoft.com primitive webip ocf:heartbeat:IPaddr \ params ip="192.168.8.77" property $id="cib-bootstrap-options" \ dc-version="1.1.10-14.el6-368c726" \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes="2" \ stonith-enabled="false" \ no-quorum-policy="ignore"
crm(live)configure# primitive webserver lsb:httpd crm(live)configure# verify crm(live)configure# commit crm(live)configure# show node node2.chinasoft.com node node4.chinasoft.com primitive webip ocf:heartbeat:IPaddr \ params ip="192.168.8.77" primitive webserver lsb:httpd property $id="cib-bootstrap-options" \ dc-version="1.1.10-14.el6-368c726" \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes="2" \ stonith-enabled="false" \ no-quorum-policy="ignore"
crm(live)configure# group webservice webip webserver crm(live)configure# verify crm(live)configure# commit crm(live)configure# show node node2.chinasoft.com node node4.chinasoft.com primitive webip ocf:heartbeat:IPaddr \ params ip="192.168.8.77" primitive webserver lsb:httpd group webservice webip webserver property $id="cib-bootstrap-options" \ dc-version="1.1.10-14.el6-368c726" \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes="2" \ stonith-enabled="false" \ no-quorum-policy="ignore"
# standby node2.chinasoft.com crm(live)node# cd crm(live)# status Last updated: Mon Apr 25 19:11:07 2016 Last change: Mon Apr 25 19:11:04 2016 via crm_attribute on node2.chinasoft.com Stack: classic openais (with plugin) Current DC: node4.chinasoft.com - partition with quorum Version: 1.1.10-14.el6-368c726 2 Nodes configured, 2 expected votes 2 Resources configured Node node2.chinasoft.com: standby Online: [ node4.chinasoft.com ] Resource Group: webservice webip (ocf::heartbeat:IPaddr):Started node4.chinasoft.com webserver (lsb:httpd):Started node4.chinasoft.com
# crm node online node2.chinasoft.com # crm status Last updated: Mon Apr 25 19:13:09 2016 Last change: Mon Apr 25 19:13:06 2016 via crm_attribute on node4.chinasoft.com Stack: classic openais (with plugin) Current DC: node4.chinasoft.com - partition with quorum Version: 1.1.10-14.el6-368c726 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node2.chinasoft.com node4.chinasoft.com ] Resource Group: webservice webip (ocf::heartbeat:IPaddr):Started node4.chinasoft.com webserver (lsb:httpd):Started node4.chinasoft.com
# crm configure crm(live)configure# stop webservice ERROR: syntax: stop webservice crm(live)configure# cd crm(live)# resource crm(live)resource# stop webservice crm(live)resource# status webservice resource webservice is NOT running crm(live)resource# cd crm(live)# configure crm(live)configure# delete webservice crm(live)configure# show node node2.chinasoft.com \ attributes standby="off" node node4.chinasoft.com primitive webip ocf:heartbeat:IPaddr \ params ip="192.168.8.77" primitive webserver lsb:httpd property $id="cib-bootstrap-options" \ dc-version="1.1.10-14.el6-368c726" \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes="2" \ stonith-enabled="false" \ no-quorum-policy="ignore" crm(live)configure# commit
crm(live)# configure crm(live)configure# colocation webserver_with_webip inf: webserver webip crm(live)configure# show node node2.chinasoft.com \ attributes standby="off" node node4.chinasoft.com primitive webip ocf:heartbeat:IPaddr \ params ip="192.168.8.77" primitive webserver lsb:httpd colocation webserver_with_webip inf: webserver webip property $id="cib-bootstrap-options" \ dc-version="1.1.10-14.el6-368c726" \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes="2" \ stonith-enabled="false" \ no-quorum-policy="ignore" crm(live)configure# show xml <?xml version="1.0" ?> <cib num_updates="9" dc-uuid="node4.chinasoft.com" update-origin="node2.chinasoft.com" crm_feature_set="3.0.7" validate-with="pacemaker-1.2" update-client="cibadmin" epoch="13" admin_epoch="0" cib-last-written="Mon Apr 25 19:17:30 2016" have-quorum="1"> <configuration> <crm_config> <cluster_property_set id="cib-bootstrap-options"> <nvpair id="cib-bootstrap-options-dc-version" name="dc-version" value="1.1.10-14.el6-368c726"/> <nvpair id="cib-bootstrap-options-cluster-infrastructure" name="cluster-infrastructure" value="classic openais (with plugin)"/> <nvpair id="cib-bootstrap-options-expected-quorum-votes" name="expected-quorum-votes" value="2"/> <nvpair name="stonith-enabled" value="false" id="cib-bootstrap-options-stonith-enabled"/> <nvpair name="no-quorum-policy" value="ignore" id="cib-bootstrap-options-no-quorum-policy"/> </cluster_property_set> </crm_config> <nodes> <node id="node2.chinasoft.com" uname="node2.chinasoft.com"> <instance_attributes id="nodes-node2.chinasoft.com"> <nvpair id="nodes-node2.chinasoft.com-standby" name="standby" value="off"/> </instance_attributes> </node> <node id="node4.chinasoft.com" uname="node4.chinasoft.com"/> </nodes> <resources> <primitive id="webip" class="ocf" provider="heartbeat" type="IPaddr"> <instance_attributes id="webip-instance_attributes"> <nvpair name="ip" value="192.168.8.77" id="webip-instance_attributes-ip"/> </instance_attributes> </primitive> <primitive id="webserver" class="lsb" type="httpd"/> </resources> <constraints> <rsc_colocation id="webserver_with_webip" score="INFINITY" rsc="webserver" with-rsc="webip"/> </constraints> </configuration> </cib>
<pre name="code" class="plain">crm(live)configure# location webip_on_node4 webip 200: node4.chinasoft.com crm(live)configure# verify crm(live)configure# commit crm(live)configure# cd crm(live)# status Last updated: Mon Apr 25 19:32:59 2016 Last change: Mon Apr 25 19:32:57 2016 via cibadmin on node2.chinasoft.com Stack: classic openais (with plugin) Current DC: node4.chinasoft.com - partition with quorum Version: 1.1.10-14.el6-368c726 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node2.chinasoft.com node4.chinasoft.com ] webip (ocf::heartbeat:IPaddr):Started node4.chinasoft.com webserver (lsb:httpd):Started node4.chinasoft.com
webserver (lsb:httpd):Started node4.chinasoft.com
删除资源的方法
# crm resource
crm(live)resource# stop vip
crm(live)resource# stop webip
crm(live)resource# stop webserver
crm(live)resource# cd
crm(live)# configure
crm(live)configure# delete
cib-bootstrap-options node4.chinasoft.com webip webip_on_node4 webserver_with_webip
node2.chinasoft.com vip webip_before_webserver webserver
crm(live)configure# delete vip
crm(live)configure# delete webserver
crm(live)configure# delete webip
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# cd
crm(live)# status
Last updated: Tue Apr 26 15:56:37 2016
Last change: Tue Apr 26 15:56:33 2016 via cibadmin on node4.chinasoft.com
Stack: classic openais (with plugin)
Current DC: node4.chinasoft.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
0 Resources configured
Online: [ node2.chinasoft.com node4.chinasoft.com ]
crm(live)# configure
crm(live)configure# show
node node2.chinasoft.com \
attributes standby="off"
node node4.chinasoft.com \
attributes standby="off"
property $id="cib-bootstrap-options" \
dc-version="1.1.10-14.el6-368c726" \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore" \
last-lrm-refresh="1461657233"
这样定义代表集群中每一个资源的默认权重为100
crm(live)configure# rsc_defaults resource-stickiness=100
crm(live)configure# verify
crm(live)configure# commit
定义webstore、webip并添加到webservice组中
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="192.168.8.20:/sharestore" directory="/web/htdocs" fstype="nfs" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart
crm(live)configure# verify
crm(live)configure# primitive webserver lsb:httpd op monitor interval=30s timeout=20s on-fail=restart
crm(live)configure# verify
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.8.77 op monitor interval=30s timeout=20s on-fail=restart
crm(live)configure# verify
crm(live)configure# group webservice webip webstore webserver
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node node2.chinasoft.com \
attributes standby="off"
node node4.chinasoft.com \
attributes standby="off"
primitive webip ocf:heartbeat:IPaddr \
params ip="192.168.8.77" \
op monitor interval="30s" timeout="20s" on-fail="restart"
primitive webserver lsb:httpd \
op monitor interval="30s" timeout="20s" on-fail="restart"
primitive webstore ocf:heartbeat:Filesystem \
params device="192.168.8.20:/sharestore" directory="/web/htdocs" fstype="nfs" \
op monitor interval="20s" timeout="40s" \
op start timeout="60s" interval="0" \
op stop timeout="60s" on-fail="restart" interval="0"
group webservice webip webstore webserver
property $id="cib-bootstrap-options" \
dc-version="1.1.10-14.el6-368c726" \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore" \
last-lrm-refresh="1461657233"
rsc_defaults $id="rsc-options" \
resource-stickiness="100"
定义先后顺序
crm(live)configure# order webip_before_webstore_before_webserver mandatory: webip webstore webserver
crm(live)configure# show xml
crm(live)# status
Last updated: Tue Apr 26 16:48:20 2016
Last change: Tue Apr 26 16:47:17 2016 via cibadmin on node2.chinasoft.com
Stack: classic openais (with plugin)
Current DC: node4.chinasoft.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node2.chinasoft.com node4.chinasoft.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr):Started node2.chinasoft.com
webstore (ocf::heartbeat:Filesystem):Started node2.chinasoft.com
webserver (lsb:httpd):Started node2.chinasoft.com
[root@node4 ~]# crm node online node4.chinasoft.com
[root@node4 ~]# crm status
Last updated: Tue Apr 26 16:53:15 2016
Last change: Tue Apr 26 16:53:13 2016 via crm_attribute on node4.chinasoft.com
Stack: classic openais (with plugin)
Current DC: node4.chinasoft.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node2.chinasoft.com node4.chinasoft.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr):Started node2.chinasoft.com
webstore (ocf::heartbeat:Filesystem):Started node2.chinasoft.com
webserver (lsb:httpd):Started node2.chinasoft.com
将node2置为standby则node4上线顶替
[root@node4 ~]# crm status
Last updated: Tue Apr 26 16:53:20 2016
Last change: Tue Apr 26 16:53:13 2016 via crm_attribute on node4.chinasoft.com
Stack: classic openais (with plugin)
Current DC: node4.chinasoft.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node2.chinasoft.com node4.chinasoft.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr):Started node2.chinasoft.com
webstore (ocf::heartbeat:Filesystem):Started node2.chinasoft.com
webserver (lsb:httpd):Started node2.chinasoft.com
[root@node4 ~]# crm node standby node2.chinasoft.com
[root@node4 ~]# crm status
Last updated: Tue Apr 26 16:53:50 2016
Last change: Tue Apr 26 16:53:47 2016 via crm_attribute on node4.chinasoft.com
Stack: classic openais (with plugin)
Current DC: node4.chinasoft.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Node node2.chinasoft.com: standby
Online: [ node4.chinasoft.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr):Started node4.chinasoft.com
webstore (ocf::heartbeat:Filesystem):Started node4.chinasoft.com
webserver (lsb:httpd):Started node4.chinasoft.com