环境说明:

192.168.8.39 node2.chinasoft.com
192.168.8.42 node4.chinasoft.com
192.168.8.40 ansible管理服务器
192.168.8.77 VIP
192.168.8.20 nfs服务器

1、双机互信需要设置好,hosts文件需要解析好,时间要同步,配置好yum源

双击互信及Hosts文件配置,参考:http://blog.csdn.net/reblue520/article/details/51213030
最好使用centos6.5自带光盘,关于将光盘制作成本地httpd yum源可参考:http://blog.csdn.net/reblue520/article/details/51164294

2、准备好自动化安装包

定义ansible的管理组:
/etc/ansible/hosts

[corosync]
node2.chinasoft.com
node4.chinasoft.com

安装apache软件
# ansible corosync -m yum -a "name=httpd state=present"

在8.20上安装nfs文件服务器,并分别挂载在Node2和node4的/web/htdocs下
# yum -y install nfs-utils rpcbind
# mkdir /sharestore
# vi /etc/exports

/sharestore  *(rw,sync,no_root_squash)

启动服务
# service rpcbind restart 
# service nfs restart  
让服务随机启动
# chkconfig nfs on
# chkconfig rpcbind on

在node2和node4上分别执行挂载
# mount -t nfs 192.168.8.20:/sharestore /web/htdocs

# echo "<h1> nfs system server </h1>" /web/htdocs/index.html 
自动安装集群服务的剧本目录:
# cd /ansible/
# ls
corosync
# cd corosync/
# ls
conf  corosync.yaml  packages

剧本内容:
# vim corosync.yaml

- 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

- 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

执行剧本
# ansible-playbook corosync.yaml

报错:
TASK: [crmsh rpm packages] **************************************************** 
failed: [node2.chinasoft.com] => {"checksum": "45b4cbe3bd441d9a02cbcbc3d11091d2ad4388fa", "failed": true}
msg: Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!
failed: [node4.chinasoft.com] => {"checksum": "45b4cbe3bd441d9a02cbcbc3d11091d2ad4388fa", "failed": true}
msg: Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/corosync.yaml.retry

node2.chinasoft.com        : ok=3    changed=0    unreachable=0    failed=1   
node4.chinasoft.com        : ok=3    changed=0    unreachable=0    failed=1

处理:在node2和node4上安装libselinux-python包
# ansible corosync -a "yum install -y libselinux-python"

在其中的Node2上执行crm status查看集群是否配置成功
# crm status
Last updated: Mon Apr 25 17:51:10 2016
Last change: Mon Apr 25 17:43:35 2016 via crmd 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 ]

3、常用配置
# crm configure
crm(live)configure# show
node node2.chinasoft.com
node node4.chinasoft.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  
crm(live)configure# property stonith-enabled=false
crm(live)configure# verify
# 忽略法定票数限制
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# verify
crm(live)configure# commit
# 配置虚拟IP为8.77

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"

定义web资源

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"


将node2配置为备用节点

# 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

让node2重新上线,主节点仍然是node4

# 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


删除webservice组

# 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>

定义顺序关系
crm(live)configure# order webip_before_webserver mandatory: webip webserver
crm(live)configure# show xml
crm(live)configure# verify
crm(live)configure# commit
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
order webip_before_webserver inf: 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"


定义资源粘性,更倾向于运行在node4.chinasoft.com节点上

<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

将node4调整为备用节点,可以看到node2变为主节点,重新上线node4发现主节点又回到了node4上
crm(live)# node
crm(live)node# standby node4.chinasoft.com
crm(live)node# cd
crm(live)# show
ERROR: syntax: show
crm(live)# status
Last updated: Mon Apr 25 19:38:45 2016
Last change: Mon Apr 25 19:38:37 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 node4.chinasoft.com: standby
Online: [ node2.chinasoft.com ]

webip(ocf::heartbeat:IPaddr):Started node2.chinasoft.com 
 webserver(lsb:httpd):Started node2.chinasoft.com
crm(live)# node
crm(live)node# online node4.chinasoft.com
crm(live)node# cd
crm(live)# status
Last updated: Mon Apr 25 19:40:20 2016
Last change: Mon Apr 25 19:39:02 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

Online: [ node2.chinasoft.com node4.chinasoft.com ]

webip(ocf::heartbeat:IPaddr):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

pcs命令的使用:

环境准备:
删除之前建立的webip、webstore、webservice
crm(live)resource# stop webip
crm(live)resource# stop webstore 
crm(live)resource# stop webservice
crm(live)resource# status
 Resource Group: webservice
     webip(ocf::heartbeat:IPaddr):Stopped 
     webstore(ocf::heartbeat:Filesystem):Stopped 
     webserver(lsb:httpd):Stopped 
crm(live)resource# cd
crm(live)# configure                                
crm(live)configure# delete webservice
crm(live)configure# delete webip
INFO: constraint order:webip_before_webstore_before_webserver updated
crm(live)configure# delete webstore
crm(live)configure# show
node node2.chinasoft.com \
attributes standby="on"
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="1461664392"
rsc_defaults $id="rsc-options" \
resource-stickiness="100"
crm(live)configure# verify
crm(live)configure# commit

安装
# ansible corosync -m yum -a "name=pcs state=present"

设置vip
# pcs resource create webip ocf:heartbeat:IPaddr ip=192.168.8.77 op monitor interval=30s timeout=20s
[root@node2 ~]# pcs status
Cluster name: 
Last updated: Tue Apr 26 17:58:13 2016
Last change: Tue Apr 26 17:58:16 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
1 Resources configured

Node node2.chinasoft.com: standby
Online: [ node4.chinasoft.com ]

Full list of resources:

webip(ocf::heartbeat:IPaddr):Started node4.chinasoft.com

在node4上可以看到vip已经生成
 [root@node4 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:eb:42:3e brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.42/24 brd 192.168.8.255 scope global eth0
    inet 192.168.8.77/24 brd 192.168.8.255 scope global secondary eth0
    inet6 fe80::20c:29ff:feeb:423e/64 scope link 
       valid_lft forever preferred_lft forever

定义nfs存储
# pcs resource create webstore ocf:heartbeat:Filesystem 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
[root@node4 ~]# pcs status
Cluster name: 
Last updated: Tue Apr 26 18:05:21 2016
Last change: Tue Apr 26 18:05:18 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
2 Resources configured

Node node2.chinasoft.com: standby
Online: [ node4.chinasoft.com ]

Full list of resources:

webip(ocf::heartbeat:IPaddr):Started node4.chinasoft.com 
 webstore(ocf::heartbeat:Filesystem):Started node4.chinasoft.com

可以看到已经成功挂载
[root@node4 ~]# mount
/dev/mapper/vg_node4-root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg_node4-data on /data type ext4 (rw)
/dev/mapper/vg_node4-usr on /usr/local type ext4 (rw)
/dev/mapper/vg_node4-web on /web type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /mnt type iso9660 (ro)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.8.20:/sharestore on /web/htdocs type nfs (rw,vers=4,addr=192.168.8.20,clientaddr=192.168.8.42)

创建webserver
[root@node4 ~]# pcs resource create webserver lsb:httpd op monitor interval=30s timeout=20s on-fail=restart
[root@node4 ~]# psc status
-bash: psc: command not found
[root@node4 ~]# pcs status
Cluster name: 
Last updated: Tue Apr 26 18:12:56 2016
Last change: Tue Apr 26 18:12:49 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
3 Resources configured

Node node2.chinasoft.com: standby
Online: [ node4.chinasoft.com ]

Full list of resources:

webip(ocf::heartbeat:IPaddr):Started node4.chinasoft.com 
 webstore(ocf::heartbeat:Filesystem):Started node4.chinasoft.com 
 webserver(lsb:httpd):Started node4.chinasoft.com

将webip、webstore、webserver定义到webservice组中
[root@node4 ~]# pcs resource group add webservice webip webstore webserver
[root@node4 ~]# pcs status
Cluster name: 
Last updated: Tue Apr 26 18:13:37 2016
Last change: Tue Apr 26 18:13:35 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
3 Resources configured

Node node2.chinasoft.com: standby
Online: [ node4.chinasoft.com ]

Full list of resources:

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

此时可以通过访问http://192.168.8.77 看到挂载的nfs文件

配置node4为备用节点
# crm node standby node4.chinasoft.com

定义约束关系,pcs只支持一次两种资源之间关系的定义
[root@node4 ~]# pcs constraint order webip then webstore then webserver 
Adding webip webstore (kind: Mandatory) (Options: then webserver first-action=start then-action=start)
[root@node4 ~]# pcs constraint order show
Ordering Constraints:
  start webip then start webstore

[root@node4 ~]# pcs constraint order remove webstore webip
[root@node4 ~]# pcs constraint order webip then webserver
Adding webip webserver (kind: Mandatory) (Options: first-action=start then-action=start)
[root@node4 ~]# pcs constraint order webstore then webserver
Adding webstore webserver (kind: Mandatory) (Options: first-action=start then-action=start)
[root@node4 ~]# pcs constraint order show
Ordering Constraints:
  start webip then start webserver
  start webstore then start webserver

定义资源之间绑定关系
# pcs constraint colocation add webstore with webip


删除组资源,注意:delete命令会将所有的节点都删除
[root@node4 ~]# pcs resource delete webservice
Removing group: webservice (and all resources within group)
Stopping all resources in group: webservice...
Removing Constraint - colocation-webstore-webip-INFINITY
Removing Constraint - order-webip-webserver-mandatory
Deleting Resource - webip
Removing Constraint - order-webstore-webserver-mandatory
Deleting Resource - webstore
Deleting Resource (and group) - webserver
[root@node4 ~]# pcs status
Cluster name: 
Last updated: Tue Apr 26 19:17:21 2016
Last change: Tue Apr 26 19:17:11 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

Node node2.chinasoft.com: standby
Online: [ node4.chinasoft.com ]

Full list of resources:

重新添加资源
# pcs resource create webip ocf:heartbeat:IPaddr ip=192.168.8.77 op monitor interval=30s timeout=20s on-fail=restart
移除webip
# pcs resource move webip
# pcs status

CentOS 6.5环境使用ansible剧本自动化部署Corosync + pacemaker环境及corosync常用配置详解的更多相关文章

  1. tomcat生产环境JDK部署及虚拟主机等常用配置详解

    jdk和tomcat环境部署: 1.删除系统自带的openjdk # java -version java version "1.7.0_45" OpenJDK Runtime E ...

  2. 【E20200105-1】Centos 7.x 下vsftpd配置文件常用配置详解

    centos 7 下vsftp的安装和配置可以参见<[E20200102-1]centos 7 下vsftp的安装和配置> ########匿名用户(anonymous)设置####### ...

  3. Jenkins Ansible GitLab 自动化部署

    Jenkins Ansible GitLab 自动化部署 DevOps https://www.cnblogs.com/yangjianbo/articles/10393765.html https: ...

  4. Nginx+Tomcat的服务器端环境配置详解

    这篇文章主要介绍了Nginx+Tomcat的服务器端环境配置详解,包括Nginx与Tomcat的监控开启方法,需要的朋友可以参考下 Nginx+tomcat是目前主流的Javaweb架构,如何让ngi ...

  5. 基于 CentOS Mysql 安装与主从同步配置详解

    CentOS Mysql 安装 Mysql (Master/Slave) 主从同步 1.为什么要使用主从同步 1.如果主服务器出现问题,可以快速切换到从服务器提供的服务 2.可以在从服务器上执行查询操 ...

  6. libCURL开源库在VS2010环境下编译安装,配置详解

    libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 http://blog.csdn.net/su ...

  7. Ansible安装部署及常用模块详解

    Ansible命令使用 Ansible语法使用ansible <pattern_goes_here> -m <module_name> -a <arguments> ...

  8. JAVA环境变量配置详解(Windows)

    JAVA环境变量配置详解(Windows)   JAVA环境变量JAVA_HOME.CLASSPATH.PATH设置详解  Windows下JAVA用到的环境变量主要有3个,JAVA_HOME.CLA ...

  9. Ansible配置详解

    目录 Ansible配置详解 参考 配置优先级 配置参数说明 Ansible配置详解

随机推荐

  1. Azure HDInsight 上的 Spark 群集配合自定义的Python来分析网站日志

    一.前言:本文是个实践博客,演示如何结合使用自定义库和 HDInsight 上的 Spark 来分析日志数据. 我们使用的自定义库是一个名为 iislogparser.py的 Python 库. 每步 ...

  2. FinalHttp的简要介绍与使用

    http://blog.csdn.net/zhaokaiqiang1992/article/details/30291259?utm_source=tuicool 在之前的一篇文章中,我们简单的介绍了 ...

  3. zookeeper配置

    原文链接:https://www.cnblogs.com/yuyijq/p/3438829.html 前面两篇文章介绍了Zookeeper是什么和可以干什么,那么接下来我们就实际的接触一下Zookee ...

  4. HMTL列表详解

    1.无序列表<ul> ul其实没啥好说的,大家用得最多就是它,它的属性无非就是type: disc circle square 2.有序列表<ol> H4的时候就有2个属性,t ...

  5. Golang的防坑小技巧

    Golang的防坑小技巧 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 作为一名小白,在之前没有接触到编程的小伙伴,难免会踩到一些坑,比如说刚刚入门的时候你需要安装环境,学习Gol ...

  6. JAVA记录-异常基本概念

    1.异常分类 2.错误和异常的区别 3.try-catch-xxx处理方式 Java Exception:1.Error 2.Runtime Exception 运行时异常3.Exception 4. ...

  7. IDEA中导入多个包自动合并为星号

    IDEA中导入同一个包下的几个class会自动合并为星号,如下图.可以通过设置让其不自动合并为星号. 1.选择File→Settings→Editor→Code style→Java,再点击右边的Im ...

  8. TCP粘包,拆包及解决方法

    在进行Java NIO学习时,发现,如果客户端连续不断的向服务端发送数据包时,服务端接收的数据会出现两个数据包粘在一起的情况,这就是TCP协议中经常会遇到的粘包以及拆包的问题.我们都知道TCP属于传输 ...

  9. python学习笔记8--面向对象编程

    一.面向对象编程 面向对象--Object Oriented Programming,简称oop,是一种程序设计思想.在说面向对象之前,先说一下什么是编程范式,编程范式你按照什么方式来去编程,去实现一 ...

  10. 基于Selenium的Web自动化框架增强篇

    在写完上一篇“基于Selenium的Web自动化框架”(http://www.cnblogs.com/AlwinXu/p/5836709.html)之后一直没有时间重新审视该框架,正好趁着给同事分享的 ...