LVS快速搭建教程


LVS配置教程

LVS配置教程

作者:oldjiang

一、前言

    相信專程來讀此文的讀者對LVS必然有一定的了解,首先看圖:

 

毋庸置疑,Load Balancer是負載調度器,由它將網絡請求無縫隙調度到真實服務器,至於此集群使用的是哪一種IP負載均衡技術(LVS有三種負載均衡技術,分別是VS/NATVS/TUNVS/DR),暫時不用理會。

觀察此圖,我們知道,LVS與其他基於應用層或基於IP層的負載均衡應用擁有類似的一點:一台及其以上的負載調度器和數台甚至成百上千台真實服務器。

LVS來搭建負載均衡集群,理論上來說,只需要在負載調度器上安裝LVS核心軟件ipvsipvs的功能實現軟件ipvsadm,而真實服務器無需額外安裝軟件。

當前,大部分Linux發行版本已經集成了ipvs,因此我們只需要安裝它的實現軟件ipvsadm即可。

在安裝這個軟件的時候,我們不需要考慮我們將使用哪一種IP負載均衡技術,直接安裝即可。

 

 

二、安裝ipvs

1、檢查Load Balancer服務器是否已支持ipvs

modprobe -l|grep ipvs

若有類似以下輸出,則表示服務器已支持ipvs

若服務器不支持ipvs,則需要手動下載ipvs並編譯安裝,相信你們的Linux版本都已支持ipvs,所以我不在此討論如何在內核安裝ipvs,有興趣的朋友可以關注我的博客,在稍后時間內,我會放出ipvs的編譯安裝方法。

2、檢查是否有必須的依賴包:Kernel-develgccopensslopenssl-develpopt 

rpm -q kernel-devel
rpm -q gcc
rpm -q openssl
rpm -q openssl-devel
rpm -q popt

若有類似以下輸出,則表示服務器已安裝這些依賴包:

    

若服務器輸出package ** is not installed則表示該包未安裝,在安裝光盤找到該rpm文件,並上傳至服務器安裝,不會安裝的讀者請谷歌,網上有詳細教程,我就不在此處獻丑。

3、Load Balancer服務器上安裝ipvsadm

    訪問官網下載ipvsadm軟件:http://www.linuxvirtualserver.org 

很多新人在下載ipvsadm時犯了個小錯誤,直接在官網上下載個最高版本的tar.gz包到服務器上進行安裝,而忽略了官網的說明。

1)、下載ipvsadm之前,先使用以下命令查看當前Load Balancer服務器內核版本:

rpm -q kernel-devel

這是我的輸出:

其中被我手動標注紅色的數字就是我的服務器內核版本,根據這個版本號到官網上下載對應該內核版本的ipvsadm版本。

我的2.6.18對應的ipvsadm版本為1.24,下載ipvsadm-1.24.tar.gz文件,1.251.26需要2.6.28-rc3及其以上的內核版本,請根據你的內核版本下載相應的安裝文件,后續的安裝步驟一致,不用擔心。你也可以選擇下載rpm包進行安裝,在此不做討論。

2)、解壓安裝包。

tar -zxvf ipvsadm-1.24.tar.gz

3)、建立編譯所需要的軟鏈接。

ln -s /usr/src/kernels/2.6.18-164.el5-i686 /usr/src/linux

其中的“/usr/src/kernels/2.6.18-164.el5-i686”是你當前允許內核的所在的位置,“/usr/src/kernels”下可能有多個目錄,請根據你的實際情況修改此命令。

4)、編譯並安裝ipvsadm

進入ipvsadm-1.24所在目錄,執行以下命令:

make && make install

若沒有錯誤提示,則安裝成功,使用ipvsadm命令驗證:

 

 

三、集群部署

在此之前,我們未曾提過LVS提供的三種IP負載均衡技術運用,但是此時我們的負載調度器上的ipvs已經安裝好了。接下來,就是要部署負載均衡環境的時候了,此時我們就需要考慮我們將使用哪一種方案來搭建我們的環境。

不過在實際的生產過程中,使用VS/NAT或者VS/TUN亦或VS/DR,肯定在我們部署網絡環境的時候就考慮到了,只是我為了方便新手更好地理解LVS,才在此處提到這一點。

以下介紹三種調度方式的配置方法。

 

1、使用VS/NAT調度

    首先要考慮,在什么樣的網絡環境下,可以使用NAT方式來搭建負載集群,先來一張官方提供的VS/NAT體系結構圖:

    這幅圖就是VS/NAT的體系結構,NAT本身是一種將私有地址轉換為合法IP地址的一種技術,在VS/NAT結構中,整個集群系統只有一個對外的合法地址,這個IPLoad Balancer上對外可見,其他的真實服務器與這個調度器組成了一個對外不可見的內網,Internet上的用戶訪問集群必須通過集群提供的對外IP訪問調度器,調度器再利用NAT技術,將真實服務器置於網絡上。

形象點比喻,在VS/NAT模式下,調度器就相當於工作在第三層網絡層的路由器(這個比喻可能不太恰當,但是便於理解),路由器有一個WAN口,WAN口提供一個在互聯網上唯一的且合法的IP地址,同樣路由器也有一個LAN口,與局域網中的所有真實服務器連接,真實服務器的網關地址指向路由器的LAN口地址。當用戶訪問路由器時,路由器會更改數據包包頭的目標地址為某個真實服務器中的地址,然后交給該真實服務器處理,當真實服務器處理完畢后,會根據數據包包頭的源地址將數據返回給用戶,但是由於真實服務器使用的是路由器的IP做為網關,所以真實服務器返回的數據必將經過路由器,路由器在接收到數據包后,將數據包包頭的源地址(由真實服務器發出的數據包源地址為真實服務器的內網IP)修改為WAN口地址,然后根據數據包的目標地址再發送給用戶。這種數據傳輸模式也是VS/NAT的數據傳輸模式。

以上的理論知識很重要,如果沒有把VS/NAT的體系結構和網絡模式搞清楚,以下的配置步驟即使搞清楚了,也難以理解其如此配置的原因。

好了,根據以上描述的網絡模型,畫出我的拓撲圖:

Load BalnacerClient在模擬出的外網中,使用同一網段:192.168.1.0-255Load Balancer與兩台真實服務器在同一個局域網中,網段為:10.0.0.0-255

我們可以使用VMware建立三個虛擬主機,全部裝載Linux2.6以上的版本,三台虛擬主機以Bridged(橋接)的方式聯網。其中一台虛擬主機用作Load Balancer,另外兩台用作真實服務器。

1、在Load Balancer上運行以下腳本(Joseph Mack提供)

#!/bin/sh
#------mini-HOWTO-setup-LVS-NAT-director----------
 
#set ip_forward ON for vs-nat director (1 on, 0 off).
cat /proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/ipv4/ip_forward
 
#director is gw for realservers
#turn OFF icmp redirects (1 on, 0 off)
echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects
cat       /proc/sys/net/ipv4/conf/all/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
cat       /proc/sys/net/ipv4/conf/default/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects
cat       /proc/sys/net/ipv4/conf/eth0/send_redirects
 
#setup DIP
/sbin/ifconfig eth0 10.0.0.1 broadcast 10.0.0.255 netmask 255.255.255.0
 
#setup VIP
/sbin/ifconfig eth0:0 192.168.1.11 broadcast 192.168.1.255 netmask 255.255.255.0
 
#set default gateway
/sbin/route add default gw 192.168.1.1 netmask 0.0.0.0 metric 1
 
#clear ipvsadm tables
/sbin/ipvsadm -C
 
#install LVS services with ipvsadm
#add telnet to VIP with rr sheduling
/sbin/ipvsadm -A -t 192.168.1.11:80 -s rr
 
#first realserver
#forward telnet to realserver 10.0.0.2 using LVS-NAT (-m), with weight=1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 10.0.0.2:80 -m -w 1
#check that realserver is reachable from director
ping -c 1 10.0.0.2
#second realserver
#forward telnet to realserver 10.0.0.3 using LVS-NAT (-m), with weight=1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 10.0.0.3:80 -m -w 1
#checking if realserver is reachable from director
ping -c 1 10.0.0.3
 
#list ipvsadm table
/sbin/ipvsadm
#------mini-HOWTO-setup-LVS-NAT-director----------

2、在第一台Real Server上運行以下腳本:

#!/bin/sh
#---------mini-HOWTO-setup-LVS-NAT-realserver-------
#setup IP
/sbin/ifconfig eth0 10.0.0.2 broadcast 10.0.0.255 netmask 255.255.255.0
#installing default gw 10.0.0.1 for vs-nat'
/sbin/route add default gw 10.0.0.1
#show routing table
/bin/netstat -rn
 
#checking if DEFAULT_GW is reachable
ping -c 1 10.0.0.1
 
#looking for VIP on director from realserver
ping -c 1 10.0.0.3
 
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat       /proc/sys/net/ipv4/ip_forward
#---------mini-HOWTO-setup-LVS-NAT-realserver-------

3、在第二台Real Server上運行以下腳本:

#!/bin/sh
#---------mini-HOWTO-setup-LVS-NAT-realserver-------
#setup IP
/sbin/ifconfig eth0 10.0.0.3 broadcast 10.0.0.255 netmask 255.255.255.0
#installing default gw 10.0.0.1 for vs-nat'
/sbin/route add default gw 10.0.0.1
#show routing table
/bin/netstat -rn
 
#checking if DEFAULT_GW is reachable
ping -c 1 10.0.0.1
 
#looking for VIP on director from realserver
ping -c 1 10.0.0.2
 
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat       /proc/sys/net/ipv4/ip_forward
#---------mini-HOWTO-setup-LVS-NAT-realserver-------

 

運行方法如下:

1)、可以用類似lvs_server命名文件,保存至任意位置。

2)、給予該文件執行權限。

chmod +x lvs_server

3)、執行該腳本。

./lvs server

運行完成后,訪問VIP(http://192.168.1.11),查看結果,第一個客戶機顯示:

第二個客戶機顯示:

注意事項: 1、VS/NAT的真實服務器可以使用任何機器,任何操作系統,支持大部分的網絡服務(如:httpd、ftpd、telnetd等等),唯一的要求就是真實服務器必須支持TCP/IP,不過我們可以忽略這樣要求。
2、在VS/NAT模式下,必須打開Load Balancer的ip_forward,關閉ICMP重定向。
3、所有的真實服務器網關地址必須指向到調度器的內網地址。
4、你的真實服務器上必須已部署好http服務器,並為缺省主頁寫入不同的內容以測試調度器調度結果。
5、客戶機和真實服務器在兩個不同的網絡中,理論上也可以在一個網絡中,需要做一些額外的設置。

 

 

2、使用VS/DR調度

首先,我們看一下,VS/DR在什么樣的網絡環境下使用,上圖:

該圖是官方提供的VS/DR體系結構圖,在VS/DR模式下,Load Balancer和所有的Real Server在物理上有一個網卡通過不分斷的局域網相連,調度器和真實服務器必須綁定同一VIP,該VIP在調度器上對外可見,而真實服務器上只需將VIP配置在Non-ARP網絡設備上,它對外不可見,只是用於欺騙真實服務器用於處理目標地址為VIP的網絡請求。真實服務器將請求處理后,直接返回給用戶,不需要在通過調度器返回,所以在VS/DR模式下,真實服務器的網關地址不需要指向調度器。

該原理非常重要,只有理解VS/DR的工作原理,在配置的過程中才能了然於胸,我的敘述太過簡略,若有不理解的地方,請到LVS官方網站查看。

來一個簡單的拓撲圖:

為了簡化模擬過程,所有的機器全部在一個網段下,客戶機的IP192.168.1.10Load Balancer同樣提供一個對外可見的VIP192.168.1.11,其DIP與真實服務器在一個不分段的局域網中,可以使用交換機或者集線器連接,網關全部指向192.168.1.1。當然,你的真實服務器也可以使用其他路由器提供的互聯網服務,只需要把網關指向它即可。

1、在Load Balancer上運行以下腳本(Joseph Mack提供)

#!/bin/bash
#---------------mini-rc.lvs_dr-director------------------------
#set ip_forward OFF for lvs-dr director (1 on, 0 off)
#(there is no forwarding in the conventional sense for LVS-DR)
cat       /proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/ip_forward
 
#director is not gw for realservers: leave icmp redirects on
echo 'setting icmp redirects (1 on, 0 off) '
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
cat       /proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
cat       /proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
cat       /proc/sys/net/ipv4/conf/eth0/send_redirects
 
#setup DIP
/sbin/ifconfig eth0 192.168.1.101 broadcast 192.168.1.255 netmask 255.255.255.0
 
#add ethernet device and routing for VIP 192.168.1.11
/sbin/ifconfig eth0:0 192.168.1.11 broadcast 192.168.1.11 netmask 255.255.255.255
/sbin/route add -host 192.168.1.11 dev eth0:0
#listing ifconfig info for VIP 192.168.1.11
/sbin/ifconfig eth0:0
 
#check VIP 192.168.1.11 is reachable from self (director)
/bin/ping -c 1 192.168.1.11
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
 
#setup_ipvsadm_table
#clear ipvsadm table
/sbin/ipvsadm -C
#installing LVS services with ipvsadm
#add telnet to VIP with round robin scheduling
/sbin/ipvsadm -A -t 192.168.1.11:80 -s rr
 
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 192.168.1.102:80 -g -w 1
#check realserver reachable from director
ping -c 1 192.168.1.102
 
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 192.168.1.103:80 -g -w 1
#check realserver reachable from director
ping -c 1 192.168.1.103
 
#displaying ipvsadm settings
/sbin/ipvsadm
 
#not installing a default gw for LVS_TYPE vs-dr
#---------------mini-rc.lvs_dr-director------------------------

2、在第一台Real Server上運行以下腳本:

#!/bin/bash
#----------mini-rc.lvs_dr-realserver------------------
#setup IP
/sbin/ifconfig eth0 192.168.1.102 broadcast 192.168.1.255 netmask 255.255.255.0
#installing default gw 192.168.1.1 for vs-dr
/sbin/route add default gw 192.168.1.1
#showing routing table
/bin/netstat -rn
#checking if DEFAULT_GW 192.168.1.1 is reachable
ping -c 1 192.168.1.1
 
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat       /proc/sys/net/ipv4/ip_forward
 
#looking for DIP 192.168.1.101
ping -c 1 192.168.1.101
 
#looking for VIP (will be on director)
ping -c 1 192.168.1.11
 
#install_realserver_vip
/sbin/ifconfig lo:0 192.168.1.11 broadcast 192.168.1.11 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig lo:0
#installing route for VIP 192.168.1.11 on device lo:0
/sbin/route add -host 192.168.1.11 dev lo:0
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
 
#hiding interface lo:0, will not arp
echo "1" >/proc/sys/net/ipv4/conf/all/hidden
cat       /proc/sys/net/ipv4/conf/all/hidden
echo "1" >/proc/sys/net/ipv4/conf/lo/hidden
cat       /proc/sys/net/ipv4/conf/lo/hidden
 
#----------mini-rc.lvs_dr-realserver------------------

2、在第二台Real Server上運行以下腳本:

#!/bin/bash
#----------mini-rc.lvs_dr-realserver------------------
#setup IP
/sbin/ifconfig eth0 192.168.1.103 broadcast 192.168.1.255 netmask 255.255.255.0
#installing default gw 192.168.1.1 for vs-dr
/sbin/route add default gw 192.168.1.1
#showing routing table
/bin/netstat -rn
#checking if DEFAULT_GW 192.168.1.1 is reachable
ping -c 1 192.168.1.1
 
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat       /proc/sys/net/ipv4/ip_forward
 
#looking for DIP 192.168.1.101
ping -c 1 192.168.1.101
 
#looking for VIP (will be on director)
ping -c 1 192.168.1.11
 
#install_realserver_vip
/sbin/ifconfig lo:0 192.168.1.11 broadcast 192.168.1.11 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig lo:0
#installing route for VIP 192.168.1.11 on device lo:0
/sbin/route add -host 192.168.1.11 dev lo:0
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
 
#hiding interface lo:0, will not arp
echo "1" >/proc/sys/net/ipv4/conf/all/hidden
cat       /proc/sys/net/ipv4/conf/all/hidden
echo "1" >/proc/sys/net/ipv4/conf/lo/hidden
cat       /proc/sys/net/ipv4/conf/lo/hidden
 
#----------mini-rc.lvs_dr-realserver------------------

 

腳本執行方法請參考VS/NAT模式。

運行完成后,訪問VIP(http://192.168.1.11),查看結果,第一個客戶機顯示:

第二個客戶機顯示:

注意事項: 1、基本上大部分搭載着unices和Microsoft OS的服務器都可以在VS/DR模式下作為真實服務器使用。
2、Load Balancer和所有的Real Server在物理上必須有一個網卡通過不分斷的局域網相連。
3、調度器上的VIP地址對外可見;真實服務器必須將VIP綁定到Nor-ARP網卡上,它對外不可見,只是用於欺騙真實服務器用於處理目標地址為VIP的網絡請求。
4、在VS/DR模式下,無需使用ip_forward功能,因此為了安全考慮,關閉了該功能。
5、真實服務器不再使用調度器作為網關,因此打開調度器的ICMP重定向。
4、你的真實服務器上必須已部署好http服務器,並為缺省主頁寫入不同的內容以測試調度器調度結果。

 

 

3、使用VS/TUN調度

VS/TUN在生成中很少使用,因其條件較為苛刻,但是其與另外兩種模式相比較,也有其獨特的優勢之處,首先上圖:

 

    在這個體系結構中,調度器根據各個服務器的負載情況,動態地選擇一台服務器,將請求報文封裝在另一個IP報文中,再將封裝后的IP報文轉發給選出的服務器;服務器收到報文后,先將報文解封獲得原來目標地址為VIP的報文,服務器發現VIP地址被配置在本地的IP隧道設備上,所以就處理這個請求,然后根據路由表將響應報文直接返回給客戶。

因此,VS/TUN的設置與VS/DR有部分相似之處,VS/TUN的調度器和真實服務器也需要綁定一個VIP,不同的是VS/TUN模式下,VIP綁定的網卡與VS/DR不同,因為VS/TUN需要ip隧道支持。

拓撲圖與VS/DR一致:

模擬過程中,所有的機器全部在一個網段下,客戶機的IP192.168.1.10Load Balancer同樣提供一個對外可見的VIP192.168.1.11

VS/TUN模式無需調度器和所有的真實服務器必須在一個不間斷的局域網中,即使你的調度器在北京,但是你的真實服務器在美國、英國甚至條件允許的話,你的真是服務器在月球上,也是允許的。

在我的模擬中,為了簡化了模擬環境,所有機器全部在一個網段,網關全部指向192.168.1.1

1、在Load Balancer上運行以下腳本:

#!/bin/bash
#---------------mini-rc.lvs_dr-director------------------------
#set ip_forward OFF for lvs-dr director (1 on, 0 off)
#(there is no forwarding in the conventional sense for LVS-DR)
cat       /proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/ip_forward
 
#director is not gw for realservers: leave icmp redirects on
echo 'setting icmp redirects (1 on, 0 off) '
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
cat       /proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
cat       /proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
cat       /proc/sys/net/ipv4/conf/eth0/send_redirects
 
#setup DIP
/sbin/ifconfig eth0 192.168.1.101 broadcast 192.168.1.255 netmask 255.255.255.0
 
#add ethernet device and routing for VIP 192.168.1.11
/sbin/ifconfig tunl0 192.168.1.11 broadcast 192.168.1.11 netmask 255.255.255.255
/sbin/route add -host 192.168.1.11 dev tunl0
#listing ifconfig info for VIP 192.168.1.11
/sbin/ifconfig tunl0
 
#check VIP 192.168.1.11 is reachable from self (director)
/bin/ping -c 1 192.168.1.11
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
 
#setup_ipvsadm_table
#clear ipvsadm table
/sbin/ipvsadm -C
#installing LVS services with ipvsadm
#add telnet to VIP with round robin scheduling
/sbin/ipvsadm -A -t 192.168.1.11:80 -s rr
 
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 192.168.1.102:80 -i -w 1
#check realserver reachable from director
ping -c 1 192.168.1.102
 
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 192.168.1.103:80 -i -w 1
#check realserver reachable from director
ping -c 1 192.168.1.103
 
#displaying ipvsadm settings
/sbin/ipvsadm
 
#not installing a default gw for LVS_TYPE vs-dr
#---------------mini-rc.lvs_dr-director------------------------

2、在第一台Real Server上運行以下腳本:

#!/bin/bash
#----------mini-rc.lvs_dr-realserver------------------
#setup IP
/sbin/ifconfig eth0 192.168.1.102 broadcast 192.168.1.255 netmask 255.255.255.0
#installing default gw 192.168.1.1 for vs-dr
/sbin/route add default gw 192.168.1.1
#showing routing table
/bin/netstat -rn
#checking if DEFAULT_GW 192.168.1.1 is reachable
ping -c 1 192.168.1.1
 
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat       /proc/sys/net/ipv4/ip_forward
 
#looking for DIP 192.168.1.101
ping -c 1 192.168.1.101
 
#looking for VIP (will be on director)
ping -c 1 192.168.1.11
 
#install_realserver_vip
/sbin/ifconfig tunl0 192.168.1.11 broadcast 192.168.1.11 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig tunl0
#installing route for VIP 192.168.1.11 on device tunl0
/sbin/route add -host 192.168.1.11 dev tunl0
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
 
#hiding interface tunl0, will not arp
echo "1" >/proc/sys/net/ipv4/conf/all/hidden
cat       /proc/sys/net/ipv4/conf/all/hidden
echo "1" >/proc/sys/net/ipv4/conf/tunl0/hidden
cat       /proc/sys/net/ipv4/conf/tunl0/hidden
 
#----------mini-rc.lvs_dr-realserver------------------

3、在第二台Real Server上運行以下腳本:

#!/bin/bash
#----------mini-rc.lvs_dr-realserver------------------
#setup IP
/sbin/ifconfig eth0 192.168.1.103 broadcast 192.168.1.255 netmask 255.255.255.0
#installing default gw 192.168.1.1 for vs-dr
/sbin/route add default gw 192.168.1.1
#showing routing table
/bin/netstat -rn
#checking if DEFAULT_GW 192.168.1.1 is reachable
ping -c 1 192.168.1.1
 
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat       /proc/sys/net/ipv4/ip_forward
 
#looking for DIP 192.168.1.101
ping -c 1 192.168.1.101
 
#looking for VIP (will be on director)
ping -c 1 192.168.1.11
 
#install_realserver_vip
/sbin/ifconfig tunl0 192.168.1.11 broadcast 192.168.1.11 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig tunl0
#installing route for VIP 192.168.1.11 on device tunl0
/sbin/route add -host 192.168.1.11 dev tunl0
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
 
#hiding interface tunl0, will not arp
echo "1" >/proc/sys/net/ipv4/conf/all/hidden
cat       /proc/sys/net/ipv4/conf/all/hidden
echo "1" >/proc/sys/net/ipv4/conf/tunl0/hidden
cat       /proc/sys/net/ipv4/conf/tunl0/hidden
 
#----------mini-rc.lvs_dr-realserver------------------

 

腳本執行方法請參考VS/NAT模式。

運行完成后,訪問VIP(http://192.168.1.11),查看結果,第一個客戶機顯示:

第二個客戶機顯示:

 

注意事項: 1、 VS/TUN模式下的所有真實服務器必須使用Linux系統,因為迄今為止,只有Linux系統支持隧道技術。
2、 Load Balancer和Real Server的VIP必須綁定在tunl0網卡上,且關閉Real Server網卡tunl0的arp功能。
3、 你的真實服務器上必須已部署好http服務器,並為缺省主頁寫入不同的內容以測試調度器調度結果。

 歡迎糾錯,若轉載,請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM