集群基礎 (heartbeat心跳元件)

2021-08-04 09:42:05 字數 2929 閱讀 3107

集群間心跳(heartbeat)

heartbeat-3.0

.4-2.el6.x86_64.rpm

heartbeat-devel-3.0

.4-2.el6.x86_64.rpm

heartbeat-libs-3.0

.4-2.el6.x86_64.rpm

yum install -y heartbeat-*
2.修改heartbeat配置檔案(heartbeat沒有健康檢查)

cd /etc/ha.d/

[root@server1 ha.d]# cat readme.config

and they all go in this directory.

they are:

ha.cf main configuration file(主配置檔案)

haresources resource configuration file(資源定義檔案)

authkeys authentication information(認證檔案)

these first two may be readable by everyone, but

the authkeys file

must not be.

the good news is

that sample versions of these files may be found in

the documentation directory (providing you installed the documentation).

if you installed heartbeat using rpm packages then

this command will show you where they are on

your system:

rpm -q heartbeat -d

if you installed heartbeat using debian packages then

the documentation should be located in /usr/share/doc/heartbeat

[root@server1 ha.d]# cd /usr/share/doc/heartbeat-3.0.4/

[root@server1 heartbeat-3.0

.4]# ls

authkeys copying haresources

authors copying.lgpl readme

2)複製主配置檔案到/etc/ha.d/才能生效

cd /usr/share/doc/heartbeat-3.0

.4/ cp ha.cf authkeys haresources /etc/ha.d/

3)修改主配置檔案(在主節點修改)

cd /etc/ha.d/

vim ha.cf   (呼叫ipfaill外掛程式用於主備切換,實現高可用)

34 logfacility local0

48 keepalive 2 心跳頻率

56 deadtime 30 多久一次判斷是否掛了

61 warntime 10 多久警告一次

71 initdead 60 初始化時間

76 u***ort 733 埠連線(區域網不能衝突了)

91 bcast eth0 廣播傳送

157 auto_failback on 自動回切

211 node server1

212 node server4

220ping

172.25

.39.250(和227行的ping群設定乙個即可)

253 respawn hacluster /usr/lib64/heartbeat/ipfail(64位)

259 apiauth ipfail gid=haclient uid=hacluster(api認證,在裝rpm包時候,使用者已經被建立)

4)修改認證檔案

cd /etc/ha.d/

vim authkeys

23 auth 1

241 crc

chmod 600 authkeys (認證key必須600許可權,不然訪問不了)*

5)修改資源定義檔案

cd /etc/ha.d/(可以自動搜尋這三個地方的指令碼/etc/ha.d/rc.d/、/etc/ha.d/resourced)

vim haresources

151 server1 ipaddr::172.25.39.100/24/eth0 httpd(ipaddr:資源指令碼名;後面傳參)(eth0:vip生效的地方)【主節點的主機名、vip、需要維護的服務】

3.傳送相同的三個檔案到server4

scp ha.cf authkeys haresources server4:/etc/ha.d/
4.

1)/etc/init.d/heartbeat start(server1)

tail -f /var/log/messages(檢視是否有錯誤)

2)開啟server4上的心跳

5.測試:

編寫測試頁:/var/www/html/index.html

(/etc/init.d/heartbeat stop

/etc/init.d/heartbeat start)

可以在網頁上測試172.25

.78.100或者在主機上 curl 172.25

.78.100

關於心跳 Heartbeat

最近做了一些服務軟體冗餘的工作。其中的一點就是實現服務冗餘的切換機制,通常採用心跳來實現,我這裡採用的是應用層的自定義心跳協議。心跳協議 heartbeat protocol 是用來監控網路中的節點及確認其正常工作。監控 倆字就要求了 心跳協議的資訊必須包含 狀態描述 和 切換機制描述。在服務冗餘心...

HeartBeat 集群元件概述

通常使用集群方式實現,這也是集群的最大作用和體現。其終極目標是確保服務實時可用,不會因為任意的軟硬體故障導致服務出現終止和不可用的情形。系統的可靠性 reliability 和可維護性 maintainability 來度量。工程上,通常用平均無故障時間 mttf 來度量系統的可靠性,用平均修復時間...

為什麼心跳包 HeartBeat 是必須的?

幾乎所有的網遊服務端都有心跳包 heartbeat或ping 的設計,在最近開發手遊服務端時,也用到了心跳包。思考思考,心跳包是必須的嗎?為什麼需要心跳包?tcp沒有提供斷線檢測的方法嗎?tcp提供的keepalive機制可以替代heartbeat嗎?由於連線丟失時,tcp不會立即通知應用程式。比如...