前言:
實驗環境:
1,配置主負載均衡器ubserver1:
(1)安裝Ldirectord軟體包
#sudo apt-get install ldirectord
#sudo cp /usr/share/doc/ldirectord/examples/ldirectord.cf /etc/ha.d
(3)haresources檔案做以下改動
ubserver1 192.168.3.100 lvs.sh 改為
ubserver1 192.168.3.100 lvs.sh ldirectord
(4)ldirectord.cf檔案配置:
#sudo vim /etc/ha.d/ldirectord.cf
<a href="http://xuchengji.blog.51cto.com/attachment/201006/15/160472_12765798122iMF.png"></a>
當checktype=negotiate時要求啟用
request=”test.html” #在www伺服器ubserver2,ubserver3的/var/www下建立test.html/頁内容為“work”,這是因為:ldirectord monitors the health of the real servers by periodically requesting a known URL and checking that the response contains an expected response
receive=”work”
當checktype=connect時這兩個配置可以注釋掉因為Connect only attemts to make a TCP/IP connection,我做實驗時,把這兩個注釋掉,發現當一台www伺服器down掉後,是發現不了的,不知道這是為什麼。
<b>checktype = connect</b>|<b>external</b>|<b>negotiate</b>|<b>off</b>|<b>on</b>|<b>ping</b>|<b>checktimeout</b>N
Type of check to perform. Negotiate sends a request and matches a receive string. Connect only attemts to make a TCP/IP connection, thus the request and receive strings may be omitted. If checktype is a number then negotiate and connect is combined so that after each N connect attempts one negotiate attempt is performed. This is useful to check often if a service answers and in much longer intervalls a negotiating check is done. Ping means that ICMP ping will be used to test the availability of real servers. Ping is also used as the connect check for UDP services. Off means no checking will take place and no real or fallback servers will be activated. On means no checking will take place and real servers will always be activated. Default is negotiate.
2,配置從主負載均衡器ubserver5:
與主負載均衡器ubserver1的所做的修改相同。ldirectord.cf配置檔案内容相同。
3,模拟故障:
關掉ubserver2的www服務後與啟有後,用#sudo ipvsadm –L –n 檢視結果
<a href="http://xuchengji.blog.51cto.com/attachment/201006/15/160472_1276579813cCtU.png"></a>
4,用了Ldirectord後,當一台www伺服器down掉後,在用戶端不會出現錯誤頁;如不用,則會。
總結:用lvs+heartbeat+ldirectord感覺要配置的東西的很多,ha.cf,haresources,authkeys,ldirectord.cf四個配置檔案,還要在www伺服器上建立讓ldirectord發現它是否正常的網頁,還要寫LVS的腳本(實驗用的lvs.sh就是)這樣的配置過程給以後的維護帶來困難。網上關于這方面的配置案例很多,都大同小異,一定要親自實驗下,不然不知道到底行不行。過程中會碰到很多問題,解決了就是學習。
本文轉自xcjgutong 51CTO部落格,原文連結:http://blog.51cto.com/xuchengji/333153