CentOS 6.5环境使用ansible剧本自动化部署Corosync + pacemaker环境及corosync常用配置详解

环境说明:

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

[[email protected] ~]# crm node online node4.chinasoft.com

[[email protected] ~]# 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上线顶替

[[email protected] ~]# 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

[[email protected] ~]# crm node standby node2.chinasoft.com

[[email protected] ~]# 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

[[email protected] ~]# 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已经生成

[[email protected] ~]# 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

[[email protected] ~]# 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

可以看到已经成功挂载

[[email protected] ~]# 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

[[email protected] ~]# pcs resource create webserver lsb:httpd op monitor interval=30s timeout=20s on-fail=restart

[[email protected] ~]# psc status

-bash: psc: command not found

[[email protected] ~]# 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组中

[[email protected] ~]# pcs resource group add webservice webip webstore webserver

[[email protected] ~]# 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只支持一次两种资源之间关系的定义

[[email protected] ~]# pcs constraint order webip then webstore then webserver

Adding webip webstore (kind: Mandatory) (Options: then webserver first-action=start then-action=start)

[[email protected] ~]# pcs constraint order show

Ordering Constraints:

start webip then start webstore

[[email protected] ~]# pcs constraint order remove webstore webip

[[email protected] ~]# pcs constraint order webip then webserver

Adding webip webserver (kind: Mandatory) (Options: first-action=start then-action=start)

[[email protected] ~]# pcs constraint order webstore then webserver

Adding webstore webserver (kind: Mandatory) (Options: first-action=start then-action=start)

[[email protected] ~]# pcs constraint order show

Ordering Constraints:

start webip then start webserver

start webstore then start webserver

定义资源之间绑定关系

# pcs constraint colocation add webstore with webip

删除组资源,注意:delete命令会将所有的节点都删除

[[email protected] ~]# 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

[[email protected] ~]# 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

时间: 2024-11-08 09:35:01

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

Jenkins+Ansible+Gitlab自动化部署三剑客

最近一直在学习Ansible的一些playbook的写法, 所以一直没有怎么更新, 想到目前大家对诸如saltstack, docker, Ansible等自动化部署相关的工具很感兴趣, 但又苦于没有可学习的中文实例, 这里我就把我这几个月所接触到目前国外比较流行的部署经验给大家分享一下. 首先给大家介绍的是Ansible, 恩, 重要的问题说三遍, 不是Saltstack, Ansible作为一个python写的自动化部署工具, 确实较之前我所接触的Chef, saltstack, puppe

Ansible 常用模块详解(3)

title: Ansible 常用模块详解(3) date: 2018-12-01 15:22:11 tags: Ansible categories: Ansible copyright: true --- Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能,ansible是基于模块工作的,本身没有批量部署的能力,真正具有批量部署的是an

ansible常用模块详解

ansible常用模块详解: ansible <host-pattern> [-m module_name] [-a args] [options] #ansible命令格式  指定主机组或ip地址  指定调用模块   传递给模块的参数   ansible-doc -l #列出可用模块 ansible-doc -s model_name #查看指定模块详细用法 command:ansible默认模块,对指定主机执行命令,不能理解特殊字符 例:ansible web -a 'date' #对we

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

这篇文章主要介绍了Nginx+Tomcat的服务器端环境配置详解,包括Nginx与Tomcat的监控开启方法,需要的朋友可以参考下 Nginx+tomcat是目前主流的Javaweb架构,如何让nginx+tomcat同时工作呢,也可以说如何使用nginx来反向代理tomcat后端均衡呢?直接安装配置如下: 1.Java JDK安装: #下载相应的jdk软件包,然后解压安装,我这里包名称为:jdk-7u25-Linux-x64.tar.gz ? 1 tar -xzf jdk-7u25-linux

CentOS 6.x上搭建vSFTPD服务器搭建与配置详解

摘要: 手把手教你搭建vsftpd服务器,实现了基于db文件和MySQL数据库文件进行虚拟用户认证,当然了也本文章也包含搭建过程中问题的排查啦,哈哈哈. 另外,我在CentOS 7.x上也进行了搭建测试,步骤一致,个别命令会有不同,但不影响测试效果. 服务器部署需求分析(实现效果): 1.登录.传输全程进行加密处理. 2.记录用户上传.下载文件日志. 3.针对每个用户有公共文件夹(大家都可以看到和下载其中的文件)和私有文件夹(只有自己可以看到,并且可上传下载文件). 一.vsftpd服务安装:

Centos 7基于DR(直接路由)模式的负载均衡配置详解

DR(直接路由)是三种负载均衡模式其中之一,也是使用最多的一种模式,关于该模式的介绍,可以参考博文:LVS负载均衡群集详解. DR的工作模式示意图如下: 该模式的原理已经在上面链接的博文中写了下来.现在直接搭建一个基于DR模式的负载均衡群集. 环境如下: 在上面这个环境中,需要解决的问题有下面几点: 1.所有web节点和调度器都配置上VIP:客户端访问VIP(群集的虚拟IP地址)时,若是 调度器将请求转发给web节点,然后由web节点直接去响应客户端,那么客户端在收到 数据包后,发现收到的数据包

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

libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 CURL开源库VS2010环境下编译安装,配置详解 一 准备 1.1 CURL官网下载地址:http://curl.haxx.se/download.html 1.2 找到源码包,我这里下载的是7.32.0版:http://curl.haxx.se/download/curl-7.32.0.zip 二 步骤 2.1 打开curl-7.32.0\

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

Ansible命令使用 Ansible语法使用ansible <pattern_goes_here> -m <module_name> -a <arguments> -m NAME,–module-name=NAME:指定执行使用的模块 -u USERNAME,–user=USERNAME:指定远程主机以USERNAME运行命令 -s,–sudo:相当于Linux系统下的sudo命令 -USUDO_USERNAME,–sudo-user=SUDO_USERNAME:使用

走进自动化运维之Ansible服务部署,附带(参数及模块)详解!

何为Ansible: 简单的自动化运维管理工具,不需要配置代理工具,基于Python研发. Ansible是基于模块工作的,本身没有批量部署的能力.真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架. 自动化运维工具"三剑客": 工具 开发语言 结构 配置文件格式 运行任务 Ansible Python 无 YAML 支持命令行 SaltStack Python C/S YAML 支持命令行 Puppet Ruby C/S Ruby语法格式 通过模块实现 a