- 論壇徽章:
- 0
|
一) 前言:
網(wǎng)上關(guān)于heartbeat的文章很多,但大部分是基于1.x style的,
我把我配置的2.x style的heartbeat 過程發(fā)出來,
希望對大家能有一點用,
2.x和1.x最主要的區(qū)別在于,
1) 2.x支持CRM管理,資源文件由原來的haresources變?yōu)閏ib.xml,
2) 支持OCF格式的resource agent,
3) 可以對多資源組進行獨立監(jiān)控(這點我不確定在1.x里是否可以,沒試過)
4)支持多節(jié)點
二) 配置
本文假設原有的heartbeat 已經(jīng)配置好且能正常工作,
如和配置heartbeat不屬于本文討論范圍.
我這里以兩節(jié)點為例:
node1 和node2,
有兩個資源作HA,apache和jboss,
其中apache使用vip :192.168.1.205,
jboss無vip,
1)在ha.cf里面增加
crm yes
apiauth cibmon uid=hacluster
respawn hacluster /usr/local/lib/heartbeat/cibmon -d
2)將haresources資源文件轉(zhuǎn)換成cib.xml,2.x里編譯好后自帶有轉(zhuǎn)換腳本,很方便.
假設haresources文件如下,
node1 192.168.1.205 runhttpd.sh
node2 runjboss.sh
每一行表示一個資源組,
node1,node2表示prefered node,即該資源組優(yōu)先在該node上運行,
192.168.1.205與runhttpd.sh一起屬于第一個資源組,為提供http服務的vip,
啟動的時候從左到右依次運行腳本,關(guān)閉的時候從右到左依次關(guān)閉.
a):轉(zhuǎn)換命令
/usr/local/lib/heartbeat/haresources2cib.py --stout -c /usr/local/etc/ha.d/ha.cf /usr/local/etc/ha.d/haresources
b):這一步可選
清空/usr/local/etc/ha.d/haresources
echo "" > /usr/local/etc/ha.d/haresources
3)
修改heartbeat目錄權(quán)限,可以用以下命令:
find / -type d -name "heartbeat" -exec chown -R hacluster {} \;
find / -type d -name "heartbeat" -exec chgrp -R haclient {} \;
4)LSB格式的resource agent script中必須支持status功能
所謂的resource agent就是服務的啟動腳本,這我這里叫runhttpd.sh,runjboss等,
必須能接收start,stop,status,三個參數(shù),如果是OCF格式agent,則必須支持
start,stop,monitor三個參數(shù).其中status和monitor參數(shù)是用來監(jiān)控資源的,非常重要.
例如LSB風格的腳本,運行./runhttpd.sh status時候,
返回值包含OK或則running則表示資源正常
返回值包含stopped或者No則表示資源不正常。
假如是OCF風格的腳本,運行./runhttpd.sh monitor時候,
返回0表示資源是正常的,
返回7表示資源出現(xiàn)問題.
三) 與1.x相比的區(qū)別
與1.x風格相比,功能變化:
1)保留原有所有功能
如,網(wǎng)絡,heartbeat ,機器down了時候均可以切換資源。
2)自動監(jiān)控資源
每2分鐘檢測資源運行情況,如果發(fā)現(xiàn)資源不在,則嘗試啟動資源,
如果60s后還未啟動成功,則資源切換向另節(jié)點。時間可以修改。
<primitive class="heartbeat" id="runhttpd.sh_2" provider="heartbeat" type="runhttpd.sh">
<operations>
<op id="runhttpd.sh_2_mon" interval="120s" name="monitor" timeout="60s"/>
</operations>
</primitive>
對VIP的監(jiān)控,每5S監(jiān)控一次,若vip失效,則嘗試重啟vip,timeout時間為5s,若5s后啟動不成功,則切換向另節(jié)點。
<primitive class="ocf" id="IPaddr_192_168_1_205" provider="heartbeat" type="IPaddr">
<operations>
<op id="IPaddr_192_168_1_205_mon" interval="5s" name="monitor" timeout="5s"/>
</operations>
<instance_attributes id="IPaddr_192_168_1_205_inst_attr">
<attributes>
<nvpair id="IPaddr_192_168_1_205_attr_0" name="ip" value="192.168.1.205"/>
</attributes>
</instance_attributes>
</primitive>
3)可以對各資源組實現(xiàn)獨立監(jiān)控.
比如jboss運行在node1上,apache運行在node2上,
4)同時監(jiān)控系統(tǒng)負載
可以自動將資源切換到負載低的node上
四) CRM管理程序crm_resource功能示例:
Examples
1)查看所有資源
crm_resource -L
2)查看資源跑在哪個節(jié)點上
crm_resource -W -r runhttpd.sh_2
resource runhttpd.sh_2 is running on: server1
crm_resource -W -r runhttpd.sh_2
resource runhttpd.sh_2 is NOT running
4)啟動/停止資源
crm_resource -r runhttpd.sh_2 -p target_role -v started
crm_resource -r runhttpd.sh_2 -p target_role -v stopped
5)查看資源在cib.xml中的定義
crm_resource -x -r runhttpd.sh_2
6)將資源從當前節(jié)點移動向另個節(jié)點
crm_resource -M -r runhttpd.sh_2
7)將資源移向指定節(jié)點
crm_resource -M -r runhttpd.sh_2 -H c001n02
允許資源回到正常的節(jié)點
crm_resource -U -r runhttpd.sh_2
NOTE: the values of resource_stickiness and default_resource_stickiness may mean that it doesnt move back. In such cases, you should use -M to move it back and then run this command.
9)將資源從CRM中刪除
crm_resource -D -r runhttpd.sh_2 -t primitive
10)將資源組從CRM中刪除
crm_resource -D -r my_first_group -t group
11)將資源從CRM中禁用
crm_resource -p is_managed -r runhttpd.sh_2 -t primitive -v off
12)將資源從新從CRM中啟用
crm_resource -p is_managed -r runhttpd.sh_2 -t primitive -v on
13)Resetting a failed resource after having been manually cleaned up
crm_resource -C -H c001n02 -r runhttpd.sh_2
14)檢查所有節(jié)點上未在CRM中的資源
crm_resource -P
15)檢查指定節(jié)點上未在CRM中的資源
crm_resource -P -H c001n02
Querying a parameter of a resource. Say the resource is the following:
<primitive id="example_mail" class="ocf" type="MailTo" provider="heartbeat">
<instance_attributes id="example_mail_inst">
<attributes>
<nvpair id="example_mail_inst_attr0" name="email" value="root"/>
<nvpair id="example_mail_inst_attr1" name="subject" value="Example Failover"/>
</attributes>
</instance_attributes>
</primitive>
You could query the email address using the following:
crm_resource -r example_mail -g email
16)設置資源的某個屬性
crm_resource -r example_mail -p email -v "myemailaddress@somedomain.com"
寫的比較匆忙,有錯誤的地方請指正.
歡迎轉(zhuǎn)載,修改,不需要標明作者,不過最好請標明來自CU.
參考文檔:www.linux-ha.org |
|