heartbeat 安裝使用

Hearbeat 軟件未來發展說明(2.1.4以後):

hearbeat                   羣集消息層負責維護集羣各節點間的相互通信及基本信息
cluster glue                 中間層負責調度,包括兩個模塊:本地資源管理和stonith

resource agents       資源代理層         

實現各種資源的啓動、停止、監控等

(pacemaker)資料待補充!


生產場景(主要是爲了解決單點):

        1、四層:前端負載均衡器,配合lvs (keeplived有區別的)。

              注意是:hearbeat +lvs + ldirectord(健康檢查)

        2、七層:配合haporxy、nginx,負載ip漂移!

        3、配合數據庫主庫的高可用。

        4、存儲的高可用,比如nfs網絡文件存儲系統。

        5、單點的分佈式文件系統。


實驗準備: 虛擬機兩臺;配置各自的vip ;(虛擬網卡模擬直連)

                   網卡三塊:eth0 外網  eth1 內網管理ip  eth2 用於服務器心跳 ;vip 應用程序掛載服務。

                   配置hosts,ping 測試;

                   添加心跳路由: route add -host 10.0.10.22 dev eth2

                 提示:防火牆一定要關閉,成敗關鍵!


安裝:

1、下載軟件包:


      提示:普通的yum源無此軟件

使用epel源安裝:

wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm   #注意epel源使用和系統相同版本

rpm -qa |grep epel

安裝heartbeat
yum install heartbeat* -y

提示:

yum 源跟新網址:http://mirrors.aliyun.com/help/centos

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

yum緩存保留修改設置:

sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf


2、安裝檢查rpm -aq heartbeat
3、啓動文件

/etc/init.d/heartbeat       #腳本文件

4、配置目錄

/etc/ha.d/

5、服務資源

     控制目錄

/etc/ha.d/resource.d/       #可以放到init.d

(腳本文件)

6、 核心配置 文件

ha.cf (參數配置文件) :基本參數
authkey(認證文件)     :高可用服務器之間根據對端的authkey,對對端認證
harresource(資源配置文件):配置啓動ip資源及腳本程序,服務等

提示:配置文件模版 路徑:   /usr/share/doc/heartbeat-3.0.4/                                              # 文件包括:haresources、ha.cf、authkeys


配置文件ha.cf配置 說明:

生產配置範例(/etc/ha.d/ha.cf):

#the start by kong 2015/7/5 
debugfile /var/log/ha-debug
logfile/var/log/ha-log
logfacilitylocal1
keepalive 2
deadtime 30
warntime 10
initdead 60
#bcasteth1
mcast eth2 225.0.0.7 694 1 0
auto_failback on
node A
node B
crmno
#the end by kong

#提示兩臺主機heartbaet 配置時相同的


debugfile /var/log/ha-debug

heartbeat 調試日誌存放位置       #24 行
logfile /var/log/ha-log普通log                                         # 29 行
logfacility local0在syslog服務中配置通過locall設備接收日誌      #34 行

keepalive  2

(心跳間隔時間)

指定心跳間隔時間爲2秒(即每2秒在eth1上發一次廣播)   # 48 行

deadtime  30

(宣佈死亡時間)

指定若備用節點在30秒內沒有收到主節點的心跳信號,則立即接管主節點的資源服務                             # 56 行

wamtime  10

(警告延遲時間)

指定心跳延遲的時間爲10秒。當10秒鐘內備份節點不能接收到主節點的心跳信號時,就會往日誌中寫入一個警告日誌,但此時不會切換服務

initdead    120

(初始化死亡時間)

指定在 HEARTBEAT 首次運行後,需要等待120秒才啓動主服務器的任何資源。該選項用於解決這種情況產生的時間間隔。取值至少

爲deadtime的兩倍。單機啓動時會遇到vip綁定慢,爲正常現象。該值設置長的原因。

#bcast eth1

(廣播方式)

指明心跳使用以太網廣播方式在eth1接口上進行廣播。如使用兩個實際網絡傳送心跳則 #bcast eth0 eth1

mcast eth2  255.0.0.1 694 1 0   (多播)

設置廣播通信使用的端口,694 爲默認使用端口 ;

   eth2 設備

   255.0.0.1 地址

auto failback on#用來定義當主節點回復後,是否將服務自動切回。 |建議人工
node  hostname#主節點主機名 。使用uname -n 查看
node  hostname2#備用節點主機名。
crm no是否開啓集羣資源管理功能


配置文件/etc/ha.d/authkeys  配置說明:

#如下爲默認配置文件

#

#Authentication file.  Must be mode 600

#       提示:authkey權限必須爲600

#

#Must have exactly one auth directive at the front.

#authsend authentication using this method-id

#

#Then, list the method and key that go with that method-id

#

#Available methods: crc sha1, md5.  Crc doesn't need/want a key.

#       提示:可以設置的認證方法 ,總計有三類

#You normally only have one authentication method-id listed in this file

#

#Put more than one to make a smooth transition when changing auth

#methods and/or keys.

#

#

#sha1 is believed to be the "best", md5 next best.

#       提示:sha1的方式是最好的

#crc adds no security, except from packet corruption.

#Use only on physically secure networks.

#

#auth 1

#1 crc

#2 sha1 HI!

#3 md5 Hello!

#默認是crc方法,這是不加密的,不夠安全

生成方法:

[root@B ha.d]# echo kong|sha1sum     # 用的sha1

5e1d19b4602d90f43ab23a1470bb3d3a8939799a  -

編輯配置文件:

提示:兩臺機器配置相同

[root@A ha.d]# cat authkeys 

auth 1

1 sha1 5e1d19b4602d90f43ab23a1470bb3d3a8939799a

[root@A ha.d]# chmod 600 authkeys 


配置文件/etc/ha.d/haresource  配置說明(兩臺配置相同):

生產配置

   範例:

[root@A ha.d]# cat haresources 
#kong services
A   IPaddr::10.0.0.18/24/eth0
B   IPaddr::10.0.0.19/24/eth0


 #A 爲主機名,表示初始狀態會在  A  綁定ip 10.0.0.17
#IPaddr爲heartbeat 配置ip的默認腳本,其後的ip等都是腳本的參數
 #10.0.0.17/24 eth0

#爲集羣對外服務的vip,初始啓動在A 上;

#24爲子網掩碼;

#eth0爲ip綁定的實際物理網卡,爲heartbeat提供對外服務的通信接口

           更多說明:

來自 Mysql+drdb+Heartbeat 文檔


  wKiom1WZTFvBlINiAAONLLuubpw543.jpg

文件分析

haresource:

data-1-2 kong::test abc:test:ab   shipeng

分析:data-1-2 優先啓動腳本:

/etc/ha.d/resource.d/kong test start

/etc/ha.d/resource.d/abc test ab start

/etc/ha.d/resource.d/shipeng start

放到haresource下面的內容都要支持 /etc/ha.d/resource.d/shipeng start/stop這樣的控制模式。



啓動服務

[root@A ha.d]# /etc/init.d/heartbeat  strat 
Usage: /etc/init.d/heartbeat {start|stop|status|restart|reload|force-reload}
[root@A ha.d]# /etc/init.d/heartbeat  start
Starting High-Availability services: INFO:  Resource is stopped
INFO:  Resource is stopped
Done.

服務器 A :


vip檢查:

[root@A ha.d]# ip addr |grep -E "10.0.0.19|10.0.0.18"
    inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0


服務器 B :

[root@B ha.d]# ip a|grep -E "10.0.0.18|10.0.0.19"
    inet 10.0.0.19/24 brd 10.0.0.255 scope global secondary eth0


關停其中一臺(B):

vip檢查:

[root@A ha.d]# ip addr |grep -E "10.0.0.19|10.0.0.18"
    inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0
    inet 10.0.0.19/24 brd 10.0.0.255 scope global secondary eth0


提示:防火牆切記關閉





















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