歡迎您光臨本站 註冊首頁

分享:heartbeat 2.x style的配置(使用cib.xml)

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

分享:heartbeat 2.x style的配置(使用cib.xml)

一) 前言:

網上關於heartbeat的文章很多,但大部分是基於1.x style的,

我把我配置的2.x style的heartbeat 過程發出來,

希望對大家能有一點用,

2.x和1.x最主要的區別在於,

1) 2.x支持CRM管理,資源文件由原來的haresources變為cib.xml,

2) 支持OCF格式的resource agent,

3) 可以對多資源組進行獨立監控(這點我不確定在1.x里是否可以,沒試過)

4)支持多節點

二) 配置

本文假設原有的heartbeat 已經配置好且能正常工作,
如和配置heartbeat不屬於本文討論範圍.

我這裡以兩節點為例:
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資源文件轉換成cib.xml,2.x里編譯好后自帶有轉換腳本,很方便.
        假設haresources文件如下,
        node1 192.168.1.205 runhttpd.sh
        node2 runjboss.sh
        每一行表示一個資源組,
        node1,node2表示prefered node,即該資源組優先在該node上運行,
        192.168.1.205與runhttpd.sh一起屬於第一個資源組,為提供http服務的vip,
        啟動的時候從左到右依次運行腳本,關閉的時候從右到左依次關閉.
        a):轉換命令
        /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目錄許可權,可以用以下命令:
        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,三個參數,如果是OCF格式agent,則必須支持
                    start,stop,monitor三個參數.其中status和monitor參數是用來監控資源的,非常重要.
        例如LSB風格的腳本,運行./runhttpd.sh status時候,
        返回值包含OK或則running則表示資源正常
        返回值包含stopped或者No則表示資源不正常。

        假如是OCF風格的腳本,運行./runhttpd.sh monitor時候,
        返回0表示資源是正常的,
        返回7表示資源出現問題.

三) 與1.x相比的區別

與1.x風格相比,功能變化:

1)保留原有所有功能
        如,網路,heartbeat ,機器down了時候均可以切換資源。

2)自動監控資源
        每2分鐘檢測資源運行情況,如果發現資源不在,則嘗試啟動資源,
        如果60s后還未啟動成功,則資源切換向另節點。時間可以修改。
         <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的監控,每5S監控一次,若vip失效,則嘗試重啟vip,timeout時間為5s,若5s后啟動不成功,則切換向另節點。
         <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)可以對各資源組實現獨立監控.
        比如jboss運行在node1上,apache運行在node2上,

4)同時監控系統負載
        可以自動將資源切換到負載低的node上


四) CRM管理程序crm_resource功能示例:

Examples
1)查看所有資源

  crm_resource -L

2)查看資源跑在哪個節點上

  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)將資源從當前節點移動向另個節點

  crm_resource -M -r runhttpd.sh_2

7)將資源移向指定節點

  crm_resource -M -r runhttpd.sh_2 -H c001n02

8)允許資源回到正常的節點

  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)檢查所有節點上未在CRM中的資源

  crm_resource -P

15)檢查指定節點上未在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"


寫的比較匆忙,有錯誤的地方請指正.

歡迎轉載,修改,不需要標明作者,不過最好請標明來自CU.

參考文檔:www.linux-ha.org
《解決方案》

good ,不過有 hagui這樣的圖形界面配置工具,大家可以用這個圖形工具去配置。

另外,newstar ha是基於heartbeat,如果能放出他們的配置工具就更好了。(如果他們願意遵守gpl協議的話)
《解決方案》

有沒有試過將IPaddr + drbd + Filesystem + service(apache, ftp etc.)的全部使用ocf RA的例子?我正在研究這玩意,有很多問題。最好還能用上pingd作為連接的監控進程。
《解決方案》

好東西 謝謝分享
2樓圖形配置?
有幾台伺服器裝了圖形界面?
《解決方案》

2.x的圖形配置工具很複雜,折騰了很久
《解決方案》

好東西。一定要定。目前還沒有詳細說2.X的新資源配置文件的文檔呢。
《解決方案》

對hb不熟悉,贊一個
《解決方案》

樓主對2.0的基本配置說的不是很詳細。剛弄完了1.0的功能,正在搗騰CRM。資料不多,碰到了這篇文章真是慶幸,感謝一下。:em02: :em02:
《解決方案》

這幾天主要在看HEARTBEAT,對樓主的文章提個疑問吧:

2)將haresources資源文件轉換成cib.xml,2.x里編譯好后自帶有轉換腳本,很方便.
        假設haresources文件如下,
        node1 192.168.1.205 runhttpd.sh
        node2 runjboss.sh
        每一行表示一個資源組,

在這一段中runhttpd.sh這個腳本,原因我不是很理解,如果針對VIP的話,其實沒必要,直接寫個node1 192.168.1.205 apache(apache的默認啟動腳本)即可,HEARTBEAT可以自動增加個介面並賦予IP192.168.1.205。或許樓主的意思runhttpd.sh就是代表的默認的apache的啟動腳本,那就是我誤解了。如果不是的話還請樓主把這個腳本的程序內容貼出來讓大家學習一下:em02:
《解決方案》

我發現heartbeat v2.1.3的haresource2cib.py轉換ipaddr有問題,會把nic和netmask顛倒,需要手動修改回來

[火星人 ] 分享:heartbeat 2.x style的配置(使用cib.xml)已經有533次圍觀

http://coctec.com/docs/service/show-post-6935.html