pacemaker+corosync实现资源调度


场景一:定义web资源实现web集群的高可用!node

本次环境:web

   Centos6系统 2台,各安装了http服务。bootstrap

   Pacemaker   corosync服务已经安装vim


一、  查看当前环境浏览器

crm(live)configure# show
node erick.com \
         attributesstandby=off
node erick1.com \
         attributesstandby=off
property cib-bootstrap-options: \
         dc-version=1.1.14-8.el6-70404b0\
         cluster-infrastructure="classicopenais (with plugin)" \
         expected-quorum-votes=2\
         stonith-enabled=false\
         no-quorum-policy=stop\
         last-lrm-refresh=1467844686

一、  定义webvip资源bash

crm(live)configure# primitive webipocf:heartbeat:IPaddr params ip=192.168.223.110
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node erick.com \
attributes standby=off
node erick1.com \
         attributesstandby=off
primitive webip IPaddr \
         paramsip=192.168.223.110
property cib-bootstrap-options: \
         dc-version=1.1.14-8.el6-70404b0\
         cluster-infrastructure="classicopenais (with plugin)" \
         expected-quorum-votes=2\
         stonith-enabled=false\
         no-quorum-policy=stop\
         last-lrm-refresh=1467844686

在节点上查看是否vip已经生成服务器

[root@erick ~]# ip a
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 qlen1000
   link/ether 00:0c:29:8c:43:f0 brd ff:ff:ff:ff:ff:ff
   inet 192.168.223.131/24 brd 192.168.223.255 scope global eth0
   inet 192.168.223.110/24brd 192.168.223.255 scope global secondary eth0
   inet6 fe80::20c:29ff:fe8c:43f0/64 scope link
       valid_lft forever preferred_lft forever
[root@erick~]#

定义web资源ide

crm(live)configure# primitivewebserver lsb:httpd
crm(live)configure# verify
crm(live)configure# comm
crm(live)configure# show
node erick.com \
         attributesstandby=off
node erick1.com \
         attributesstandby=off
primitive webip IPaddr \
         paramsip=192.168.223.110
primitive webserver lsb:httpd
property cib-bootstrap-options: \
         dc-version=1.1.14-8.el6-70404b0\
         cluster-infrastructure="classicopenais (with plugin)" \
         expected-quorum-votes=2\
         stonith-enabled=false\
         no-quorum-policy=stop\
         last-lrm-refresh=1467844686
crm(live)configure#

如今来利用pacemaker启动服务oop

crm(live)# resource start webip
crm(live)# resource start webserver
crm(live)#
crm(live)#
crm(live)#
crm(live)# status
Last updated: Thu Jul  7 21:16:03 2016                  Last change: Thu Jul  7 21:16:00 2016 by root via cibadmin onerick.com
Stack: classic openais (with plugin)
Current DC: erick.com (version1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured,2 expected votes
 
Online: [ erick.com erick1.com ]
 
Full list of resources:
 
 webip     (ocf::heartbeat:IPaddr):  Started erick.com
 webserver      (lsb:httpd):       Started erick1.com
 
crm(live)#

  如今能够看到资源很是均衡的分别在两个节点上起动了。这样有个问题,会致使web没法访问。如今我咱们要实现把两个资源定义在一块儿,使其可以在一个节点启动测试

crm(live)configure# colocationwebserver_before_webip inf: webserver webip
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node erick.com \
         attributesstandby=off
node erick1.com \
         attributesstandby=off
primitive webip IPaddr \
         paramsip=192.168.223.110 \
         metatarget-role=Started
primitive webserver lsb:httpd \
         metatarget-role=Started
colocation webserver_before_webipinf: webserver webip
property cib-bootstrap-options: \
         dc-version=1.1.14-8.el6-70404b0\
         cluster-infrastructure="classicopenais (with plugin)" \
         expected-quorum-votes=2\
         stonith-enabled=false\
         no-quorum-policy=stop\
         last-lrm-refresh=1467844686
crm(live)configure# up
crm(live)# status
Last updated: Thu Jul  7 21:20:50 2016                  Last change: Thu Jul  7 21:20:37 2016 by root via cibadmin onerick.com
Stack: classic openais (with plugin)
Current DC: erick.com (version1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured,2 expected votes
 
Online: [ erick.com erick1.com ]
 
Full list of resources:
 
 webip     (ocf::heartbeat:IPaddr):  Started erick.com
 webserver      (lsb:httpd):       Started erick.com

能够看到两个资源都在erick节点了,那么我门使用浏览器测试下:

wKiom1d97WaySL15AAA8HYLvX3w925.png-wh_50

Ok,访问成功!

因为咱们是2台机器,如今咱们若一台服务器宕机后,默认是的仲裁是服务关闭,因此咱们要修改下策略,改为ignore

crm(live)configure# propertyno-quorum-policy=ignore
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure#
crm(live)configure# show
node erick.com \
         attributesstandby=off
node erick1.com \
         attributesstandby=off
primitive webip IPaddr \
         paramsip=192.168.223.110 \
         metatarget-role=Started
primitive webserver lsb:httpd \
         metatarget-role=Started
colocation webserver_before_webipinf: webserver webip
property cib-bootstrap-options: \
dc-version=1.1.14-8.el6-70404b0 \
         cluster-infrastructure="classicopenais (with plugin)" \
         expected-quorum-votes=2\
         stonith-enabled=false\
         no-quorum-policy=ignore \
         last-lrm-refresh=1467844686

如今,咱们关闭一台虚拟机的服务,(模仿其宕机)查看资源转移状况

[root@erick ~]# vim/etc/httpd/conf/httpd.conf
[root@erick ~]# /etc/init.d/corosyncstop
Signaling Corosync Cluster Engine(corosync) to terminate: [  OK  ]
Waiting for corosync services tounload:.                  [  OK  ]
[root@erick~]#

咱们到erick1节点查看状况

crm(live)# status
Last updated: Thu Jul  7 07:06:59 2016                  Last change: Thu Jul  7 21:24:24 2016 by root via cibadmin onerick.com
Stack: classic openais (with plugin)
Current DC: erick1.com (version1.1.14-8.el6-70404b0) - partition WITHOUT quorum
2 nodes and 2 resources configured,2 expected votes
 
Online: [ erick1.com ]
OFFLINE: [ erick.com ]
 
Full list of resources:
 
 webip     (ocf::heartbeat:IPaddr):  Started erick1.com
 webserver      (lsb:httpd):       Startederick1.com
 
crm(live)#

经过web访问下

wKiom1d97c_zdHkfAAB3dLap07g124.png-wh_50

能够看到资源已经转移到erick1上来了。下面咱们把erick节点的服务启动起来。查看资源会不会转移

[root@erick ~]# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync):               [  OK  ]
 
 
crm(live)# status
Last updated: Thu Jul  7 07:09:03 2016                  Last change: Thu Jul  7 21:24:24 2016 by root via cibadmin onerick.com
Stack: classic openais (with plugin)
Current DC: erick1.com (version1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured,2 expected votes
 
Online: [ erick.com erick1.com ]
 
Full list of resources:
 
 webip     (ocf::heartbeat:IPaddr):  Started erick1.com
 webserver      (lsb:httpd):       Started erick1.com

资源并无转移,说明不陪权重是不会转移的。

情景二:

咱们以上只能作到当机器宕机时资源实现转移,当httpd服务挂掉时,并不会实现转移。下面咱们来实现监控资源

crm(live)configure# monitorwebserver 20s:15s
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node erick.com \
         attributesstandby=off
node erick1.com \
         attributesstandby=off
primitive webip IPaddr \
         paramsip=192.168.223.110 \
         metatarget-role=Started
primitive webserver lsb:httpd \
         meta target-role=Started \
         op monitor interval=20stimeout=15s
colocation webserver_before_webipinf: webserver webip
property cib-bootstrap-options: \
         dc-version=1.1.14-8.el6-70404b0\
         cluster-infrastructure="classicopenais (with plugin)" \
         expected-quorum-votes=2\
         stonith-enabled=false\
         no-quorum-policy=ignore\
         last-lrm-refresh=1467844686

  若此时咱们httpd服务强行杀掉后,还会自动启动,只有当本身没法启动时才会启动。下面咱们把erick1节点httpd的端口改成22这样http服务就没法启动了(过程略),手动killhttpd进程(过程略),下面查看资源分布状况

Full list of resources:
 
 webip     (ocf::heartbeat:IPaddr):  Started erick.com
 webserver        (lsb:httpd):       Startederick.com
 
Failed Actions:
* webserver_start_0 on erick1.com'unknown error' (1): call=90, status=complete, exitreason='none',
   last-rc-change='Thu Jul  707:19:27 2016', queued=0ms, exec=87ms
 
crm(live)# resource cleanupwebserver   ##清除失败的资源
Cleaning up webserver on erick.com,removing fail-count-webserver
Cleaning up webserver on erick1.com,removing fail-count-webserver
Waiting for 2 replies from theCRMd.. OK
crm(live)#
crm(live)# status
Last updated: Thu Jul  7 21:40:15 2016                  Last change: Thu Jul  7 07:20:45 2016 by hacluster via crmd onerick1.com
Stack: classic openais (with plugin)
Current DC: erick1.com (version1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured,2 expected votes
 
Online: [ erick.com erick1.com ]
 
Full list of resources:
 
 webip     (ocf::heartbeat:IPaddr):  Started erick.com
 webserver      (lsb:httpd):       Startederick.com

经过web验证下

wKioL1d97k-woOtuAABvIxpG-EM573.png-wh_50

本次实验完成!!

相关文章
相关标签/搜索