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