Apache+heartbeat HA方案
主從熱備,當master 宕機自動切換到slave提供服務,直到master恢復後自動切換到master提供服務。
1、系統環境
Master: ha01
eth0:192.168.58.101
eth1:192.168.107.101
Slave: ha02
eth0:192.168.58.102
eth1:192.168.107.102
Virual IP :192.168.58.100
Httpd 安裝系統時選擇安裝
Heartbeat:
libnet:
2、軟件安裝
1)用tar安裝
tar xvf /mnt/libnet.tar.gz -C /usr/src/ ①
tar xvf /mnt/heartbeat-2.0.8.tar.gz -C /usr/src
cd /usr/src/libnet/
./configure &&make &&make install
cd ../heartbeat-2.0.8
./ConfigureMe configure &&make&&make install
groupadd -g 694 haclient
useradd -u 694 -g haclient hacluster
沒有以上用戶名啓動服務會報錯:
heartbeat[19932]: 2009/02/12_20:31:07 ERROR: Invalid user id name [hacluster]
*********************************①********************************************
好奇害死貓!!
以下爲不裝libnet先裝heartbeat時報錯信息:
./ConfigureMe configure
configure: error: The following required components noted earlier are missing: libnet
*******************************************************************************
2)用rpm安裝
heartbeat-pils-2.1.3-3.el5.centos.i386.rpm
heartbeat-stonith-2.1.3-3.el5.centos.i386.rpm ②
heartbeat-2.1.3-3.el5.centos.i386.rpm
**********************************②*******************************************
Cluster.pdf P12
Node fencing – STONITH
*******************************************************************************
chkconfig –add heartbeat
chkconfig heartbeat on
chkconfig httpd off
3、配置文件
1、copy 配置文件
cp /usr/share/doc/heartbeat-2.0.8/{ha.cf,haresources,authkeys} /etc/ha.d/
ha.cf :主要配置文檔
haresources :資源文檔,包括heartbeat服務啓動時使用的資源。
authkeys :安全驗證
2、文件配置
以下文件配置在master、slave下都一樣
1)/etc/hosts 寫完保存自動生效。
192.168.58.101 ha01
192.168.58.102 ha02
2)ha.cf
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 5
warntime 3
initdead 10
udpport 694
bcast eth1 # Linux
auto_failback on
watchdog /dev/watchdog
node ha01
node ha02
3)haresources
ha01 IPaddr::192.168.58.100 httpd
4)authkeys
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!
驗證等級,由低到高!!!
3、注意事項
1)Master先啓動後,再啓動slave,否則直接執行failover了。
2)service heartbeat start
Starting High-Availability services:
2009/02/12_23:57:57 INFO: Resource is stopped
[ OK ]
表明heartbeat正常運行。
4、測試
1)ping ha01 ha02
3)切換測試
ha01正常 | ||
測試命令 |
ha01 |
ha02 |
ifconfig |
eth0:0 192.168.58.100 |
無eth0:0 |
ps aux|grep heartbeat |
master control process
FIFO reader
write: bcast eth1
read: bcast eth1 | |
ps aux |grep httpd |
有httpd服務 |
無httpd服務 |
web打開192.168.58.100、192.168.58.101正常
ha01宕機 | ||
測試命令 |
ha01 |
ha02 |
ifconfig |
無eth0:0 |
eth0:0 192.168.58.100 |
ps aux|grep heartbeat |
master control process
FIFO reader
write: bcast eth1
read: bcast eth1 | |
ps aux |grep httpd |
有httpd服務 |
有httpd服務 |
web打開192.168.58.100、192.168.58.102正常
ha01恢復 | ||
測試命令 |
ha01 |
ha02 |
ifconfig |
eth0:0 192.168.58.100 |
無eth0:0 |
ps aux|grep heartbeat |
master control process
FIFO reader
write: bcast eth1
read: bcast eth1 | |
ps aux |grep httpd |
有httpd服務 |
無httpd服務 |
web打開192.168.58.100、192.168.58.101正常
由於設備簡陋只能人工估計。多次中斷測試初步估計主機備機切換時間不足30秒
4)107斷網測試
中斷107網段網線 | ||
測試命令 |
ha01 |
ha02 |
ifconfig |
有eth0:0 192.168.58.100 | |
ps aux|grep heartbeat |
master control process
FIFO reader
write: bcast eth1
read: bcast eth1 | |
ps aux |grep httpd |
有httpd服務 | |
|
不通超時 |
Web能同時打開 192.168.58.100、192.168.58.101、192.168.58.102
第三方機器測試:
ping 192.168.58.100 通
arp –a 查看mac地址
Interface: 192.168.58.1 --- 0x2
Internet Address Physical Address Type
192.168.58.100 00-0c-29-a5-e7-a4 dynamic
192.168.58.101 00-0c-29-a5-e7-a4 dynamic
192.168.58.102 00-0c-29-ec-f2-1f dynamic
107網段恢復時,正常。
5)58.101斷網測試
中斷58.101網線 | ||
測試命令 |
ha01 |
ha02 |
ifconfig |
eth0:0 192.168.58.100 | |
ps aux|grep heartbeat |
master control process
FIFO reader
write: bcast eth1
read: bcast eth1 | |
ps aux |grep httpd |
有httpd服務 |
無httpd服務 |
Web都打不開
解決方案一:
在master(ha01)eth0網口才用bond技術,兩個或兩個以上網卡虛擬出一個網卡。
優點:
1、提高master的eth0(bond0)端口帶寬(N*100M),提高端口一的數據吞吐能力
2、假設單網卡全年故障時間是1天,哪麼兩個或兩個以上網卡的故障時間是1/(N*365)天,大大降低故障出現率。
缺點:
1、 需要添置新的硬件,增加成本(一張網卡不到100元)。
Bond綁定網卡請參見bond文檔。
解決方案2:(測試)
修改ha.cf配置文檔,將bcast改爲eth0
cat /etc/ha.d/ha.cf |grep -v "^#" 查看bcast
bcast eth1 # Linux
修改後
Master:ucast eth0 192.168.58.102
Slave:ucast eth0 192.168.58.101
查看107網段數據包:
tcpdump -i eth1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
0 packets captured
0 packets received by filter
0 packets dropped by kernel
說明心跳已經修改到eth0端口。
tcpdump -i eth0 >log
01:03:54.007087 IP ha02.32780 > ha01.ha-cluster: UDP, length 167
01:03:55.924565 IP ha01.32781 > ha02.ha-cluster: UDP, length 167
01:03:56.055518 IP ha02.32780 > ha01.ha-cluster: UDP, length 167
01:03:57.928805 IP ha01.32781 > ha02.ha-cluster: UDP, length 167
01:03:58.083680 IP ha02.32780 > ha01.ha-cluster: UDP, length 167
優點:
1、 不需要添加新網卡,可以直接將機器上的雙網卡綁定。
缺點:
1、 eth0端口數據通信量過大,在服務器訪問量增大時,會降低訪問速度。
2、 在58網段容易造成數據衝突,增加交換機負擔
5、數據存儲
1、nfs共享存儲
添加一臺NFS服務器來存儲網站內容
2、 drbd備份存儲
2009-2-14
清蒸