LVS的DR模型+NAS
<a href="http://blog.51cto.com/attachment/201212/160314830.png" target="_blank"></a>
在上圖的DR模型中,所有機器(包括Director)都配置了一個額外的IP位址,即vip
該模型需要解決一下幾個問題
1、當一個客戶client上VIP發去一個連接配接請求是,此請求必須要連接配接到Director的VIP上,而不是real server上的lo:0的,因為LVS主要目的就是要Director負責排程這些連接配接請求到real server上,是以到ARP廣播請求時,僅将Director的MAC位址響應給client就可以了。
解決此問題,
(1)可以再路由器上做靜态的mac-ip綁定、或arp位址過濾。
(2)在本地的linux主機上通過arp_ignore、arp_announce來解決。
在這我們就用第二種方法來解決。
關于arp_ignore、arp_announce在linux的2.4和2.6的版本中以引入。
Arp_announce --arp宣告 有3個值
0 - (default) Use any local address, configured on any interface.
1 - Try to avoid local addresses that are not in the target's subnet for this interface.
2 - Always use the best local address for this target. --自己與arp請求的目标ip位址不符,不回答。
Arp_ignore --arp忽略 有8個值
0 - (default): reply for any local target IP address, configured on any interface.
1 - reply only if the target IP address is local address configured on the incoming interface. --僅響應與本地的進接口一緻的請求
2 - reply only if the target IP address is local address configured on the incoming interface and both with the sender's IP address are part from same subnet on this interface.
3 - do not reply for local address configured with scope host,only resolutions for golbal and link addresses are replied.
4-7 - reserved
8 - do not reply for all local addresses
2、real server必須要有與director的VIP一樣的ip位址,即可以配置Looback位址
3、Real server 必須要有到client的路由
下面就用上面的模型圖做一個web服務的例子,具體配置一下。
1、Director上的配置
配置eth0:0的ip
<a href="http://blog.51cto.com/attachment/201212/160333424.png" target="_blank"></a>
安裝ipvsadm
yum -y install ipvsadm
添加規則使Director成為虛拟的web服務
Ipvsadm -A -t 192.168.2.1:80 -s rr
指明後方的real server
Ipvsadm -a -t 192.168.2.1:80 -r 192.168.2.100 -g (預設就是-g 即DR)
Ipvsadm -a -t 192.168.2.1:80 -r 192.168.2.200 -g
service ipvsadm save
service ipvsadm start
chkconfig ipvsadm on
2、real server的配置
Real server 的lo:0接口ip的配置
先看一下arp的那兩個參數
sysctl -a |grep arp 預設都是0
net.ipv4.conf.eth0.arp_ignore = 0
net.ipv4.conf.eth0.arp_announce = 0
設定它們的值如下:
echo "net.ipv4.conf.eth0.arp_ignore = 1" >>/etc/sysctl.conf
echo "net.ipv4.conf.eth0.arp_announce = 2" >>/etc/sysctl.conf
sysctl -p --立即生效 下面配置lo:0 的ip
<a href="http://blog.51cto.com/attachment/201212/160355343.png" target="_blank"></a>
掩碼是4個255
server1和server2一樣
你可以cp server1
scp 192.168.2.100:/etc/sysctl.conf /etc/
3、配置server1和server2的路由
route add -host 192.168.2.1 dev lo:0
4、搭建Server1和server2的web服務
這裡就不寫了
當客戶機client通路VIP是,每重新整理一次就會在server1和server2之間輪詢,這在實際應用中對于靜态的網站不會出現什麼問題,但當時動态網站時,如你注冊了一個賬号儲存到了server1上了,當你重新整理時你連接配接到了server2上,但是server2上可沒有儲存你的注冊資訊呀,怎樣解決這個問題呢,需要共享存儲了。我們先看看先下面的NAS吧。。
<a href="http://baike.baidu.com/picview/2679515/2679515/0/f35ea009737def736b60fbd2.html"></a>
<a href="http://baike.baidu.com/picview/2679515/2679515/0/f35ea009737def736b60fbd2.html"> </a>
NAS網絡存儲是檔案級别的共享存儲,可以通過檔案共享協定SAMBA、NFS來實作。
假如有一台共享存儲伺服器,它的ip為192.168.2.2 我們可以共享檔案夾在本地,server1和server2通過磁盤映射将共享檔案夾挂載到/var/ww/html/下,在共享檔案夾下存放我們的動态網站不就可以了。你也可以設定成自動挂載。。。。!!!
關于NFS的配置和自動挂載,這裡我就不寫了,可以參考
本文轉自 abc16810 51CTO部落格,原文連結:http://blog.51cto.com/abc16810/1104029