所需軟體:
ipvsadm-1.24-10.x86_64.rpm
heartbeat-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-pils-2.1.3-3.el5.centos.x86_64.rpm
heartbeat-stonith-2.1.3-3.el5.centos.x86_64.rpm
PyXML-0.8.4-4.x86_64.rpm
系統環境:
CentOS 5.4 64-bit
HA1 10.0.0.108
HA1 10.0.0.109
web1 10.0.0.110
web2 10.0.0.111
VIP 10.0.0.100
ipvsadm-1.24安裝
rpm -ivh ipvsadm-1.24-10.x86_64.rpm
/sbin/ipvsadm
heartbeat 安裝
rpm -ivh heartbeat-pils-2.1.3-3.el5.centos.x86_64.rpm
rpm -ivh heartbeat-stonith-2.1.3-3.el5.centos.x86_64.rpm
rpm -ivh PyXML-0.8.4-4.x86_64.rpm
rpm -ivh heartbeat-2.1.3-3.el5.centos.x86_6
4.rpm
注:若heartbeat一次未安裝好,再裝一次
rpm -q heartbeat -d #檢視安裝路徑
echo "service heartbeat start" >> /etc/rc.local
配置heartbeat
cd /usr/share/doc/heartbeat-2.1.3/
cp authkeys ha.cf haresources /etc/ha.d/
cd /etc/ha.d
vi authkeys
#去掉注釋 設定校驗模式
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!
echo "10.0.0.108 HA1" >>/etc/hosts
echo "10.0.0.109 HA2" >>/etc/hosts
vi haresources
#添加:(約44行下面)
HA1 10.0.0.100 vip.sh
vi ha.cf
#去掉注釋(約95行)
bcast eth0
#去掉注釋并修改(約125行)
ucast eth0 10.0.0.109
#去掉注釋并修改(約215、216行)
node HA1
node HA2
chmod 600 authkeys
vi /etc/init.d/vip.sh
#/sbin/bash!
ifconfig eth0:0 10.0.0.100 broadcast 10.0.0.100 netmask 255.255.255.255 up
route add -host 10.0.0.100 dev eth0:0
#setup ipvs
ipvsadm -C
ipvsadm -A -t 10.0.0.100:80 -s rr
ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.110 -g
ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.111 -g
ipvsadm
HA2的配置和HA1一樣,可以直接上傳HA1的authkeys ha.cf haresources三個檔案
sftp 10.0.0.108
get authkeys ha.cf haresources
quit
修改HA2中ha.cf裡(約125行)為:
ucast eth0 10.0.0.108
把vip.sh放到LVS伺服器
vi /etc/init.d/vip.sh //放到這裡開機自啟動
chmod 755 /etc/init.d/vip.sh
/etc/init.d/vip.sh
lvs.sh
ifconfig lo:0 10.0.0.100 broadcast 10.0.0.100 netmask 255.255.255.255 up
route add -host 10.0.0.100 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
web1 web2安裝WEB服務
安裝過程略
注:
把lvs.sh放到WEB伺服器
#vi /etc/init.d/lvs.sh #放到這裡開機自啟動
#chmod 755 /etc/init.d/lvs.sh
#/etc/init.d/lvs.sh
得出結論:
不斷重新整理10.0.0.100,會輪流顯示web1和web2頁面
轉載請注明: 轉載自http://www.elain.org
本文轉自 elain2012 51CTO部落格,原文連結:http://blog.51cto.com/elain/669067