場景一:定義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
一、 定義web的vip資源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節點了,那麼我門使用瀏覽器測試下:
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訪問下
能夠看到資源已經轉移到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服務就沒法啓動了(過程略),手動kill掉httpd進程(過程略),下面查看資源分佈狀況
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驗證下
本次實驗完成!!