歡迎您光臨本站 註冊首頁

heartbeat2.x的測試終結篇,針對使用heartbeat的新手

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

heartbeat2.x的測試終結篇,針對使用heartbeat的新手

下面的內容針對heartbeat新手,很多的操作是putty上的直接複製
Heartbeat 2.x 功能
2.x和1.x最主要的區別在於,
1) 2.x支持CRM管理,資源文件由原來的haresources變為cib.xml,
2) 支持OCF格式的resource agent,
3) 可以對多資源組進行獨立監控
4)支持多節點

一、下載軟體包
下載libnet
http://www.packetfactory.net/libnet/
下載heartbeat
http://www.linux-ha.org/DownloadSoftware
http://hg.linux-ha.org/lha-2.1/archive/STABLE-2.1.4.tar.bz2
二、編譯安裝軟體包
tar -xvf libnet-1.1.3-RC-01.tar.gz(此版本有問題,使用1.2版本)
cd libnet
./configure ; make ; make install
cd ..
tar -xvf Heartbeat-STABLE-2-1-STABLE-2.1.4.tar.bz2
cd Heartbeat-STABLE-2-1-STABLE-2.1.4
./ConfigureMe configure ; make ; make install

在包含自 /usr/include/libnet.h:120 的文件中,
                 從send_arp.c:33:
/usr/include/./libnet/libnet-types.h:36:23: 錯誤:../config.h:沒有那個文件或者目錄
gmake: *** 錯誤 1
gmake: Leaving directory `/w/Heartbeat-STABLE-2-1-STABLE-2.1.4/heartbeat/libnet_util'
gmake: *** 錯誤 1
gmake: Leaving directory `/w/Heartbeat-STABLE-2-1-STABLE-2.1.4/heartbeat'
make: *** 錯誤 1

更換libnet1.2的穩定版本
tar -xvf libnet.tar.gz
執行相同的編譯沒有錯誤
三、編輯配置文件
groupadd -g 694 haclient
useradd -u 694 -g haclient hacluster

這個操作是編譯安裝必須的過程
/usr/share/doc/heartbeat-2.1.4此目錄中放置的是配置文件的示例httpd is an unknown Resource Agent. Please refer to http://www.linux-ha.org/ResourceAgent
說明沒有httpd服務,安裝上就可以了
rpm -ivh httpd-2.2.3-11.el5_1.3.x86_64.rpm
rs2 heartbeat: : EMERG: Rebooting system.  Reason: /usr/lib64/heartbeat/cib如果沒有上述賬戶將會出現上面的錯誤
rm -rf /var/run/heartbeat

修改heartbeat目錄許可權,可以用以下命令:
find / -type d -name "heartbeat" -exec chown -R hacluster {} \;
find / -type d -name "heartbeat" -exec chgrp -R haclient {} \;
chown -R hacluster /usr/lib/heartbeat
chown -R hacluster /usr/lib/ocf/resource.d/heartbeat
chown -R hacluster /usr/include/heartbeat
chown -R hacluster /usr/share/heartbeat
chown -R hacluster /var/lib/heartbeat
chown -R hacluster /var/run/heartbeat
chgrp -R haclient /usr/lib/heartbeat
chgrp -R haclient /usr/lib/ocf/resource.d/heartbeat
chgrp -R haclient /usr/include/heartbeat
chgrp -R haclient /usr/share/heartbeat
chgrp -R haclient /var/lib/heartbeat
chgrp -R haclient /var/run/heartbeat建立賬戶就是解決這個問題的。# cat authkeys
auth 1
1 crc
#chmod 600 authkeys這個步驟是不能缺少的
cat ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 10
warntime 5
initdead 60
udpport 694
#baud    19200
#serial  /dev/ttyS0      # Linux
#bcast   eth1
mcast eth0 225.0.0.1 694 1 0
#ucast eth1 172.16.1.134
auto_failback on
watchdog /dev/watchdog
crm yes
node    rs11
node    rs12
ping 192.168.1.141
ping_group group1 10.10.10.254 10.10.10.253
respawn hacluster /usr/lib/heartbeat/ipfail
#respawn hacluster /usr/lib/heartbeat/pingd
#apiauth ping gid=haclient uid=hacluster
apiauth ipfail gid=haclient uid=hacluster
respawn hacluster /usr/lib/heartbeat/cibmon -d
apiauth cibmon   uid=hacluster#cat bak.haresources
rs11   192.168.1.145  httpd
這個文件原名為haresources在1.x上使用,不過為了區別使用此名稱
如不使用此配置方式將出現資源無法啟動的問題;類似 rs11 192.168.1.145/24/eth0 httpd
生成附上一段配置文件cib.xml的生成方式/lib64標識x86_64的方式
rm -rf /var/lib/heartbeat/crm/cib.xml*
/usr/lib64/heartbeat/haresources2cib.py haresources
rm -rf /var/lib/heartbeat/crm/cib.xml*
/usr/lib64/heartbeat/haresources2cib.py -stout -c /etc/ha.d/ha.cf /etc/ha.d/haresources
rm -rf /var/lib/heartbeat/crm/cib.xml*
/usr/lib64/heartbeat/haresources2cib.py -stout -c /etc/ha.d/ha.cf /etc/ha.d/bak.haresources


  rm -rf /var/lib/heartbeat/crm/cib.xml*
/usr/lib/heartbeat/haresources2cib.py -stout -c /etc/ha.d/ha.cf /etc/ha.d/bak.haresources
scp /var/lib/heartbeat/crm/cib.xml 192.168.1.147:/var/lib/heartbeat/crm/cib.xml

  scp ha.cf root@192.168.1.144:/etc/ha.d/ha.cf
scp /var/lib/heartbeat/crm/cib.xml root@192.168.1.144:/var/lib/heartbeat/crm/cib.xml
cat /var/lib/heartbeat/crm/cib.xml
                <resources>
                        <group id="group_1">
                                <primitive class="ocf" id="IPaddr_192_168_1_145" provider="heartbeat" type="IPaddr">
                                        <operations>
                                                <op id="IPaddr_192_168_1_145_mon" interval="5s" name="monitor" timeout="5s"/>
                                        </operations>
                                        <instance_attributes id="IPaddr_192_168_1_145_inst_attr">
                                                <attributes>
                                                        <nvpair id="IPaddr_192_168_1_145_attr_0" name="ip" value="192.168.1.145"/>
                                                </attributes>
                                        </instance_attributes>
                                </primitive>
                                <primitive class="lsb" id="httpd_2" provider="heartbeat" type="httpd">
                                        <operations>
                                                <op id="httpd_2_mon" interval="120s" name="monitor" timeout="60s"/>
                                        </operations>
                                </primitive>
                        </group>
                </resources>
將上面的httpd_2部分修改說明
interval="20s"
timeout="10s"
即每20秒檢測資源運行情況,如果發現資源不在,則嘗試啟動資源,如果10s后還未啟動成功,則資源切換向另節點,上述的數值可以縮減的更小,否則默認的2分鐘會給人一種服務down沒有重啟或者切換的感覺。注意:IPaddr使用的是ocf格式的控制腳本,路徑為:/usr/lib/ocf/resource.d/heartbeat/IPaddr
如果是在/etc/init.d/下的腳步都是lsb的腳步,這個通過crm_mon是可以看到 ;crm_resource -L也是有相同的顯示;
介紹一下ocf和lsb格式的區別:
LSB格式的腳本必須支持status功能,必須能接收start,stop,status,三個參數;而如果是OCF格式,則必須支持start,stop,monitor三個參數.其中status和monitor參數是用來監控資源的,非常重要.
例如LSB風格的腳本,運行./Mysql status時候,
返回值包含OK或則running則表示資源正常
返回值包含stopped或者No則表示資源不正常。
假如是OCF風格的腳本,運行./Mysql monitor時候,
返回0表示資源是正常的,
返回7表示資源出現問題.
ocf格式的啟動腳本在/usr/lib/ocf/resource.d/heartbeat
lsb的腳步一般在/etc/init.d/下面
啟動腳步后
通過crm_mon 可以查看資源狀態;可以通過參數指定刷新時間crm_mon -i1,標識每秒刷新;
#crm_mon -i1
Refresh in 1s...
============
Last updated: Wed Dec 10 00:57:44 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): online
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs11
    httpd_2     (lsb:httpd):    Started rs11查看所有資源
#crm_resource -L
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr)
    httpd_2     (lsb:httpd)
查看資源在那個節點上運行
#crm_resource -W -r httpd_2
resource httpd_2 is running on: rs11
查看資源在cib.xml中的定義# crm_resource -x -r httpd_2
httpd_2 (lsb:httpd):    Started rs11
raw xml:
<primitive class="lsb" provider="heartbeat" type="httpd" id="httpd_2">
   <operations>
     <op id="httpd_2_mon" interval="120s" name="monitor" timeout="60s"/>
   </operations>
   <instance_attributes id="httpd_2">
     <attributes>
       <nvpair name="target_role" id="httpd_2-target_role" value="started"/>
     </attributes>
   </instance_attributes>
</primitive>啟動/停止資源
#crm_resource -r httpd_2 -p target_role -v started
#crm_resource -r httpd_2 -p target_role -v stopped
將資源從當前節點轉移到另個節點
#crm_resource -M -r httpd_2
將資源轉移到指定節點
#crm_resource -M -r httpd_2 -H rs12
允許資源回到正常的節點
#crm_resource -U -r httpd_2
將資源從CRM中刪除
#crm_resource -D -r httpd_2 -t primitive
將資源組從CRM中刪除
#crm_resource -D -r My-DRBD-group -t group
將資源從CRM中禁用
#crm_resource -p is_managed -r httpd_2 -t primitive -v off
將資源從新從CRM中啟用
#crm_resource -p is_managed -r httpd_2 -t primitive -v on
重啟資源
#crm_resource -C -H rs12 -r httpd_2
檢查所有節點上未在CRM中的資源
#crm_resource -P
檢查指定節點上未在CRM中的資源
#crm_resource -P -H rs12
檢查所有節點上未在CRM中的資源
#crm_resource -P
檢查指定節點上未在CRM中的資源
#crm_resource -P -H rs12
設置資源的某個屬性
#crm_resource -r httpd_2 -p email -v "lvsheat@qq.com"
網路切換測試
Refresh in 1s...
============
Last updated: Wed Dec 10 01:11:16 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): OFFLINE
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):       Stopped==> Started rs12
    httpd_2     (lsb:httpd):    Stopped==> Started rs12
Refresh in 1s...
============
Last updated: Wed Dec 10 01:11:42 2008
Current DC: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): OFFLINE
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): online
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs11
    httpd_2     (lsb:httpd):    Started rs11服務切換,需要設置cib.xml中的數值
Refresh in 1s...
============
Last updated: Wed Dec 10 01:12:25 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): online
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs11
    httpd_2     (lsb:httpd):    Started rs11 FAILED
Failed actions:
    httpd_2_monitor_5000 (node=rs11, call=13, rc=7): complete

Refresh in 1s...
============
Last updated: Wed Dec 10 01:12:35 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): online
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs11
    httpd_2     (lsb:httpd):    Stopped
Failed actions:
    httpd_2_monitor_5000 (node=rs11, call=16, rc=7): complete
Refresh in 1s...
============
Last updated: Wed Dec 10 01:12:38 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): online
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs11
    httpd_2     (lsb:httpd):    Started rs11
宕機切換
Refresh in 1s...
============
Last updated: Wed Dec 10 01:13:23 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): online
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs11
    httpd_2     (lsb:httpd):    Stopped
Failed actions:
    httpd_2_monitor_5000 (node=rs11, call=19, rc=7): complete
Refresh in 1s...
============
Last updated: Wed Dec 10 01:13:41 2008
Current DC: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0)
2 Nodes configured.
1 Resources configured.
============
Node: rs12 (041ec13a-a975-4813-ae93-56ca0dfc89b0): online
Node: rs11 (6bccf2ee-a1b7-40d2-a875-729149e372ea): OFFLINE
Resource Group: group_1
    IPaddr_192_168_1_145        (ocf::heartbeat:IPaddr):        Started rs12
    httpd_2     (lsb:httpd):    Started rs12

mv httpd.conf httpd.conf.1
killall httpd

[ 本帖最後由 kns1024wh 於 2008-12-30 11:07 編輯 ]
《解決方案》

很不錯的文檔。剛好正在搞,看看。
《解決方案》

收藏,:lol:
《解決方案》

看的一些文檔咋都沒有原理說明呢~~~~~~~
 如果第一次看都比較暈。
《解決方案》

回復 #4 hb_li_520 的帖子

原理說明在官方web頁上有。
《解決方案》

原帖由 hb_li_520 於 2008-12-26 16:33 發表 http://linux.chinaunix.net/bbs/images/common/back.gif
看的一些文檔咋都沒有原理說明呢~~~~~~~
 如果第一次看都比較暈。


heartbeat的官方文檔,個人覺得組織的不是很好,剛開始可能有些難以入門。相比之下,其他的一些開源項目官方文檔要好的多,比如drbd。
《解決方案》

回復 1# kns1024wh


    httpd_2   腳本怎麼寫的?

[火星人 ] heartbeat2.x的測試終結篇,針對使用heartbeat的新手已經有873次圍觀

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