- 論壇徽章:
- 0
|
heartbeat2.1.4 實現(xiàn)監(jiān)控應用服務(mysql)具體步驟:
OS:centos 4.6
APP01:
eth0:10.1.2.111
eth1:100.100.100.100
APP02:
eth0:10.1.2.110
eth1:100.100.100.99
Vip:10.1.2.113
rpm -ivh heartbeat-pils-2.1.4-2.1.rpm
rpm -ivh heartbeat-stonith-2.1.4-2.1.rpm
rpm -ivh heartbeat-2.1.4-2.1.rpm
cat /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 1000ms
deadtime 10
warntime 5
initdead 60
udpport 694
bcast eth1 eth0
auto_failback off
watchdog /dev/watchdog
crm on
node APP02 APP01
ping 10.1.2.10
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root
EOD
cat /etc/ha.d/haresources
APP02 IPaddr::10.1.2.113/24/eth0 Mysql
EOD
#這里的Mysql是用來控制mysql的停止和啟動和監(jiān)控
echo -e "auth 1\n1 crc" >/etc/ha.d/authkeys
chmod 600 /etc/ha.d/authkeys
/usr/lib/heartbeat/haresources2cib.py
#在/var/lib/heartbeat/下會生成cib.xml文件,但該文件需要進行部分調(diào)整
只需修改cib.xml文件中資源部分:
修改為:
interval="30s"
timeout="15s"
即每30秒檢測資源運行情況,如果發(fā)現(xiàn)資源不在,則嘗試啟動資源,如果15s后還未啟動成功,則資源切換向另節(jié)點
注意:IPaddr使用的是ocf格式的控制腳本,路徑為:/usr/lib/ocf/resource.d/heartbeat/IPaddr
這里的Mysql沒有指定使用什么風格的控制腳本,默認應該也是ocf,可在這里因為ocf下只有mysql,沒有Mysql這個腳本
heartbeat會去/etc/ha.d/resource.d/下尋找Mysql,在這里我使用了LSB風格,但使用很正常,這一點有些不解.
介紹一下ocf和lsb格式的區(qū)別:
LSB格式的腳本必須支持status功能,必須能接收start,stop,status,三個參數(shù);而如果是OCF格式,則必須支持start,stop,monitor三個參數(shù).其中status和monitor參數(shù)是用來監(jiān)控資源的,非常重要.
例如LSB風格的腳本,運行./Mysql status時候,
返回值包含OK或則running則表示資源正常
返回值包含stopped或者No則表示資源不正常。
假如是OCF風格的腳本,運行./Mysql monitor時候,
返回0表示資源是正常的,
返回7表示資源出現(xiàn)問題.
ocf格式的啟動腳本在/usr/lib/ocf/resource.d/heartbeat
lsb格式的啟動腳本在/usr/lib/lsb/resource.d/heartbeat
cd /etc/ha.d/ && scp authkeys haresources ha.cf 10.1.2.110:/etc/ha.d/
cd /var/lib/heartbeat/crm
rm cib.xml.* -f
ssh 10.1.2.110 "rm /var/lib/heartbeat/crm/* -f"
scp cib.xml 10.1.2.110:/var/lib/heartbeat/crm/
note:heartbeat2.x不使用haresources,如果它的存在的話,在heartbeat啟動時log中會出現(xiàn)一條WARN的信息:
heartbeat[30304]: 2008/11/26_20:02:02 WARN: File /etc/ha.d/haresources exists.
heartbeat[30304]: 2008/11/26_20:02:02 WARN: This file is not used because crm is enabled
但不影響使用.
啟動heartbeat:
/etc/init.d/heartbeat start
#沒有主次之分,誰先啟動誰先獲取資源.
監(jiān)控資源運行情況:
#每3秒更新一次,顯示當前資源的情況.
crm_mon -i3
#查看所有資源
[root@APP01 crm]# crm_resource -L
Resource Group: group_1
IPaddr_10_1_2_113 (ocf::heartbeat:IPaddr)
Mysql_2 (heartbeat:Mysql)
[root@APP01 crm]#
#查看資源跑在哪個節(jié)點上
[root@APP01 crm]# crm_resource -W -r Mysql_2
resource Mysql_2 is running on: APP01
[root@APP01 crm]#
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u3/111930/showart_2185652.html |
|