heartbeat

Heartbeat

 

Server1 172.25.23.1

Server2 172.25.23.2

VIP 172.25.23.100

Iptables selinux disabled 加解析 rhel6.5

 

server1server2上都配置

一.配置heartbeat

1.安裝軟件

[root@server1 ~]# yum install httpd -y# web做測試

[root@server1 ~]# ls

wKioL1fVJJrx3rqvAAA6NuPnr1M695.png 

[root@server1 ~]# yum install -y *

 

2.修改配置文件

[root@server1 ~]# cd /etc/ha.d

[root@server1 ha.d]# rpm -q heartbeat -d

wKioL1fVJKjCU_URAAG6hwpHs7k446.png 

 

[root@server1 ha.d]# vim ha.cf

......

29 logfile /var/log/ha-log#系統運行日誌文件,取默認值

48 keepalive 2#心跳頻率,自己設定。1:表示1秒;1ms:表示 1毫秒

56 deadtime 30#節點死亡時間閥值,就是從節點在過了 30 後還沒有收到心跳就認爲主節點死亡

61 warntime 10#發出警告時間

71 initdead 60#守護進程首次啓動後應該等待 120 秒後再啓動主服務器上的資源

76 udpport 694#心跳信息傳遞的 udp 端口,使用端口694進行 bcast ucast 通信 (同一個廣播域udpport不同)

91 bcast   eth0

157 auto_failback on         #當主節點恢復後,是否自動切回

211 node   server1.example.com #主節點,排在前邊

212 node   server2.example.com #從節點

220 ping 172.25.23.250 # ping第三方IP

253 respawn hacluster /usr/lib64/heartbeat/ipfail

259 apiauth ipfail gid=haclient uid=hacluster

......

 

[root@server1 ha.d]# vim authkeys # 認證方式

......

auth 1

1 crc

#2 sha1 HI!

#3 md5 Hello!

 

[root@server1 ha.d]# chmod 600 authkeys # 修改權限

[root@server1 ha.d]# vim haresources

......

server1.example.com IPaddr::172.25.23.100/24/eth0 httpd   

 

# IPaddr 的作用是啓動 Virutal IP,它是 HeartBeat 自帶的一個腳本

# ldirectord 的作用是啓動 ldirectord 監控程序它會使 ldirectord.cf 中定義的 lvs 生效

並監聽其健康狀

# httpd apache 服務的啓動腳本。

 

三個主默認目錄: /etc/init.d   /etc/ha.d/rc.d   /etc/ha.d/resource.d

                                                       

[root@server1 ha.d]# scp authkeys haresources ha.cf [email protected]:/etc/ha.d/

[root@server1 ha.d]# /etc/init.d/heartbeat start

[root@server2 ha.d]# /etc/init.d/heartbeat start

# 同時啓動server1server2服務

[root@server1 ha.d]# tail -f /var/log/ha-log

# 查看啓動是否成功

 

2.測試

[root@server1 ha.d]# echo server1 > /var/www/html/index.html

[root@server2 ha.d]# echo server2 > /var/www/html/index.html

[root@server1 ha.d]# Ip addr show #可查看到vip在哪裏

 

訪問172.252.3.100 先訪問server1的,當server1heartbeat停止,再由server2接管。期間若server1heartbeat啓動(只能手動啓動,不會自動),則又由server1接管,這是因爲採用了主備模式。

 

當主節點server1只停止httpd服務時,只要heartbeat服務不停止,server2就不會接管;所以網頁訪問時會出現錯誤界面。

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章