LVS羣集——NAT&&DR模型

——————題記

1、Lvs羣集

LVS: Linux Virtual Server

LVSipvsadm/ipvs

2、何時使用lvs

clip_image001[4]

3、Lvs director is a layer4 switch

clip_image002[4]

4、LVS羣集的ip地址名稱:Lvs ip address name

clip_image003[4]

clip_image004[4]

5、LVS羣集的類型:Types of lvs cluster

①:LVS-NAT

通過NAT實現虛擬服務器(VS/NAT)

clip_image005[4]

特點:

? IP DIP必須在同一網段,而且必須爲私有地址

? IP爲RIP的default gateway

? irector很容易會成爲整個網絡的瓶頸點

? IP可支持端口映射

②:LVS-DR

通過直接路由實現虛擬服務器(VS/DR)

clip_image006[4]

特點:

? RIP DIP必須在同一網段,都不必是私有地址,

? IP直接給CIP回覆,directory只需要處理請求數據,這樣的工作效率將成倍的提高,解決了LVM-NAT的瓶頸問題。不能進行端口映射

? IP不支持端口映射。服務必須使用默認的端口

? 理員可以直接通過Internet連接到RIP對服務器進行配置。但這裏同時也存在着來自Internet的網絡安全隱患

③:LVS-TUN

通過IP隧道實現虛擬服務器(VS/TUN)

clip_image007[4]

特點:

? IP DIP 都必須爲公網地址,DIP RIP之間數據通過網絡Internet傳送。

? directory和server可以不再同一個網段,可以跨越地區,其他的都和LVM-DR形式的一樣。

? 其耗資源,投資較大。

6、arp_announce/arp_ignore

clip_image008[4]

arp_announce

clip_image009[4]

arp_ignore

clip_image010[4]

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,負載均衡羣集

HAHigh Availability ,高可用性羣集

HPHigh Performance,高性能羣集

負載均衡集羣目的是提供和節點個數成正比的負載能力,這種集羣很適合提供大訪問量的Web服務。負載均衡集羣往往也具有一定的高可用性特點。

高可用性集羣運行於兩個或多個節點上,目的是在系統出現某些故障的情況下,仍能繼續對外提供服務。高可用性集羣的設計思想就是要最大限度地減少服務中斷時間。這類集羣中比較著名的有Turbolinux TurboHA、Heartbeat、Kimberlite等。

高性能集羣對一種服務而言不具有負載均衡功能,它可以提高整個系統的可靠性,但不能增加負載的能力。當然,高可用性集羣可以運行多種服務,並適當分配在不同節點上,比如節點A提供Oracle服務,同時節點B提供Sybase服務,這也可以看成是某種意義上的負載均衡,不過這是對多種服務的分配而言。 簡單的說,高性能計算(High-Performance Computing)是計算機科的一個分支,它致力於開發超級計算機,研究並行算法和開發相關軟件。

Director:

4層:TCP/IP port(類似DNAT)

應用層:5/7 代理服務器

clip_image011[4]

clip_image012[4]

1. 定義虛擬服務器

ip1:80 s rr

2. ip1:80 -r server1

ip2:80 -r server2

HA 高可用性

HAHigh 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,服務進程(服務腳本) 存儲

clip_image013[4]

壓力測試工具: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模型

拓撲圖:

clip_image018[6]

案例應用實現詳細步驟如下:

1. Client-pc客戶端配置

image 

 

2. Director服務器配置

2.1 Director服務器ip地址配置

[root@nodel ~]# 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

[root@nodel ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=192.168.2.1

[root@nodel ~]# 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數據包轉發能力

[root@director ~]# vim /etc/sysctl.conf

7 net.ipv4.ip_forward = 1

[root@director ~]# sysctl -p

net.ipv4.ip_forward = 1

2.3 配置本地yum服務器:

clip_image014[5]

2.4 安裝配置dircetor服務器:

[root@director ~]# yum install -y ipvsadm

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

image

[root@director ~]# service ipvsadm save

Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]

[root@director ~]# service ipvsadm start

Clearing the current IPVS table: [ OK ]

Applying IPVS configuration: [ OK ]

3. 配置real-server-1web服務器:

3.1 ip地址配置

[root@nodel ~]# hostname r1.nodel.com

註銷重新登錄

[root@r1 ~]# 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

[root@r1 ~]# 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服務器:

[root@r1 ~]# 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

[root@r1 ~]#mkdir /mnt/cdrom

[root@r1 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r1 ~]#yum list all

3.3 Real-server-1Web服務器:

[root@r1 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

[root@r1 ~]#echo "web1" > /var/www/html/index.html

[root@r1 ~]# 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-1web服務:(使用vmnet1

image

 

4. 配置real-server2web服務器:

4.1 ip地址配置

[root@nodel ~]# hostname r2.nodel.com

註銷重新登錄

[root@r2 ~]# 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

[root@r2 ~]# 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服務器:

[root@r2 ~]# 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

[root@r2 ~]#mkdir /mnt/cdrom

[root@r2 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r2 ~]#yum list all

4.3 Real-server-2Web服務器:

[root@r2 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

[root@r2 ~]#echo "web2" > /var/www/html/index.html

[root@r2 ~]# 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-2web服務:(使用vmnet1

image

5. 客戶端測試:wrr

5.1 客戶端訪問director的羣集服務服務:(網卡使用橋接模式)http//192.168.145.100

image 

5.2 客戶端不斷刷新,發現出現2次web2,一次web1界面,說明按權重輪詢

image

5.3 director上查看信息如下:輪詢調度比幾乎爲2:1

[root@director ~]# 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 客戶端測試-2rr

[root@director ~]# ipvsadm –C #首先清空以前配置

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

[root@director ~]# ipvsadm -A -t 192.168.145.100:80 -s rr

[root@director ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.2.100 -m

[root@director ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.2.101 –m

[root@director ~]# 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

[root@director ~]# service ipvsadm save

Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]

[root@director ~]# service ipvsadm restart

Clearing the current IPVS table: [ OK ]

Applying IPVS configuration: [ OK ]

客戶端訪問director的羣集服務服務:(網卡使用橋接模式)http//192.168.145.100

image

客戶端不斷刷新,發現web2和web1交替出現,比率爲1:1,說明依次輪詢rr

image

在director上查看信息如下:輪詢調度比幾乎爲1:1;

說明lvs調度方法是用的是RR模式

[root@director ~]# 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模型

拓撲圖:

image 

案例應用實現詳細步驟如下:

一.Client-pc客戶端配

image

 

. Director服務器配置

2.1 Director服務器ip地址配置

[root@nodel ~]# setup

image

 

[root@nodel ~]# service network restart

Shutting down interface eth0: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface eth0: [ OK ]

[root@nodel ~]# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0C:29:66:E1:DA

inet addr:192.168.145.100  Mask:255.255.255.0

[root@nodel ~]# 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

[root@nodel ~]# hostname director.nodel.com #註銷重新登錄

2.2 director添加路由

[root@director ~]# 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

[root@director ~]# route add -host 192.168.145.100 dev eth0:0

[root@director ~]# 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服務器:

[root@director ~]# 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

[root@director ~]#mkdir /mnt/cdrom

[root@director ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@director ~]#yum list all

2.4 安裝配置dircetor服務器:

[root@director ~]# yum install -y ipvsadm

[root@director ~]# ipvsadm -ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

[root@director ~]# ipvsadm -A -t 192.168.145.100:80 -s rr

[root@director ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.145.200 -g

[root@director ~]# ipvsadm -a -t 192.168.145.100:80 -r 192.168.145.201 -g

[root@director ~]# 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

image

 

[root@director ~]# service ipvsadm save

[root@director ~]# service ipvsadm restart

三.配置real-server-1web服務器:

3.1 解決arp問題:

[root@nodel ~]# hostname r1.nodel.com

註銷重新登錄

[root@r1 ~]# echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf

[root@r1 ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf

[root@r1 ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf

[root@r1 ~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf

[root@r1 ~]# 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地址和路由

[root@r1 ~]# setup

image

image

[root@r1 ~]# service network restart

[root@r1 ~]# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0C:29:1B:F1:BA

inet addr:192.168.145.200  Mask:255.255.255.0

[root@r1 ~]# ifconfig lo:0

lo:0 Link encap:Local Loopback

inet addr:192.168.145.100 Mask:255.255.255.255

[root@r1 ~]# 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

[root@r1 ~]# route add -host 192.168.145.100 dev lo:0

[root@r1 ~]# 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-1Web服務器:

[root@r1 ~]#mkdir /mnt/cdrom

[root@r1 ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@r1 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

[root@r1 ~]# echo "web1 -- real-server-1" > /var/www/html/index.html

[root@r1 ~]# 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-1web服務:(橋接)

image

 

四.配置real-server2web服務器:

4.1 解決arp問題:

[root@nodel ~]# hostname r2.nodel.com

註銷重新登錄

[root@r2 ~]# echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf

[root@r2 ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >> /etc/sysctl.conf

[root@r2 ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf

[root@r2 ~]# echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf

[root@r2 ~]# 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地址和路由

[root@r2 ~]# setup

image

image

[root@r2~]# service network restart

[root@r2 ~]# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1

inet addr:192.168.145.201  Mask:255.255.255.0

[root@r2 ~]# ifconfig lo:0

lo:0 Link encap:Local Loopback

inet addr:192.168.145.100 Mask:255.255.255.255

[root@r2 ~]# 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

[root@r2 ~]# route add -host 192.168.145.100 dev lo:0

[root@r2 ~]# 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-2Web服務器:

[root@r2 ~]#mkdir /mnt/cdrom

[root@r2 ~]# mount /dev/cdrom /mnt/cdrom/

[root@r2 ~]# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm

[root@r2 ~]#echo "web2 -- real-server-2" > /var/www/html/index.html l

[root@r2 ~]# 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-2web服務:(橋接)

image

 

五.客戶端測試:

5.1 客戶端訪問director的羣集服務服務:(網卡使用橋接模式)http//192.168.145.100

image

5.2 客戶端不斷刷新,發現web2和web1交替出現,比率爲1:1,說明依次輪詢模式爲RR

image

5.3director上查看信息如下:輪詢調度比幾乎爲1:1;

說明lvs調度方法是用的是RR模式

[root@director ~]# 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模型完結!

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