Apache+heartbeat HA方案

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
[url]http://www.linux-ha.org/download/[/url]   #此處爲ha下載有各種系統安裝包
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、配置文件

1copy 配置文件

cp /usr/share/doc/heartbeat-2.0.8/{ha.cf,haresources,authkeys} /etc/ha.d/
ha.cf :主要配置文檔
haresources :資源文檔,包括heartbeat服務啓動時使用的資源。
   authkeys :安全驗證
2、文件配置

   以下文件配置在masterslave下都一樣
1/etc/hosts   寫完保存自動生效。
192.168.58.101 ha01
192.168.58.102 ha02
   2ha.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
   3haresources
   ha01 IPaddr::192.168.58.100 httpd
4authkeys
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!
驗證等級,由低到高!!!
3、注意事項

1Master先啓動後,再啓動slave,否則直接執行failover了。
2service heartbeat start
Starting High-Availability services:
2009/02/12_23:57:57 INFO:  Resource is stopped
[  OK  ]
表明heartbeat正常運行。
4、測試

  1ping ha01 ha02
   PING ha01 (192.168.58.101) 56(84) bytes of data.
   PING ha02 (192.168.58.102) 56(84) bytes of data.
3)切換測試
ha01正常
測試命令
ha01
ha02
  ifconfig  
eth00 192.168.58.100
eth00
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.100192.168.58.101正常
 
ha01宕機
測試命令
ha01
ha02
  ifconfig  
eth00
eth00 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.100192.168.58.102正常
ha01恢復
測試命令
ha01
ha02
  ifconfig  
eth00 192.168.58.100
eth00
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.100192.168.58.101正常

 

由於設備簡陋只能人工估計。多次中斷測試初步估計主機備機切換時間不足30
4107斷網測試
中斷107網段網線
測試命令
ha01
ha02
  ifconfig  
eth00 192.168.58.100
ps aux|grep heartbeat
master control process
FIFO reader
write: bcast eth1
read: bcast eth1
ps aux |grep httpd
httpd服務
Ping 192.168.58.100
不通超時
Web能同時打開 192.168.58.100192.168.58.101192.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網段恢復時,正常。
558.101斷網測試
中斷58.101網線
測試命令
ha01
ha02
  ifconfig  
eth00 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都打不開
解決方案一:
masterha01eth0網口才用bond技術,兩個或兩個以上網卡虛擬出一個網卡。
優點:
1、提高mastereth0bond0)端口帶寬(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
修改後
Masterucast eth0 192.168.58.102
Slaveucast 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、數據存儲

   1nfs共享存儲
      添加一臺NFS服務器來存儲網站內容
2、  drbd備份存儲

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2009-2-14

清蒸

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