LVS群集——NAT&&DR模型
——————題記
1、Lvs群集
LVS: Linux Virtual Server
LVS:ipvsadm/ipvs
2、何時使用lvs
3、Lvs director is a layer4 switch
4、LVS群集的ip地址名稱:Lvs ip address name
5、LVS群集的型別:Types of lvs cluster
①:LVS-NAT
通過NAT實現虛擬伺服器(VS/NAT)
特點:
? IP DIP必須在同一網段,而且必須為私有地址
? IP為RIP的default gateway
? irector很容易會成為整個網路的瓶頸點
? IP可支援埠對映
②:LVS-DR
通過直接路由實現虛擬伺服器(VS/DR)
特點:
? RIP DIP必須在同一網段,都不必是私有地址,
? IP直接給CIP回覆,directory只需要處理請求資料,這樣的工作效率將成倍的提高,解決了LVM-NAT的瓶頸問題。不能進行埠對映
? IP不支援埠對映。服務必須使用預設的埠
? 理員可以直接通過Internet連線到RIP對伺服器進行配置。但這裡同時也存在著來自Internet的網路安全隱患
③:LVS-TUN
通過IP隧道實現虛擬伺服器(VS/TUN)
特點:
? IP DIP 都必須為公網地址,DIP RIP之間資料通過網路Internet傳送。
? directory和server可以不再同一個網段,可以跨越地區,其他的都和LVM-DR形式的一樣。
? 其耗資源,投資較大。
6、arp_announce/arp_ignore
arp_announce
arp_ignore
LVS群集的詳解
一、群集的概念:
群集由通過輸入/輸出系統互聯的若干伺服器構成。這些伺服器連線到儲存介質中,由分佈資源管理軟體(DRM) 進行管理。其組成部分處在不斷的改進之中:刀片式伺服器,快速InfiniBand I/O技術和更為複雜的DRM軟體,這些部分組合在一起,使得群整合為IT經理們的實用工具。
二、群集的主要應用:
伺服器群集技術最主要的應用即在於網路負載平衡的功能。 網路負載平衡使用兩臺或更多臺一起工作的主機計算機組成的群集,為伺服器提供了高可用性和高伸縮性。Internet 客戶端使用一個 IP 地址或一組地址訪問群集。客戶端無法區別群集和單一伺服器。伺服器應用程式並不表明它們是在群集上執行的。但是,網路負載平衡群集與執行單個伺服器應用程式的單個主機有很大的區別,因為即使在某個群集主機發生故障的情況下,它也可以提供不間斷服務。群集對客戶端請求的響應也比單個主機快。
如果某個主機發生故障或離線,則網路負載平衡通過將傳入的網路通訊重定向到工作的群集主機,從而帶來了高可用性。連到離線主機的現有連線將丟失,但是 Internet 服務仍然是可用的。在多數情況下(例如,就 Web 伺服器而言),客戶端軟體可以自動重試失敗的連線,而且客戶端在接收響應時,只有數秒鐘的延遲。 網路負載平衡通過在分配給網路負載平衡群集的一個或多個虛擬 IP 地址(群集 IP 地址)間分配傳入的網路通訊,從而帶來了可變化的效能。然後,群集中的主機同時對不同的客戶端請求甚至來自同一客戶端的多個請求做出響應。例如,Web 瀏覽器可以從網路負載平衡群集中的不同主機獲得所有單張網頁中的多幅影象。這就提高了處理速度,並縮短了對客戶端做出響應的時間。
網路負載平衡使得單個子網上的所有群集主機可以同時檢測群集 IP 地址的傳入網路通訊。在每個群集主機上,網路負載平衡驅動程式充當群集介面卡驅動程式和 TCP/IP 堆疊間的過濾器,以便在主機間分配通訊。
三、LVS的排程演算法:
在核心中的連線排程演算法上,IPVS已實現了以下十種排程演算法:
LVS的演算法分為兩大類:
靜態演算法:只是根據演算法進行排程並不考慮後端REALSERVER的實際連線情況
* 輪叫排程(Round-Robin Scheduling)(rr)
排程器通過"輪叫"排程演算法將外部請求按順序輪流分配到叢集中的真實伺服器上,它均等地對待每一臺伺服器,而不管伺服器上實際的連線數和系統負載。
* 加權輪叫排程(Weighted Round-Robin Scheduling)(wrr)
排程器通過"加權輪叫"排程演算法根據真實伺服器的不同處理能力來排程訪問請求。這樣可以保證處理能力強的伺服器處理更多的訪問流量。排程器可以自動問詢真實伺服器的負載情況,並動態地調整其權值
* 目標地址雜湊排程(Destination Hashing Scheduling)(dh)
"目標地址雜湊"排程演算法根據請求的目標IP地址,作為雜湊鍵(Hash Key)從靜態分配的散列表找出對應的伺服器,若該伺服器是可用的且未超載,將請求傳送到該伺服器,否則返回空。
* 源地址雜湊排程(Source Hashing Scheduling)(sh)
"源地址雜湊"排程演算法根據請求的源IP地址,作為雜湊鍵(Hash Key)從靜態分配的散列表找出對應的伺服器,若該伺服器是可用的且未超載,將請求傳送到該伺服器,否則返回空。
動態演算法:前端的排程器會根據後端REALSERVER的實際連線情況來分配請求
* 最小連線排程(Least-Connection Scheduling)(LC)
排程器通過"最少連線"排程演算法動態地將網路請求排程到已建立的連結數最少的伺服器上。如果集群系統的真實伺服器具有相近的系統性能,採用"最小連線"排程演算法可以較好地均衡負載。
* 加權最小連線排程(Weighted Least-Connection Scheduling)(WLC) (Default)
在集群系統中的伺服器效能差異較大的情況下,排程器採用"加權最少連結"排程演算法優化負載均衡效能,具有較高權值的伺服器將承受較大比例的活動連線負載。排程器可以自動問詢真實伺服器的負載情況,並動態地調整其權值。
* 最短預期延時排程(Shortest Expected Delay Scheduling)(SED)
對wlc的改進,在wlc演算法的基礎上給權重值加一,主要用來針對某個伺服器活動連結數值為0情況
* 不排隊排程(Never Queue Scheduling)(NQ)
基於SED演算法的改進,不排隊。Never Queue從不排隊,若第二個要給沒有連線數的伺服器,不至於讓另一個伺服器特別閒,在權重差別比較大的時候特別有用。
* 基於區域性性的最少連結(Locality-Based Least Connections Scheduling)(LBLC)
基於本地的最少連線,DH演算法的動態演算法,會計算快取上現在處於活動連線的。
* 帶複製的基於區域性性最少連結(Locality-Based Least Connections with Replication Scheduling)(LBLCR)
帶複製的基於本地的最少連線,基於icp協議快取複製來完成的。
四、群集的種類:
LB:Load Balancing,負載均衡群集
HA:High Availability ,高可用性群集
HP:High Performance,高效能群集
負載均衡叢集目的是提供和節點個數成正比的負載能力,這種叢集很適合提供大訪問量的Web服務。負載均衡叢集往往也具有一定的高可用性特點。
高可用性叢集運行於兩個或多個節點上,目的是在系統出現某些故障的情況下,仍能繼續對外提供服務。高可用性叢集的設計思想就是要最大限度地減少服務中斷時間。這類叢集中比較著名的有Turbolinux TurboHA、Heartbeat、Kimberlite等。
高效能叢集對一種服務而言不具有負載均衡功能,它可以提高整個系統的可靠性,但不能增加負載的能力。當然,高可用性叢集可以執行多種服務,並適當分配在不同節點上,比如節點A提供Oracle服務,同時節點B提供Sybase服務,這也可以看成是某種意義上的負載均衡,不過這是對多種服務的分配而言。 簡單的說,高效能運算(High-Performance Computing)是計算機科的一個分支,它致力於開發超級計算機,研究並行演算法和開發相關軟體。
Director:
4層:TCP/IP port(類似DNAT)
應用層:5/7 代理伺服器
1. 定義虛擬伺服器
ip1:80 s rr
2. ip1:80 -r server1
ip2:80 -r server2
HA 高可用性
HA:High Availability ,高可用
一般性:99.9%
關鍵性:99.999%
節點:
2個節點 active -àstandby active-àactive
RHCS redhat aluster suite 100個節點 n/m模式
arp 快取 控制資訊 心跳線 (雙絞線 光纖 序列線)
群集分裂 (split-brain)
解決方法: stonith(電源交換機,ssh,meatware)fence機器模組裝置
共享儲存:
? das : 直接附加儲存 scsi 磁碟櫃
? nas : 網路附加儲存 samba nfs 檔案級的共享 效率低
? san : 儲存區域網路 fc-san(光纖) ip-san(iscsi:ip)效率高
群集檔案系統 redhat:gfs2 oracle:ocfs2
故障轉移:
故障轉移域
多個節點:群集工作票數:quorum dc
2個節點:仲裁磁碟(100M)心跳線
實現方式:
heartbeat v1 v2 v3
群集資源:
群集ip,服務程序(服務指令碼) 儲存
壓力測試工具:ab –c 100 –n 1000 http://172.16.100.1/index.html
IPVS命令用法:
ipvsadm
-A|E –t|u vip:port -s SCHEDULING(方法)
-d -D| -t|u vip:port
-a | e -t|u vip:port -g|i|m (模式 dr,tun,nat)
ipvsadm -A|E -t|u|f service-address [-s scheduler]
[-p [timeout]] [-M netmask]
ipvsadm -D -t|u|f service-address
ipvsadm -C
ipvsadm -R
ipvsadm -S [-n]
ipvsadm -a|e -t|u|f service-address -r server-address
[-g|i|m] [-w weight] [-x upper] [-y lower]
ipvsadm -d -t|u|f service-address -r server-address
ipvsadm -L|l [options]
ipvsadm -Z [-t|u|f service-address]
ipvsadm --set tcp tcpfin udp
ipvsadm --start-daemon state [--mcast-interface interface]
[--syncid syncid]
ipvsadm --stop-daemon state
ipvsadm -h
-A——add-service在核心的虛擬伺服器表中新增一條新的虛擬伺服器記錄。也就是增加一臺新的虛擬伺服器。
-E ——edit-service 編輯核心虛擬伺服器表中的一條虛擬伺服器記錄。
-D ——delete-service 刪除核心虛擬伺服器表中的一條虛擬伺服器記錄。
-C ——clear清除核心虛擬伺服器表中的所有記錄。
-R ——restore恢復虛擬伺服器規則
-S ——save 儲存虛擬伺服器規則,輸出為-R 選項可讀的格式
-a ——add-server 在核心虛擬伺服器表的一條記錄裡新增一條新的真實伺服器記錄。也就是在一個虛擬伺服器中增加一臺新的真實伺服器
-e ——edit-server 編輯一條虛擬伺服器記錄中的某條真實伺服器記錄
-d ——delete-server刪除一條虛擬伺服器記錄中的某條真實伺服器記錄
-L|-l ——list 顯示核心虛擬伺服器表
-Z ——zero虛擬服務表計數器清零(清空當前的連線數量等)
——set tcp tcpfin udp 設定連線超時值
——start-daemon啟動同步守護程序。他後面可以是master 或backup,用來說明LVS Router 是master 或是backup.在這個功能上也可以採用keepalived 的VRRP 功能。
——stop-daemon 停止同步守護程序
-h ——help顯示幫助資訊其他的選項:-t ——tcp-service service-address 說明虛擬伺服器提供的是tcp 的服務[vip:port] or [real-server-ip:port] -u ——udp-service service-address 說明虛擬伺服器提供的是udp 的服務[vip:port] or [real-server-ip:port] -f ——fwmark-service fwmark 說明是經過iptables 標記過的服務型別。
-s ——scheduler scheduler 使用的排程演算法,有這樣幾個選項rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq,預設的排程演算法是: wlc. -p ——persistent [timeout] 持久穩固的服務。這個選項的意思是來自同一個客戶的多次請求,將被同一臺真實的伺服器處理。timeout 的預設值為300 秒。
-M ——netmask netmask persistent granularity mask
-r ——real-server server-address真實的伺服器[Real-Server:port]
-g ——gatewaying指定LVS 的工作模式為直接路由模式(也是LVS 預設的模式)
-i ——ipip 指定LVS 的工作模式為隧道模式-m ——masquerading 指定LVS 的工作模式為NAT 模式-w ——weight weight 真實伺服器的權值——mcast-interface interface 指定組播的同步介面-c ——connection顯示LVS 目前的連線 如:ipvsadm -L -c——timeout 顯示tcp tcpfin udp 的timeout 值 如:ipvsadm -L ——timeout——daemon 顯示同步守護程序狀態——stats 顯示統計資訊——rate 顯示速率資訊——sort 對虛擬伺服器和真實伺服器排序輸出——numeric -n 輸出IP 地址和埠的數字形式
壓力測試工具:ab –c 100 –n 1000 http://172.16.100.1/index.html
案例一:
NAT模型
拓撲圖:
案例應用實現詳細步驟如下:
1. Client-pc客戶端配置
2. Director伺服器配置
2.1 Director伺服器ip地址配置
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.145.100
GATEWAY=192.168.145.254
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.2.1
[[email protected] ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
2.2 開啟director資料包轉發能力
[[email protected] ~]# vim /etc/sysctl.conf
7 net.ipv4.ip_forward = 1
[[email protected] ~]# sysctl -p
net.ipv4.ip_forward = 1
2.3 配置本地yum伺服器:
2.4 安裝配置dircetor伺服器:
[[email protected] ~]# yum install -y ipvsadm
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[[email protected] ~]# service ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
[[email protected] ~]# service ipvsadm start
Clearing the current IPVS table: [ OK ]
Applying IPVS configuration: [ OK ]
3. 配置real-server-1的web伺服器:
3.1 ip地址配置
[[email protected] ~]# hostname r1.nodel.com
登出重新登入
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:1b:f1:ba
NETMASK=255.255.255.0
IPADDR=192.168.2.100
GATEWAY=192.168.2.1
[[email protected] ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
3.2 配置本地yum伺服器:
[[email protected] ~]# vim /etc/yum.repos.d/server.repo
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[[email protected] ~]#mkdir /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[[email protected] ~]#yum list all
3.3 Real-server-1的Web伺服器:
[[email protected] ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm
[[email protected] ~]#echo "web1" > /var/www/html/index.html
[[email protected] ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for r1.nodel.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
3.4 客戶端訪問real-server-1的web服務:(使用vmnet1)
4. 配置real-server2的web伺服器:
4.1 ip地址配置
[[email protected] ~]# hostname r2.nodel.com
登出重新登入
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:1b:f1:ba
NETMASK=255.255.255.0
IPADDR=192.168.2.101
GATEWAY=192.168.2.1
[[email protected] ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
4.2 配置本地yum伺服器:
[[email protected] ~]# vim /etc/yum.repos.d/server.repo
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[[email protected] ~]#mkdir /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[[email protected] ~]#yum list all
4.3 Real-server-2的Web伺服器:
[[email protected] ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm
[[email protected] ~]#echo "web2" > /var/www/html/index.html
[[email protected] ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for r2.nodel.vom
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
4.4 客戶端訪問real-server-2的web服務:(使用vmnet1)
5. 客戶端測試:wrr
5.1 客戶端訪問director的群集服務服務:(網絡卡使用橋接模式)http://192.168.145.100
5.2 客戶端不斷重新整理,發現出現2次web2,一次web1介面,說明按權重輪詢
5.3 在director上檢視資訊如下:輪詢排程比幾乎為2:1
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.145.100:80 wrr
-> 192.168.2.100:80 Masq 1 0 12
-> 192.168.2.101:80 Masq 2 0 24
5.4 客戶端測試-2:rr
[[email protected] ~]# ipvsadm –C #首先清空以前配置
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[[email protected] ~]# ipvsadm -A -t 192.168.145.100:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.2.100 -m
[[email protected] ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.2.101 –m
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.145.100:80 rr
-> 192.168.2.101:80 Masq 1 0 0
-> 192.168.2.100:80 Masq 1 0 0
[[email protected] ~]# service ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
[[email protected] ~]# service ipvsadm restart
Clearing the current IPVS table: [ OK ]
Applying IPVS configuration: [ OK ]
客戶端訪問director的群集服務服務:(網絡卡使用橋接模式)http://192.168.145.100
客戶端不斷重新整理,發現web2和web1交替出現,比率為1:1,說明依次輪詢rr
在director上檢視資訊如下:輪詢排程比幾乎為1:1;
說明lvs排程方法是用的是RR模式
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.145.100:80 rr
-> 192.168.2.100:80 Masq 1 0 15
-> 192.168.2.101:80 Masq 1 0 15
至此,lvs-nat模型已完結!
案例二:LVS-DR模型
拓撲圖:
案例應用實現詳細步驟如下:
一.Client-pc客戶端配
二. Director伺服器配置
2.1 Director伺服器ip地址配置
[[email protected] ~]# setup
[[email protected] ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:66:E1:DA
inet addr:192.168.145.100 Mask:255.255.255.0
[[email protected] ~]# ifconfig eth0:0
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:66:E1:DA
inet addr:192.168.145.100 Bcast:192.168.145.100 Mask:255.255.255.255
[[email protected] ~]# hostname director.nodel.com #登出重新登入
2.2 為director新增路由
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.145.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.145.100 0.0.0.0 UG 0 0 0 eth0
[[email protected] ~]# route add -host 192.168.145.100 dev eth0:0
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.145.100 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
192.168.145.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.145.100 0.0.0.0 UG 0 0 0 eth0 2.3 配置本地yum伺服器:
[[email protected] ~]# vim /etc/yum.repos.d/server.repo
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-cluster]
name=Red Hat Enterprise Linux cluster
baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[[email protected] ~]#mkdir /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[[email protected] ~]#yum list all
2.4 安裝配置dircetor伺服器:
[[email protected] ~]# yum install -y ipvsadm
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[[email protected] ~]# ipvsadm -A -t 192.168.145.100:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.145.200 -g
[[email protected] ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.145.201 -g
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.145.100:80 rr
-> 192.168.145.201:80 Route 1 0 0
-> 192.168.145.200:80 Route 1 0 0
[[email protected] ~]# service ipvsadm save
[[email protected] ~]# service ipvsadm restart
三.配置real-server-1的web伺服器:
3.1 解決arp問題:
[[email protected] ~]# hostname r1.nodel.com
登出重新登入
[[email protected] ~]# echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf
[[email protected] ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf
[[email protected] ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf
[[email protected] ~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf
[[email protected] ~]# sysctl -p
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
3.2 配置ip地址和路由
[[email protected] ~]# setup
[[email protected] ~]# service network restart
[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:1B:F1:BA
inet addr:192.168.145.200 Mask:255.255.255.0
[[email protected] ~]# ifconfig lo:0
lo:0 Link encap:Local Loopback
inet addr:192.168.145.100 Mask:255.255.255.255
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.145.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.145.100 0.0.0.0 UG 0 0 0 lo
[[email protected] ~]# route add -host 192.168.145.100 dev lo:0
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.145.100 0.0.0.0 255.255.255.255 UH 0 0 0 lo
192.168.145.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.145.100 0.0.0.0 UG 0 0 0 lo
3.3 配置Real-server-1的Web伺服器:
[[email protected] ~]#mkdir /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[[email protected] ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm
[[email protected] ~]# echo "web1 -- real-server-1" > /var/www/html/index.html
[[email protected] ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for r1.nodel.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
3.4 客戶端訪問real-server-1的web服務:(橋接)
四.配置real-server2的web伺服器:
4.1 解決arp問題:
[[email protected] ~]# hostname r2.nodel.com
登出重新登入
[[email protected] ~]# echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf
[[email protected] ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf
[[email protected] ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf
[[email protected] ~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf
[[email protected] ~]# sysctl -p
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
4.2 配置ip地址和路由
[[email protected] ~]# setup
[[email protected]~]# service network restart
[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1
inet addr:192.168.145.201 Mask:255.255.255.0
[[email protected] ~]# ifconfig lo:0
lo:0 Link encap:Local Loopback
inet addr:192.168.145.100 Mask:255.255.255.255
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.145.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.145.100 0.0.0.0 UG 0 0 0 lo
[[email protected] ~]# route add -host 192.168.145.100 dev lo:0
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.145.100 0.0.0.0 255.255.255.255 UH 0 0 0 lo
192.168.145.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.145.100 0.0.0.0 UG 0 0 0 lo
4.3 配置Real-server-2的Web伺服器:
[[email protected] ~]#mkdir /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/
[[email protected] ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm
[[email protected] ~]#echo "web2 -- real-server-2" > /var/www/html/index.html l
[[email protected] ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for r2.nodel.vom
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
4.4 客戶端訪問real-server-2的web服務:(橋接)
五.客戶端測試:
5.1 客戶端訪問director的群集服務服務:(網絡卡使用橋接模式)http://192.168.145.100
5.2 客戶端不斷重新整理,發現web2和web1交替出現,比率為1:1,說明依次輪詢模式為RR
5.3在director上檢視資訊如下:輪詢排程比幾乎為1:1;
說明lvs排程方法是用的是RR模式
[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.145.100:80 rr
-> 192.168.145.200:80 Route 1 0 14
-> 192.168.145.201:80 Route 1 0 14
至此,lvs-dr模型完結!
轉載於:https://blog.51cto.com/liuguirong/1020435