[root@station20 /]# export LANG=en
[root@station20 /]# tree /ansible/ # 注释: 环境配置很重要
/ansible/
`-- corosync
|-- conf
| |-- authkey
| `-- corosync.conf
|-- corosync.yaml
`-- packages
|-- crmsh-1.2.6-4.el6.x86_64.rpm
`-- pssh-2.3.1-2.el6.x86_64.rpm
3 directories, 5 files
[root@station20 corosync]# pwd
/ansible/corosync
[root@station20 corosync]# ls
conf corosync.yaml packages
root@station20 corosync]# ls packages/
crmsh-1.2.6-4.el6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm
[root@station20 corosync]# ls conf/
authkey corosync.conf
[root@station20 corosync]# cat corosync.yaml # 查看ansible脚本文件
- hosts: all # hosts : ansible 配置文件hosts中的配置我们这里的配置是:如下
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
[root@station20 corosync]# cat /etc/ansible/hosts # ansible配置文件
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
# Ex 1: Ungrouped hosts, specify before any group headers.
#green.example.com
#blue.example.com
#192.168.100.1
#192.168.100.10
# Ex 2: A collection of hosts belonging to the 'webservers' group
#[webservers]
#alpha.example.org
#beta.example.org
#192.168.1.100
#192.168.1.110
# If you have multiple hosts following a pattern you can specify
# them like this:
#www[001:006].example.com
# Ex 3: A collection of database servers in the 'dbservers' group
#[dbservers]
#db01.intranet.mydomain.net
#db02.intranet.mydomain.net
#10.25.1.56
#10.25.1.57
# Here's another example of host ranges, this time there are no
# leading 0s:
#db-[99:101]-node.example.com
[webservers]
node4.firefox.com
node5.firefox.com
执行脚本:
2014-04-20[root@station20 ~]# cd /ansible/corosync/ [root@station20 corosync]# ansible-playbook corosync.yaml PLAY [all] ******************************************************************** GATHERING FACTS *************************************************************** ok: [node4.firefox.com] ok: [node5.firefox.com] TASK: [corosync installing] *************************************************** changed: [node5.firefox.com] changed: [node4.firefox.com] TASK: [pacemaker installing] ************************************************** changed: [node5.firefox.com] changed: [node4.firefox.com] TASK: [crmsh rpm packages] **************************************************** changed: [node5.firefox.com] changed: [node4.firefox.com] TASK: [pssh rpm packages] ***************************************************** changed: [node4.firefox.com] changed: [node5.firefox.com] TASK: [crmsh installing] ****************************************************** changed: [node5.firefox.com] changed: [node4.firefox.com] TASK: [authkey configure file] ************************************************ changed: [node5.firefox.com] changed: [node4.firefox.com] TASK: [authkey mode 400] ****************************************************** changed: [node4.firefox.com] changed: [node5.firefox.com] TASK: [corosync.conf configure file] ****************************************** changed: [node4.firefox.com] changed: [node5.firefox.com] TASK: [ensure the corosync service startup on boot] *************************** changed: [node5.firefox.com] changed: [node4.firefox.com] NOTIFIED: [restart corosync] ************************************************** changed: [node5.firefox.com] changed: [node4.firefox.com] PLAY RECAP ******************************************************************** node4.firefox.com : ok=11 changed=10 unreachable=0 failed=0 node5.firefox.com : ok=11 changed=10 unreachable=0 failed=0
使用crm定义linux高可用集群:
crm(live)configure# property stonith-enabled=false crm(live)configure# verify crm(live)configure# commit crm(live)configure# property no-quorum-policy=ignore crm(live)configure# verify crm(live)configure# commit crm(live)configure# show node node4.firefox.com node node5.firefox.com 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# rsc_defaults resource-stickiness=100 crm(live)configure# verify crm(live)configure# commit crm(live)configure# primitive webip ocf:heartbeat:IPaddr2 params ip=172.16.149.00 op monitor interval=5s timeout=20s no-fail=restart crm(live)configure# verify crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="172.16.249.168:/www/htdoc" directory="/var/www/html" fstype="nfs" op monitor interval=20s timeout=60s 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# group webservice webip webstore webserver crm(live)configure# show node node4.firefox.com node node5.firefox.com primitive webip ocf:heartbeat:IPaddr2 \ params ip="172.16.149.200" \ op monitor interval="5s" timeout="20s" no-fail="restart" primitive webserver lsb:httpd \ op monitor interval="30s" timeout="20s" on-fail="restart" primitive webstore ocf:heartbeat:Filesystem \ params device="172.16.249.168:/www/htdoc" directory="/var/www/html" fstype="nfs" \ op monitor interval="20s" timeout="60s" \ 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" rsc_defaults $id="rsc-options" \ resource-stickiness="100" crm(live)configure# show xml <?xml version="1.0" ?> <cib num_updates="5" dc-uuid="node5.firefox.com" update-origin="node5.firefox.com" crm_feature_set="3.0.7" validate-with="pacemaker-1.2" update-client="cibadmin" epoch="8" admin_epoch="0" cib-last-written="Sat Apr 19 19:42:12 2014" 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="node4.firefox.com" uname="node4.firefox.com"/> <node id="node5.firefox.com" uname="node5.firefox.com"/> </nodes> <resources> <group id="webservice"> <primitive id="webip" class="ocf" provider="heartbeat" type="IPaddr2"> <instance_attributes id="webip-instance_attributes"> <nvpair name="ip" value="172.16.149.200" id="webip-instance_attributes-ip"/> </instance_attributes> <operations> <op name="monitor" interval="5s" timeout="20s" id="webip-monitor-5s"> <instance_attributes id="webip-monitor-5s-instance_attributes"> <nvpair name="no-fail" value="restart" id="webip-monitor-5s-instance_attributes-no-fail"/> </instance_attributes> </op> </operations> </primitive> <primitive id="webstore" class="ocf" provider="heartbeat" type="Filesystem"> <instance_attributes id="webstore-instance_attributes"> <nvpair name="device" value="172.16.249.168:/www/htdoc" id="webstore-instance_attributes-device"/> <nvpair name="directory" value="/var/www/html" id="webstore-instance_attributes-directory"/> <nvpair name="fstype" value="nfs" id="webstore-instance_attributes-fstype"/> </instance_attributes> <operations> <op name="monitor" interval="20s" timeout="60s" id="webstore-monitor-20s"/> <op name="start" timeout="60s" interval="0" id="webstore-start-0"/> <op name="stop" timeout="60s" on-fail="restart" interval="0" id="webstore-stop-0"/> </operations> </primitive> <primitive id="webserver" class="lsb" type="httpd"> <operations> <op name="monitor" interval="30s" timeout="20s" on-fail="restart" id="webserver-monitor-30s"/> </operations> </primitive> </group> </resources> <constraints/> <rsc_defaults> <meta_attributes id="rsc-options"> <nvpair name="resource-stickiness" value="100" id="rsc-options-resource-stickiness"/> </meta_attributes> </rsc_defaults> </configuration> </cib> (END)
crm(live)configure# order webip_before_webstore_webserver mandatory: webip webstore webserver
crm(live)configure# verify
crm(live)configure# show xml
<?xml version="1.0" ?>
<cib num_updates="5" dc-uuid="node5.firefox.com" update-origin="node5.firefox.com" crm_feature_set="3.0.7" validate-with="pacemaker-1.2" update-client="cibadmin" epoch="8" admin_epoch="0" cib-last-written="Sat Apr 19 19:42:12 2014" 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="node5.firefox.com" uname="node5.firefox.com"/>
<node id="node4.firefox.com" uname="node4.firefox.com"/>
</nodes>
<resources>
<group id="webservice">
<primitive id="webip" class="ocf" provider="heartbeat" type="IPaddr2">
<instance_attributes id="webip-instance_attributes">
<nvpair name="ip" value="172.16.149.200" id="webip-instance_attributes-ip"/>
</instance_attributes>
<operations>
<op name="monitor" interval="5s" timeout="20s" id="webip-monitor-5s">
<instance_attributes id="webip-monitor-5s-instance_attributes">
<nvpair name="no-fail" value="restart" id="webip-monitor-5s-instance_attributes-no-fail"/>
</instance_attributes>
</op>
</operations>
</primitive>
<primitive id="webstore" class="ocf" provider="heartbeat" type="Filesystem">
<instance_attributes id="webstore-instance_attributes">
<nvpair name="device" value="172.16.249.168:/www/htdoc" id="webstore-instance_a
ttributes-device"/>
<nvpair name="directory" value="/var/www/html" id="webstore-instance_attributes
-directory"/>
<nvpair name="fstype" value="nfs" id="webstore-instance_attributes-fstype"/>
</instance_attributes>
<operations>
<op name="monitor" interval="20s" timeout="60s" id="webstore-monitor-20s"/>
<op name="start" timeout="60s" interval="0" id="webstore-start-0"/>
<op name="stop" timeout="60s" on-fail="restart" interval="0" id="webstore-stop-
0"/>
</operations>
</primitive>
<primitive id="webserver" class="lsb" type="httpd">
<operations>
<op name="monitor" interval="30s" timeout="20s" on-fail="restart" id="webserver
-monitor-30s"/>
</operations>
</primitive>
</group>
</resources>
<constraints>
<rsc_order id="webip_before_webstore_webserver" score="INFINITY">
<resource_set id="webip_before_webstore_webserver-0">
<resource_ref id="webip"/>
<resource_ref id="webstore"/>
<resource_ref id="webserver"/>
</resource_set>
</rsc_order>
</constraints>
<rsc_defaults>
<meta_attributes id="rsc-options">
<nvpair name="resource-stickiness" value="100" id="rsc-options-resource-stickiness"
/>
</meta_attributes>
</rsc_defaults>
</configuration>
</cib>
[root@node5 ~]# crm
crm(live)# status
Last updated: Sat Apr 19 20:57:02 2014
Last change: Sat Apr 19 20:51:14 2014 via cibadmin on node5.firefox.com
Stack: classic openais (with plugin)
Current DC: node5.firefox.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node4.firefox.com node5.firefox.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr2): Started node5.firefox.com
webstore (ocf::heartbeat:Filesystem): Started node5.firefox.com
webserver (lsb:httpd): Started node5.firefox.com
[root@node5 ~]# crm node standby node5.firefox.com
[root@node5 ~]# crm status
Last updated: Sat Apr 19 21:00:45 2014
Last change: Sat Apr 19 21:00:40 2014 via crm_attribute on node5.firefox.com
Stack: classic openais (with plugin)
Current DC: node5.firefox.com - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Node node5.firefox.com: standby
Online: [ node4.firefox.com ]
Resource Group: webservice
webip (ocf::heartbeat:IPaddr2): Started node4.firefox.com
webstore (ocf::heartbeat:Filesystem): Started node4.firefox.com
webserver (lsb:httpd): Started node4.firefox.com