Heartbeat+ipvsadm+ldirectord组建linux高可用集群
Heartbeat+ipvsadm+ldirectord組建linux高可用集群
1. 系統(tǒng)環(huán)境:
RHEL6,組建選擇base--默認(rèn),developmenttools—選擇所有可選包。
對外虛擬IP:192.168.50.179
網(wǎng)關(guān):192.168.50.254
負(fù)載節(jié)點:(eth0為外網(wǎng)卡)master-192.168.50.170
負(fù)載心跳:(eth1為心跳檢查)192.168.94.10
備用節(jié)點:(eth0為外網(wǎng)卡)backup-192.168.50.171
備用節(jié)點心跳:(eth1為心跳檢查)192.168.94.11
真實節(jié)點1:rs1-192.168.50.172
真實節(jié)點2:rs2-192.168.50.173
確保hostname==uname –n
編輯各機(jī)器/etc/hosts 文件,添加解析:
192.168.50.170 master
192.168.50.171 backup
192.168.50.172 rs1
192.168.50.173rs2
2.所需軟件
Heartbeat2.1.3,ipvsadm1.24
安裝heartbeat時需要:
Libnet ?(此包系統(tǒng)中未包含需要下載,我下載的是libnet-1.1.5.tar.gz)
glib2-devel (系統(tǒng)自帶)
libxml2-devel (系統(tǒng)自帶)
bzip2-devel (系統(tǒng)自帶)
Ldirector服務(wù)需要的依賴幾個perl包(CPAN下載):
Socket6-0.23.tar.gz
IO-Socket-INET6-2.65.tar.gz
MailTools-1.74.tar.gz
依次安裝以上各包以后應(yīng)該可以安裝heartbeat了。官網(wǎng)最新版的heartbeat3.0已分成3個組件包,安裝時每個包時都需要去INTERNET驗證大量XML文件,耗費的時間驚人,依賴包也比較多。Heartbeat2.1.4版本在rhe6上安裝時需要大量依賴包,而且make install時報錯,在網(wǎng)上也沒找到相關(guān)的解決方案,所以退而求其次選擇了heartbeat2.1.3版,此版安裝時比較順利,下面記錄了我的安裝過程。其中大部分配置都能從網(wǎng)上找到,我也只是借來用的,此文檔的目的只是自己備忘,以及提示一下在安裝過程中和我有同樣錯誤的菜鳥們。涉及到版權(quán)問題還請見諒。并給我留言。
3.安裝ipvsadm
#ln -s/usr/src/kernels/`uname -r` /usr/src/linux
#tar zxvfipvsadm-1.24.tar.gz
#cdipvsadm-1.24
#make;make install
---------------------------------------------------------------------------------------------------------------------------
4. 安裝heartbeat
[root@mastersrc]# tar zxvf heartbeat-2.1.3.tar.gz
[root@mastersrc]# cd heartbeat-2.1.3
[root@masterheartbeat-2.1.3]# ./ConfigureMe configure
[root@masterheartbeat-2.1.3]#groupadd haclient
[root@masterheartbeat-2.1.3]#useradd -g haclient hacluster
[root@masterheartbeat-2.1.3]#./ConfigureMe make --enable-fatal-warnings=no
[root@masterheartbeat-2.1.3]#make install
[root@masterheartbeat-2.1.3]#cp doc/{authkeys,haresources,ha.cf} /etc/ha.d/
[root@master heartbeat-2.1.3]#cp ldirectord/ldirectord.cf /etc/ha.d/
配置heartbeat
-------------------------------------------------------------------------------------
(1)編輯authkeys文件:
[root@master heartbeat-2.1.3]# sed -e /^#/d /etc/ha.d/authkeys
auth 3
3 md5 Hello!
[root@masterheartbeat-2.1.3]#chmod 600 /etc/ha.d/authkeys
--------------------------------------------------------------------------------------
(2)編輯ha.cf文件:
[root@master heartbeat-2.1.3]# sed -e /^#/d /etc/ha.d/ha.cf
debugfile/var/log/ha-debug
logfile/var/log/ha-log
logfacility ? ? local0
keepalive 2
deadtime 5
initdead 15 ? #此數(shù)值大于等于deadtime的兩倍
udpport 694
ucast eth1192.168.94.11
auto_failback on ? #負(fù)載節(jié)點重新恢復(fù)正常后從備用節(jié)點自動接管
node ? ?master
node ? ?backup
crm no ? ?#禁用crm
-----------------------------------------------------------------------------------------
(3)編輯haresources文件
[root@masterheartbeat-2.1.3]# sed -e /^#/d /etc/ha.d/haresources
master 192.168.50.179 cluster ldirectord
#負(fù)載節(jié)點主機(jī)名 虛擬IP地址 要有heartbeat管理的程序
---------------------------------------------------------------------------------------------------------------------------
(4)編輯ldirectord文件
[root@masterheartbeat-2.1.3]# sed -e /^#/d /etc/ha.d/ldirectord.cf
checktimeout=3
checkinterval=1
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
quiescent=no ?#自動刪除down掉的真實節(jié)點
virtual=192.168.50.179:80
? ? ? ? ? ? ? ?real=192.168.50.172:80 gate
? ? ? ? ? ? ? ?real=192.168.50.173:80 gate ?#此項在有更多真實節(jié)點時自由添加
? ? ? ? ? ? ? ?fallback=127.0.0.1:80 gate
? ? ? ? ? ? ? ?service=http
? ? ? ? ? ? ? ?scheduler=rr
? ? ? ? ? ? ? ?#persistent=600
? ? ? ? ? ? ? ?#netmask=255.255.255.255
? ? ? ? ? ? ? ?protocol=tcp
? ? ? ? ? ? ? ?checktype=negotiate
? ? ? ? ? ? ? ?checkport=80
? ? ? ? ? ? ? ?request="index.html" ? #向真實服務(wù)器請求的網(wǎng)頁文件名
? ? ? ? ? ? ? ?receive="Test Page" ? ?#從真實服務(wù)器返回的網(wǎng)頁內(nèi)容,當(dāng)檢測不到此網(wǎng)頁文件或返回的內(nèi)容不正確時即認(rèn)為真實 節(jié)點down掉
? ? ? ? ? ? ? ?#virtualhost=www.x.y.z
(5)編輯cluster腳本文件(此腳本要放在/etc/init.d)下
[root@masterheartbeat-2.1.3]# vi /etc/init.d/cluster
#!/bin/bash
#description:start LVS of DirectorServer
#Writtenby qiu
# define used ip.
GW=192.168.50.254
VIP=192.168.50.179
RIP1=192.168.50.172
RIP2=192.168.50.173
./etc/rc.d/init.d/functions
case"$1" in
start)
#Clear all ipvsadmrules.
/sbin/ipvsadm -C
#set lvs vip fordr
/sbin/ipvsadm--set 30 5 60
/sbin/ifconfigeth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add-host $VIP dev eth0:0
/sbin/ipvsadm -A-t $VIP:80 -s rr -p 3 ?#-p選項設(shè)置session保持時間
/sbin/ipvsadm -a-t $VIP:80 -r $WEB_RIP1:80 -g -w 1
/sbin/ipvsadm -a-t $WEB_VIP:80 -r $RIP2:80 -g -w 1
touch/var/lock/subsys/ipvsadm > /dev/null 2>&1
# set Arp 當(dāng)一臺VS接管LVS服務(wù)時,可能會網(wǎng)絡(luò)不通,這是因為路由器的MAC緩存表里無法及時刷新MAC.關(guān)于vip這個地址的MAC地址還是替換的VS的MAC,解決方法是使用arping命令.
/sbin/arping -Ieth0 -c 5 -s $VIP $GW > /dev/null 2>&1
;;
stop)
/sbin/ipvsadm -C
/sbin/ipvsadm -Z
ifconfig eth0:0down
route del $VIP
rm -rf /var/lock/subsys/ipvsadm> /dev/null 2>&1
/sbin/arping -Ieth0 -c 5 -s $VIP $GW
echo "ipvsadmstoped"
;;
status)
if [ ! -e/var/lock/subsys/ipvsadm ];then
echo "ipvsadmis stoped"
status)
if [ ! -e/var/lock/subsys/ipvsadm ];then
echo "ipvsadmis stoped"
exit 1
else
ipvsadm -ln
echo"..........ipvsadm is OK."
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage:$0{start|stop|restart|status}"
exit 1
esac
exit 0
[root@masterheartbeat-2.1.3]#chmod 755 /etc/init.d/cluster
[root@masterheartbeat-2.1.3]#chkconfig -add heartbeat
至此負(fù)載節(jié)點已經(jīng)安裝配置完畢,把一下文件拷貝到相應(yīng)備用節(jié)點的目錄:
authkeys,ha.cf,haresources,ldirectord.cf,cluster
備用幾點只需要改動ha.cf文件中 “ucast eth1 192.168.94.11”中的ip地址為負(fù)載節(jié)點的eth1所對應(yīng)的ip即可。其他配置完全相同。
5.真實節(jié)點的相關(guān)操作
(1)在真實節(jié)點上安裝lamp環(huán)境,或者其他應(yīng)用程序,在制定存放網(wǎng)頁的目錄建立index.html文件,確保內(nèi)容為“Test Page”
(2)在/etc/init.d下建立腳本文件:
#cat /etc/init.d/lvs_rs
#!/bin/sh
# chkconfig: 234572 08
# description:Config realserver lo:0 port and apply arp patch
VIP=192.168.50.179
./etc/rc.d/init.d/functions
case $1 in
? ? ? ? ? ?start)
? ? ? ? ? ?echo "lo:0 port starting"
? ? ? ? ? ?echo "0">/proc/sys/net/ipv4/ip_forward
? ? ? ? ? ?/sbin/ifconfig lo:0 $VIP broadcast $VIPnetmask 255.255.255.255 up
? ? ? ? ? ?/sbin/route add -host $VIP dev lo:0
? ? ? ? ? ?echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
? ? ? ? ? ?echo"2" > /proc/sys/net/ipv4/conf/lo/arp_announce
? ? ? ? ? ?echo"1" > /proc/sys/net/ipv4/conf/all/arp_ignore
? ? ? ? ? ?echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
? ? ? ? ? ?sysctl -p
? ? ? ? ? ?;;
? ? ? ? ? ?stop)
? ? ? ? ? ?echo "lo:0 port closing"
? ? ? ? ? ?ifconfig lo:0 down
? ? ? ? ? ?echo "1" > /proc/sys/net/ipv4/ip_forward
? ? ? ? ? ?echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
? ? ? ? ? ?;;
? ? ? ? ? ?*)
? ? ? ? ? ?echo "Usage: $0 {start|stop}"
? ? ? ? ? ?exit 1
esac
添加為系統(tǒng)啟動服務(wù):
#chkconfig –add lvs_rs
#chkconfig –level345 on
6.測試
在負(fù)載節(jié)點上運行 ?watch ipvsadm -ln ?命令,此命令現(xiàn)實lvs的轉(zhuǎn)發(fā)列表。
交替停掉或者全部停掉兩臺真實節(jié)點上的httpd服務(wù),查看轉(zhuǎn)發(fā)列表的變化。
停掉負(fù)載節(jié)點,查看備用節(jié)點是否接管任務(wù)。訪問虛擬IP看是否能訪問到兩臺真實節(jié)點的web服務(wù)。
7.維護(hù)
主要是查看 /var/log/messages;/var/log/ha-log;/var/log/ldirectord.log 中相關(guān)的日志信息做出調(diào)整
轉(zhuǎn)載于:https://blog.51cto.com/xiaoo/1209463
總結(jié)
以上是生活随笔為你收集整理的Heartbeat+ipvsadm+ldirectord组建linux高可用集群的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle数据泵导入分区表统计信息报错
- 下一篇: linux 其他常用命令