pacemaker+corosync實現資源調度


場景一:定義web資源實現web集羣的高可用!

本次環境:

   Centos6系統 2臺,各安裝了http服務。

   Pacemaker   corosync服務已經安裝


1、  查看當前環境

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

1、  定義webvip資源

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資源

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啓動服務

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

本次實驗完成!!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章