AIS是應用接口規範,是用來定義應用程式接口(API)的開放性規範的集合,這些應用程式作為中間件為應用服務提供一種開放、高移植性的程式接口。是在實作高可用應用過程中是亟需的。服務可用性論壇(SA Forum)是一個開放性論壇,它開發并釋出這些免費規範。使用AIS規範的應用程式接口(API),可以減少應用程式的複雜性和縮短應用程式的開發時間,這些規範的主要目的就是為了提高中間元件可移植性和應用程式的高可用性。
OpenAIS是基于SA Forum 标準的叢集架構的應用程式接口規範。OpenAIS提供一種叢集模式,這個模式包括叢集架構,叢集成員管理,通信方式,叢集監測等,能夠為叢集軟體或工具提供滿足 AIS标準的叢集接口,但是它沒有叢集資源管理功能,不能獨立形成一個叢集。
corosync最初隻是用來示範OpenAIS叢集架構接口規範的一個應用,可以說corosync是OpenAIS的一部分,但後面的發展明顯超越了官方最初的設想,越來越多的廠商嘗試使用corosync作為叢集解決方案。如Redhat的RHCS叢集套件就是基于corosync實作。
corosync隻提供了message layer,而沒有直接提供CRM,一般使用Pacemaker進行資源管理。
資源粘性表示資源是否傾向于留在目前節點,如果為正整數,表示傾向,負數則會離開,-inf表示正無窮,inf表示正無窮。
clone:克隆資源(可同時運作在多個節點上),要先定義為primitive後才能進行clone。主要包含 STONITH和叢集檔案系統(cluster filesystem)
master/slave:主從資源,如drbd
RA類型:
lsb:linux表中庫,一般位于/etc/rc.d/init.d/目錄下的支援start|stop|status等參數的服務腳本都是lsb
ocf:Open cluster Framework,開放叢集架構
heartbeat:heartbeat V1版本
stonith:專為配置stonith裝置而用
叢集類型和模型:
corosync+pacemaker可實作多種叢集模型,包括 Active/Active, Active/Passive, N+1, N+M, N-to-1 and N-to-N。
Active/Passive備援:
<a href="http://s3.51cto.com/wyfs02/M02/23/1A/wKiom1Mxm1XxcbIVAAI-RkHOIo4853.jpg" target="_blank"></a>
N to N 備援(多個節點多個服務):
<a href="http://s3.51cto.com/wyfs02/M01/23/1B/wKioL1Mxm3mwEGo1AAMX7BDPgxo139.jpg" target="_blank"></a>
二.系統環境:Centos 6.4 x86_64
1.配置倆台節點的主機名
1
2
3
<code>[root@node1 ~]</code><code># hostname node1.luojianlong</code>
<code>[root@node1 ~]</code><code># sed -i 's@\(HOSTNAME=\).*@\1node1.luojianlong.com@g' /etc/sysconfig/network</code>
<code>[root@node1 ~]</code><code># bash</code>
2.設定倆台節點ssh互信無密碼登入
4
<code>[root@node1 ~]</code><code># ssh-keygen -t rsa</code>
<code>[root@node1 ~]</code><code># ssh-copy-id -i ~/.ssh/id_rsa.pub root@node2</code>
<code>[root@node2 ~]</code><code># ssh-keygen -t rsa</code>
<code>[root@node2 ~]</code><code># ssh-copy-id -i ~/.ssh/id_rsa.pub root@node1</code>
1.配置倆台節點主機名以及hosts檔案:
<code>[root@node1 ~]</code><code># cat /etc/hosts</code>
<code>192.168.30.116 node1.luojianlong.com</code>
<code>192.168.30.117 node2.luojianlong.com</code>
2.在節點一和節點二上分别安裝corosync,pacemaker
<code>[root@node1 ~]</code><code># yum -y install corosync pacemaker</code>
3.在節點一和節點二上分别關閉NetworkManager服務
<code>[root@node1 ~]</code><code># service NetworkManager stop</code>
<code>[root@node1 ~]</code><code># chkconfig NetworkManager off</code>
4.在節點一和節點二上分别安裝crmsh-1.2.6-4
<code>[root@node1 ~]</code><code># yum -y --nogpgcheck localinstall crmsh*.rpm pssh*.rpm</code>
<code>[root@node2 ~]</code><code># yum -y --nogpgcheck localinstall crmsh*.rpm pssh*.rpm</code>
5.編譯corosync配置檔案:
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<code>totem {</code>
<code> </code><code>version: 2</code>
<code> </code><code>secauth: on</code>
<code> </code><code>threads: 0</code>
<code> </code><code>interface {</code>
<code> </code><code>ringnumber: 0</code>
<code> </code><code>bindnetaddr: 192.168.30.0</code>
<code> </code><code>mcastaddr: 226.94.1.1</code>
<code> </code><code>mcastport: 5405</code>
<code> </code><code>ttl: 1</code>
<code> </code><code>}</code>
<code>}</code>
<code>logging {</code>
<code> </code><code>fileline: off</code>
<code> </code><code>to_stderr: no</code>
<code> </code><code>to_logfile: </code><code>yes</code>
<code> </code><code>to_syslog: no</code>
<code> </code><code>logfile: </code><code>/var/log/cluster/corosync</code><code>.log</code>
<code> </code><code>debug: off</code>
<code> </code><code>timestamp: on</code>
<code> </code><code>logger_subsys {</code>
<code> </code><code>subsys: AMF</code>
<code> </code><code>debug: off</code>
<code>amf {</code>
<code> </code><code>mode: disabled</code>
<code>service {</code>
<code> </code><code>ver: 0</code>
<code> </code><code>name: pacemaker</code>
<code> </code><code># use_mgmtd: yes</code>
<code>aisexec {</code>
<code> </code><code>user: root</code>
<code> </code><code>group: root</code>
version:表示版本資訊;
secauth:表示叢集之間加密認證;
threads:表示開啟的線程數;
bindnetaddr:叢集所在的網絡位址;
mcastaddr:叢集發送資訊的多點傳播位址
service:表示以插件的方式運作pacemaker;
6.生成叢集認證密鑰
<code>[root@node1 ~]</code><code># corosync-keygen</code>
<code>Corosync Cluster Engine Authentication key generator.</code>
<code>Gathering 1024 bits </code><code>for</code> <code>key from </code><code>/dev/random</code><code>.</code>
<code>Press keys on your keyboard to generate entropy.</code>
<code>Press keys on your keyboard to generate entropy (bits = 176).</code>
<code>Press keys on your keyboard to generate entropy (bits = 240).</code>
<code>Press keys on your keyboard to generate entropy (bits = 304).</code>
<code>Press keys on your keyboard to generate entropy (bits = 368).</code>
<code>Press keys on your keyboard to generate entropy (bits = 432).</code>
<code>Press keys on your keyboard to generate entropy (bits = 496).</code>
<code>Press keys on your keyboard to generate entropy (bits = 560).</code>
<code>Press keys on your keyboard to generate entropy (bits = 624).</code>
<code>Press keys on your keyboard to generate entropy (bits = 688).</code>
<code>Press keys on your keyboard to generate entropy (bits = 752).</code>
<code>Press keys on your keyboard to generate entropy (bits = 816).</code>
<code>Press keys on your keyboard to generate entropy (bits = 880).</code>
<code>Press keys on your keyboard to generate entropy (bits = 944).</code>
<code>Press keys on your keyboard to generate entropy (bits = 1008).</code>
<code>Writing corosync key to </code><code>/etc/corosync/authkey</code><code>.</code>
<code>[root@node1 corosync]</code><code># scp authkey corosync.conf [email protected]:/etc/corosync/</code>
7.啟動corosync服務:
<code>[root@node1 ~]</code><code># service corosync start</code>
<code>Starting Corosync Cluster Engine (corosync): [ OK ]</code>
8.檢視corosync日志
檢視corosync引擎是否正常啟動:
<code>[root@node1 ~]</code><code># grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log</code>
<code>Jan 10 10:49:13 corosync [MAIN ] Corosync Cluster Engine (</code><code>'1.4.1'</code><code>): started and ready to provide service.</code>
<code>Jan 10 10:49:13 corosync [MAIN ] Successfully </code><code>read</code> <code>main configuration </code><code>file</code> <code>'/etc/corosync/corosync.conf'</code><code>.</code>
檢視初始化成員節點通知是否正常發出:
<code>[root@node1 ~]</code><code># grep TOTEM /var/log/cluster/corosync.log</code>
<code>Jan 10 10:49:13 corosync [TOTEM ] Initializing transport (UDP</code><code>/IP</code> <code>Multicast).</code>
<code>Jan 10 10:49:13 corosync [TOTEM ] Initializing transmit</code><code>/receive</code> <code>security: libtomcrypt SOBER128</code><code>/SHA1HMAC</code> <code>(mode 0).</code>
<code>Jan 10 10:49:13 corosync [TOTEM ] The network interface [192.168.30.116] is now up.</code>
<code>Jan 10 10:49:14 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.</code>
<code>Jan 10 10:51:11 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.</code>
檢查啟動過程中是否有錯誤産生。下面的錯誤資訊表示packmaker不久之後将不再作為corosync的插 件 運作,是以,建議使用cman作為叢集基礎架構服務;此處可安全忽略
<code>[root@node1 ~]</code><code># grep ERROR: /var/log/cluster/corosync.log | grep -v unpack_resources</code>
<code>Jan 10 10:49:14 corosync [pcmk ] ERROR: process_ais_conf: You have configured a cluster using the Pacemaker plugin </code><code>for</code> <code>Corosync. The plugin is not supported </code><code>in</code> <code>this environment and will be removed very soon.</code>
<code>Jan 10 10:49:14 corosync [pcmk ] ERROR: process_ais_conf: Please see Chapter 8 of </code><code>'Clusters from Scratch'</code> <code>(http:</code><code>//www</code><code>.clusterlabs.org</code><code>/doc</code><code>) </code><code>for</code> <code>details on using Pacemaker with CMAN</code>
檢視pacemaker是否正常啟動:
<code>[root@node1 ~]</code><code># grep pcmk_startup /var/log/cluster/corosync.log</code>
<code>Jan 10 10:49:14 corosync [pcmk ] info: pcmk_startup: CRM: Initialized</code>
<code>Jan 10 10:49:14 corosync [pcmk ] Logging: Initialized pcmk_startup</code>
<code>Jan 10 10:49:14 corosync [pcmk ] info: pcmk_startup: Maximum core </code><code>file</code> <code>size is: 18446744073709551615</code>
<code>Jan 10 10:49:14 corosync [pcmk ] info: pcmk_startup: Service: 9</code>
<code>Jan 10 10:49:14 corosync [pcmk ] info: pcmk_startup: Local </code><code>hostname</code><code>: node1.luojianlong.com</code>
如果上面指令執行均沒有問題,接着可以執行如下指令啟動node2上的corosync
<code>[root@node1 ~]</code><code># ssh node2 '/etc/init.d/corosync start'</code>
注意:啟動node2需要在node1上使用如上指令進行,不要在node2節點上直接啟動。下面是node1上的相 關日志
<code>[root@node1 ~]</code><code># tail /var/log/cluster/corosync.log</code>
<code>Jan 10 10:51:14 [14875] node1.luojianlong.com crmd: info: te_rsc_command: Action 3 confirmed - no wait</code>
<code>Jan 10 10:51:14 [14875] node1.luojianlong.com crmd: notice: run_graph: Transition 1 (Complete=1, Pending=0, Fired=0, Skipped=0, Incomplete=0, Source=</code><code>/var/lib/pacemaker/pengine/pe-input-1</code><code>.bz2): Complete</code>
<code>Jan 10 10:51:14 [14875] node1.luojianlong.com crmd: info: do_log: FSA: Input I_TE_SUCCESS from notify_crmd() received </code><code>in</code> <code>state S_TRANSITION_ENGINE</code>
<code>Jan 10 10:51:14 [14875] node1.luojianlong.com crmd: notice: do_state_transition: State transition S_TRANSITION_ENGINE -> S_IDLE [ input=I_TE_SUCCESS cause=C_FSA_INTERNAL origin=notify_crmd ]</code>
<code>Jan 10 10:51:14 [14869] node1.luojianlong.com cib: info: cib_process_request: Completed cib_query operation </code><code>for</code> <code>section </code><code>//cib/status//node_state</code><code>[@</code><code>id</code><code>=</code><code>'node1.luojianlong.com'</code><code>]</code><code>//transient_attributes//nvpair</code><code>[@name=</code><code>'probe_complete'</code><code>]: OK (rc=0, origin=</code><code>local</code><code>/attrd/7</code><code>, version=0.5.6)</code>
<code>Jan 10 10:51:14 [14869] node1.luojianlong.com cib: info: cib_process_request: Completed cib_modify operation </code><code>for</code> <code>section status: OK (rc=0, origin=</code><code>local</code><code>/attrd/8</code><code>, version=0.5.6)</code>
<code>Jan 10 10:51:16 [14869] node1.luojianlong.com cib: info: cib_process_request: Completed cib_modify operation </code><code>for</code> <code>section status: OK (rc=0, origin=node2.luojianlong.com</code><code>/attrd/6</code><code>, version=0.5.7)</code>
<code>Jan 10 10:51:31 [14869] node1.luojianlong.com cib: info: crm_client_new: Connecting 0x913f10 </code><code>for</code> <code>uid=0 gid=0 pid=9832 </code><code>id</code><code>=41a762cd-b87c-4f39-8482-a64c2c61209c</code>
<code>Jan 10 10:51:31 [14869] node1.luojianlong.com cib: info: cib_process_request: Completed cib_query operation </code><code>for</code> <code>section </code><code>'all'</code><code>: OK (rc=0, origin=</code><code>local</code><code>/crm_mon/2</code><code>, version=0.5.7)</code>
<code>Jan 10 10:51:31 [14869] node1.luojianlong.com cib: info: crm_client_destroy: Destroying 0 events</code>
9.如果安裝了crmsh,可使用如下指令檢視叢集節點的啟動狀态:
<code>[root@node1 ~]</code><code># crm status</code>
<code>Last updated: Fri Jan 10 11:07:14 2014</code>
<code>Last change: Fri Jan 10 10:51:11 2014 via crmd on node1.luojianlong.com</code>
<code>Stack: classic openais (with plugin)</code>
<code>Current DC: node1.luojianlong.com - partition with quorum</code>
<code>Version: 1.1.10-14.el6_5.1-368c726</code>
<code>2 Nodes configured, 2 expected votes</code>
<code>0 Resources configured</code>
<code>Online: [ node1.luojianlong.com node2.luojianlong.com ]</code>
<code>#從上面的資訊可以看出兩個節點都已經正常啟動,并且叢集已經處于正常工作狀态。</code>
10.執行ps auxf指令可以檢視corosync啟動的各相關程序。
<code>[root@node1 ~]</code><code># ps auxf</code>
<code>189 14869 0.4 0.2 93928 10624 ? S 09:20 0:05 \_ </code><code>/usr/libexec/pacemaker/cib</code>
<code>root 14871 0.0 0.1 94280 4036 ? S 09:20 0:01 \_ </code><code>/usr/libexec/pacemaker/stonithd</code>
<code>root 14872 0.0 0.0 75996 3216 ? S 09:20 0:00 \_ </code><code>/usr/libexec/pacemaker/lrmd</code>
<code>189 14873 0.0 0.0 89536 3444 ? S 09:20 0:00 \_ </code><code>/usr/libexec/pacemaker/attrd</code>
<code>189 14874 0.0 0.4 117180 18920 ? S 09:20 0:00 \_ </code><code>/usr/libexec/pacemaker/pengine</code>
<code>189 14875 0.0 0.1 147684 6624 ? S 09:20 0:00 \_ </code><code>/usr/libexec/pacemaker/crmd</code>
11.配置叢集的工作屬性,禁用stonith
<code>#corosync預設啟用了stonith,而目前叢集并沒有相應的stonith裝置,是以此預設配置目前尚不可用,這可以通過如下指令驗正:</code>
<code>[root@node1 ~]</code><code># crm_verify -L -V</code>
<code> </code><code>error: unpack_resources: Resource start-up disabled since no STONITH resources have been defined</code>
<code> </code><code>error: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option</code>
<code> </code><code>error: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity</code>
<code>Errors found during check: config not valid</code>
<code>#我們裡可以通過如下指令先禁用stonith:</code>
<code>[root@node1 ~]</code><code># crm configure property stonith-enabled=false</code>
<code>#使用如下指令檢視目前的配置資訊:</code>
<code>[root@node1 ~]</code><code># crm configure show</code>
<code>node node1.luojianlong.com</code>
<code>node node2.luojianlong.com</code>
<code>property $</code><code>id</code><code>=</code><code>"cib-bootstrap-options"</code> <code>\</code>
<code> </code><code>dc</code><code>-version=</code><code>"1.1.10-14.el6_5.1-368c726"</code> <code>\</code>
<code> </code><code>cluster-infrastructure=</code><code>"classic openais (with plugin)"</code> <code>\</code>
<code> </code><code>expected-quorum-votes=</code><code>"2"</code> <code>\</code>
<code> </code><code>stonith-enabled=</code><code>"false"</code>
<code>#從中可以看出stonith已經被禁用。</code>
<code>#上面的crm,crm_verify指令是1.0後的版本的pacemaker提供的基于指令行的叢集管理工具;可以在叢集中的任何一個節點上執行。</code>
12.檢視支援的叢集資源
<code>#corosync支援heartbeat,LSB和ocf等類型的資源代理,目前較為常用的類型為LSB和OCF兩類,stonith類專為配置stonith裝置而用;</code>
<code>#可以通過如下指令檢視目前叢集系統所支援的類型:</code>
<code>[root@node1 ~]</code><code># crm ra classes</code>
<code>lsb</code>
<code>ocf / heartbeat pacemaker</code>
<code>service</code>
<code>stonith</code>
<code>#如果想要檢視某種類别下的所用資源代理的清單,可以使用類似如下指令實作:</code>
<code>[root@node1 ~]</code><code># crm ra list lsb</code>
<code>[root@node1 ~]</code><code># crm ra list ocf heartbeat</code>
<code>[root@node1 ~]</code><code># crm ra list ocf pacemaker</code>
<code>[root@node1 ~]</code><code># crm ra list stonith</code>
<code># crm ra info [class:[provider:]]resource_agent</code>
<code>#例如:</code>
<code>[root@node1 ~]</code><code># crm ra info ocf:heartbeat:IPaddr</code>
13.接下來要建立的web叢集建立一個IP位址資源,以在通過叢集提供web服務時使用;這可以通過如下方式實作:
文法:
primitive <rsc> [<class>:[<provider>:]]<type>
[params attr_list]
[operations id_spec]
[op op_type [<attribute>=<value>...] ...]
op_type :: start | stop | monitor
例子:
primitive apcfence stonith:apcsmart \
params ttydev=/dev/ttyS0 hostlist="node1 node2" \
op start timeout=60s \
op monitor interval=30m timeout=60s
<code>[root@node1 ~]</code><code># crm configure primitive WebIP ocf:heartbeat:IPaddr params ip=192.168.30.230</code>
14.通過如下的指令執行結果可以看出此資源已經在node1.luojianlong.com上啟動:
<code>Last updated: Tue Mar 25 11:10:40 2014</code>
<code>Last change: Tue Mar 25 11:10:00 2014 via cibadmin on node1.luojianlong.com</code>
<code>1 Resources configured</code>
<code> </code><code>WebIP (ocf::heartbeat:IPaddr): Started node1.luojianlong.com</code>
<code>[root@node1 ~]</code><code># ip addr</code>
<code>1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN</code>
<code> </code><code>link</code><code>/loopback</code> <code>00:00:00:00:00:00 brd 00:00:00:00:00:00</code>
<code> </code><code>inet 127.0.0.1</code><code>/8</code> <code>scope host lo</code>
<code> </code><code>inet6 ::1</code><code>/128</code> <code>scope host</code>
<code> </code><code>valid_lft forever preferred_lft forever</code>
<code>2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000</code>
<code> </code><code>link</code><code>/ether</code> <code>00:0c:29:f3:fc:ba brd ff:ff:ff:ff:ff:ff</code>
<code> </code><code>inet 192.168.30.116</code><code>/24</code> <code>brd 192.168.30.255 scope global eth0</code>
<code> </code><code>inet 192.168.30.230</code><code>/24</code> <code>brd 192.168.30.255 scope global secondary eth0</code>
<code> </code><code>inet6 fe80::20c:29ff:fef3:fcba</code><code>/64</code> <code>scope link</code>
15.而後我們到node2上通過如下指令停止node1上的corosync服務,并檢視叢集狀态
<code>[root@node2 ~]</code><code># ssh node1 '/etc/init.d/corosync stop'</code>
<code>Signaling Corosync Cluster Engine (corosync) to terminate: [ OK ]</code>
<code>Waiting </code><code>for</code> <code>corosync services to unload:.[ OK ]</code>
<code>[root@node2 ~]</code><code># crm status</code>
<code>Last updated: Tue Mar 25 11:13:57 2014</code>
<code>Last change: Tue Mar 25 11:13:22 2014 via crmd on node2.luojianlong.com</code>
<code>Current DC: node2.luojianlong.com - partition WITHOUT quorum</code>
<code>Version: 1.1.10-14.el6_5.2-368c726</code>
<code>Online: [ node2.luojianlong.com ]</code>
<code>OFFLINE: [ node1.luojianlong.com ]</code>
16.上面的資訊顯示node1.luojianlong.com已經離線,但資源WebIP卻沒能在node2.luojianlong.com上啟動。這是因為此時的叢集狀态為"WITHOUT quorum",即已經失去了quorum,此時叢集服務本身已經不滿足正常運作的條件,這對于隻有兩節點的叢集來講是不合理的。是以,我們可以通過如下的指令來修改忽略quorum不能滿足的叢集狀态檢查:
<code>[root@node2 ~]</code><code># crm configure property no-quorum-policy=ignore</code>
17.片刻之後,叢集就會在目前仍在運作中的節點node2上啟動此資源了,如下所示:
<code>Last updated: Tue Mar 25 11:16:21 2014</code>
<code>Last change: Tue Mar 25 11:15:47 2014 via cibadmin on node2.luojianlong.com</code>
<code> </code><code>WebIP (ocf::heartbeat:IPaddr): Started node2.luojianlong.com</code>
18.好了,驗正完成後,我們正常啟動node1.luojianlong.com
<code>[root@node2 ~]</code><code># ssh node1 '/etc/init.d/corosync start'</code>
<code>Starting Corosync Cluster Engine (corosync): [ OK ]</code>
<code>[root@node1 ~]</code><code># ssh node2 '/etc/init.d/corosync stop'</code>
<code>Last updated: Tue Mar 25 11:24:10 2014</code>
<code>Last change: Tue Mar 25 11:22:42 2014 via crmd on node1.luojianlong.com</code>
<code>Current DC: node1.luojianlong.com - partition WITHOUT quorum</code>
<code>Online: [ node1.luojianlong.com ]</code>
<code>OFFLINE: [ node2.luojianlong.com ]</code>
正常啟動node1.luojianlong.com後,叢集資源WebIP很可能會重新從node2.luojianlong.com轉移回node1.luojianlong.com。資源的這種在節點間每一次的來回流動都會造成那段時間内其無法正常被通路,是以,我們有時候需要在資源因為節點故障轉移到其它節點後,即便原來的節點恢複正常也禁止資源再次流轉回來。這可以通過定義資源的黏性(stickiness)來實作。在建立資源時或在建立資源後,都可以指定指定資源黏性。
資源黏性值範圍及其作用:
0:這是預設選項。資源放置在系統中的最适合位置。這意味着當負載能力“較好”或較差的節點變得可用時才轉移資源。此選項的作用基本等同于自動故障回複,隻是資源可能會轉移到非之前活動的節點上;
大于0:資源更願意留在目前位置,但是如果有更合适的節點可用時會移動。值越高表示資源越願意留在目前位置;
小于0:資源更願意移離目前位置。絕對值越高表示資源越願意離開目前位置;
INFINITY:如果不是因節點不适合運作資源(節點關機、節點待機、達到migration-threshold 或配置更改)而強制資源轉移,資源總是留在目前位置。此選項的作用幾乎等同于完全禁用自動故障回複;
-INFINITY:資源總是移離目前位置;
19.我們這裡可以通過以下方式為資源指定預設黏性值:
<code>[root@node1 ~]</code><code># crm configure rsc_defaults resource-stickiness=100</code>
20.結合上面已經配置好的IP位址資源,将此叢集配置成為一個active/passive模型的web(httpd)服務叢集,為了将此叢集啟用為web(httpd)伺服器叢集,我們得先在各節點上安裝httpd,并配置其能在本地各自提供一個測試頁面
<code># node1</code>
<code>[root@node1 ~]</code><code># yum -y install httpd</code>
<code>[root@node1 ~]</code><code># echo "node1.luojianlong.com" > /var/www/html/index.html</code>
<code># node2</code>
<code>[root@node2 ~]</code><code># yum -y install httpd</code>
<code>[root@node2 ~]</code><code># echo "node2.luojianlong.com" > /var/www/html/index.html</code>
21.而後在各節點手動啟動httpd服務,并确認其可以正常提供服務。接着使用下面的指令停止httpd服務,并確定其不會自動啟動(在兩個節點各執行一遍)
<code>[root@node1 ~]</code><code># /etc/init.d/httpd stop</code>
<code>Stopping httpd: [FAILED]</code>
<code>[root@node1 ~]</code><code># chkconfig httpd off</code>
<code>[root@node2 ~]</code><code># /etc/init.d/httpd stop</code>
<code>[root@node2 ~]</code><code># chkconfig httpd off</code>
22.接下來我們将此httpd服務添加為叢集資源。将httpd添加為叢集資源有兩處資源代理可用:lsb和ocf:heartbeat,為了簡單起見,我們這裡使用lsb類型,首先可以使用如下指令檢視lsb類型的httpd資源的文法格式
<code>[root@node1 ~]</code><code># crm ra info lsb:httpd</code>
23.接下來建立資源WebSite
<code>[root@node1 ~]</code><code># crm configure primitive WebServer lsb:httpd</code>
24.檢視配置檔案中生成的定義
<code>primitive WebIP ocf:heartbeat:IPaddr \</code>
<code> </code><code>params ip=</code><code>"192.168.30.230"</code>
<code>primitive WebServer lsb:httpd</code>
<code> </code><code>stonith-enabled=</code><code>"false"</code> <code>\</code>
<code> </code><code>no-quorum-policy=</code><code>"ignore"</code>
<code>rsc_defaults $</code><code>id</code><code>=</code><code>"rsc-options"</code> <code>\</code>
<code> </code><code>resource-stickiness=</code><code>"100"</code>
25.檢視資源的啟用狀态
<code>Last updated: Tue Mar 25 11:36:53 2014</code>
<code>Last change: Tue Mar 25 11:35:37 2014 via cibadmin on node1.luojianlong.com</code>
<code>2 Resources configured</code>
<code> </code><code>WebServer (lsb:httpd): Started node2.luojianlong.com</code>
從上面的資訊中可以看出WebIP和WebServer有可能會分别運作于兩個節點上,這對于通過此IP提供Web服務的應用來說是不成立的,即此兩者資源必須同時運作在某節點上。
由此可見,即便叢集擁有所有必需資源,但它可能還無法進行正确處理。資源限制則用以指定在哪些群集節點上運作資源,以何種順序裝載資源,以及特定資源依賴于哪些其它資源。pacemaker共給我們提供了三種資源限制方法:
1)Resource Location(資源位置):定義資源可以、不可以或盡可能在哪些節點上運作;
2)Resource Collocation(資源排列):排列限制用以定義叢集資源可以或不可以在某個節點上同時運作;
3)Resource Order(資源順序):順序限制定義叢集資源在節點上啟動的順序;
定義限制時,還需要指定分數。各種分數是叢集工作方式的重要組成部分。其實,從遷移資源到決定在已降級叢集中停止哪些資源的整個過程是通過以某種方式修改分數來實作的。分數按每個資源來計算,資源分數為負的任何節點都無法運作該資源。在計算出資源分數後,叢集選擇分數最高的節點。INFINITY(無窮大)目前定義為 1,000,000。加減無窮大遵循以下3個基本規則:
1)任何值 + 無窮大 = 無窮大
2)任何值 - 無窮大 = -無窮大
3)無窮大 - 無窮大 = -無窮大
#定義資源限制時,也可以指定每個限制的分數。分數表示指派給此資源限制的值。分數較高的限制先應用,分數較低的限制後應用。通過使用不同的分數為既定資源建立更多位置限制,可以指定資源要故障轉移至的目标節點的順序。
26.對于前述的WebIP和WebServer可能會運作于不同節點的問題,可以通過以下指令來解決
<code>[root@node1 ~]</code><code># crm configure colocation webserver-with-webip INFINITY: WebServer WebIP</code>
<code>Last updated: Tue Mar 25 11:39:58 2014</code>
<code>Last change: Tue Mar 25 11:39:31 2014 via cibadmin on node1.luojianlong.com</code>
<code> </code><code>WebServer (lsb:httpd): Started node1.luojianlong.com</code>
27.接着,我們還得確定WebSite在某節點啟動之前得先啟動WebIP,這可以使用如下指令實作
<code>[root@node1 ~]</code><code># crm configure order web-server-after-webip mandatory: WebIP WebServer</code>
28.接下來驗證高可用的效果:
<code>#現在所有資源都在node1上面:</code>
<code>Last updated: Tue Mar 25 11:46:41 2014</code>
<code>Last change: Tue Mar 25 11:41:18 2014 via cibadmin on node1.luojianlong.com</code>
<code>#在node2上面停止node1的corosync</code>
<code>Waiting </code><code>for</code> <code>corosync services to unload:..[ OK ]</code>
<a href="http://s3.51cto.com/wyfs02/M00/23/15/wKioL1Mw_XLAg3vzAADSagTe9Zc155.jpg" target="_blank"></a>
29.此外,由于HA叢集本身并不強制每個節點的性能相同或相近,是以,某些時候我們可能希望在正常時服務總能在某個性能較強的節點上運作,這可以通過位置限制來實作:
<code>[root@node1 ~]</code><code># crm configure location prefer-node1 WebServer rule 200: node1.luojianlong.com</code>
這條指令實作了将WebSite限制在node1上,且指定其分數為200。
部署過程中常見的問題:
1.啟動corosync服務後,發現日志不斷的報下面這個錯誤,後來發現是selinux沒有關閉的問題。
<code>[root@node1 ~]</code><code># /etc/init.d/corosync start</code>
<code>[root@node1 ~]</code><code># tail -f /var/log/cluster/corosync.log</code>
<code>Mar 26 11:38:43 [7875] node1.luojianlong.com lrmd: info: crm_client_new: Connecting 0x1bce860 </code><code>for</code> <code>uid=189 gid=0 pid=8001 </code><code>id</code><code>=630eb39c-1acd-4cad-8930-700c71680f91</code>
<code>Mar 26 11:38:43 [7875] node1.luojianlong.com lrmd: error: qb_ipcs_shm_rb_open: qb_rb_chmod:lrmd-request-7875-8001-153: Operation not permitted (1)</code>
<code>Mar 26 11:38:43 [7875] node1.luojianlong.com lrmd: error: qb_ipcs_shm_connect: shm connection FAILED: Operation not permitted (1)</code>
<code>Mar 26 11:38:43 [7875] node1.luojianlong.com lrmd: error: handle_new_connection: Error </code><code>in</code> <code>connection setup (7875-8001-153): Operation not permitted (1)</code>
<code>Mar 26 11:38:43 [8001] node1.luojianlong.com crmd: info: crm_ipc_connect: Could not establish lrmd connection: Operation not permitted (1)</code>
<code>Mar 26 11:38:43 [8001] node1.luojianlong.com crmd: warning: do_lrm_control: Failed to sign on to the LRM 12 (30 max) </code><code>times</code>
<code>Mar 26 11:38:43 [7960] node1.luojianlong.com cib: error: plugin_dispatch: Receiving message body failed: (2) Library error: Success (0)</code>
<code>Mar 26 11:38:43 [7960] node1.luojianlong.com cib: error: cib_cs_destroy: Corosync connection lost! Exiting.</code>
<code>Mar 26 11:38:43 [7960] node1.luojianlong.com cib: info: terminate_cib: cib_cs_destroy: Exiting fast...</code>
<code>Mar 26 11:38:43 [7960] node1.luojianlong.com cib: info: qb_ipcs_us_withdraw: withdrawing server sockets</code>
解決辦法:
<code>[root@node1 ~]</code><code># setenforce 0</code>
<code>[root@node1 ~]</code><code># vi /etc/selinux/config</code>
<code># 修改SELINUX=disabled</code>
<code># 檢視selinux狀态</code>
<code>[root@node1 ~]</code><code># getenforce</code>
<code></code>
本文轉自ljl_19880709 51CTO部落格,原文連結:http://blog.51cto.com/luojianlong/1382809,如需轉載請自行聯系原作者