一、概述:
系統:Centos5.0
叢集軟體:Heartbeat
節點1IP(
主
):192.168.1.105
節點2IP(
從
):192.168.1.106
virtual IP:192.168.1.102
在節點1
上使用
uname -n
結果必須是
node01
,在節點
2
上同樣使用
uname -n
結果也必須是
node02
。
IP 192.168.1.102
是一個虛擬
IP
用來供
webserver
使用的。
二、下載安裝軟體包和配置:
1、需要以下軟體包:
heartbeat-2.1.2
heartbeat-2.1.2
heartbeat-stonith-2.1.2
也可以使用yum -y install heartbeat
來進行安裝,附件為所需要的軟體包:
檔案:
heartbeat.rar 大小
: 2627KB
下載
:
下載
2、在每個節點上配置
heartbeat
,需要有以下三個檔案
:
authkeys、
ha.cf
、
haresources
,它們存在於
/etc/ha.d/
目錄裡。
3、建立以上提到的三個檔案:
cp /usr/share/doc/heartbeat-2.1.2/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/haresources /etc/ha.d/
4、配置:
4.1、首先編輯
authkeys
檔案
:
vi /etc/ha.d/authkeys
添加以下行:在這裡我們使用的是第二種認證方式(shal)
auth 2
2 sha1 test-ha
接著把檔案的許可權改為600
:
chmod 600 /etc/ha.d/authkeys
4.2、編輯
/etc/ha.d/ha.cf
檔案
:
vi /etc/ha.d/ha.cf加入如下行:
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node node01
node node02
4.3、編輯
/etc/ha.d/haresources
檔案:
這個檔案中包含了使那個服務具有高可用性,在這裡我們使用的是httpd;
vi /etc/ha.d/haresources加入下行:
node01 172.16.4.82 httpd
4.4、我們把
node01
上的
/etc/ha.d/
目錄複寫到節點
node02
上的
/etc
目錄裡。
scp -r /etc/ha.d/ 192.168.102.X:/
4.5、在
httpd.conf
檔案裡我們添加如下行:
vi /etc/httpd/conf/httpd.conf
Listen 192.168.1.102:80
4.6、把節點
node01
上的
/etc/httpd/conf/httpd.conf
檔案複製到節點
node02
相應的目錄裡:
scp /etc/httpd/conf/httpd.conf 192.168.102.X:/
4.7、在兩個節點上分別建立一個
index
檔案來進行測試:
在node01
上:
echo "node01 apache test server" > /var/www/html/index.html
在node02
上:
echo "node02 apache test server" > /var/www/html/index.html
4.8、在兩個節點上分別啟動
heartbeat:
/etc/init.d/heartbeat start
4.9、在
node01
上,開啟一個瀏覽器:輸入
http://192.168.1.102
並斷行符號,將會看到
node01 apache test server
4.10、停止
node01
上的
heartbeat
進程,然後
在
瀏覽器裡輸入http://192.168.1.102
並斷行符號,將會看到
node02 apache test server.
三、補充:
這裡不需要建立一個虛擬網路介面和配置一個IP
(
192.168.1.102
)給它,因為
heartbeat
會協助我們來完成的,並啟動
httpd server
。