linux QOS流量管理實例四

下面的例子是一個真實的應用環境,是一個大型的自助商場,擁有一個總部,一個
貯藏室,以及其它城市的幾個貯藏室。
商場是使用MSSQL數據庫,遠程數據庫包含了詳細的儲備品的工作人員信息,並需要每天覆制總部數據庫數據,複製儲備品的詳細更新信息,檢驗價格和更新信息以便總部數據庫擁有每天的詳細信息,以及每個商店的庫存,應用程序是由第三方軟件公司開發,還沒有實現數據庫管理和遠程存儲,因此,需要訪問所有的數據庫在每一個商店。
所有的地點都有IP電話適配器,在下面的例子中,就像實際中的應用,H.323作爲VoIP協議,SIP,IAX,MGCP以及其它VoIP協議將在經過防火牆時被略爲的修改。
總部和同一城市的各店連接至同一ISP,事實上,城域網訪問要比廣域網更加便宜,總部擁有10M的連接至internet以及100M的城域網,貯藏室只希望擁有100M的城域網連接,而沒有連接至internet,其餘的貯藏室通過它們自己城市的ISP連接至internet
網絡結構如下圖所示:
IP地址規則如下:
總部:
路由器外網IP:1.1.1.1,內網IP:192.168.1.1,具有10M的internet連接和100M的城域網連接。
MSSQL HQ :192.168.1.2。
IP ATA:192.168.1.3。
 
站點A:
路由器外網IP爲:10.10.12.1,內網IP爲192.168.2.1,100M的城域網連接。
MSSQL :192.168.2.2。
IP ATA:192.168.2.3。
 
站點B:
B路由器的外網IP:1.1.2.1內網地址爲:192.168.3.1,擁有一條2M的到internet的連接
MSSQL:192.168.3.2。
IP ATAs:192.168.3.3。
 
站點C:
C路由器的外網IP:1.1.3.1內網地址爲:192.168.4.1,擁有一條1M的到internet的連接
MSSQL:192.168.4.2。
IP ATAs:192.168.4.3。
 
QOS流量規劃:
語音流量應該具備最高的優先級,因爲丟失數據包對其影響最大,我們爲語音流量設置優先級爲0。
數據庫複製非常重要,我們將其優先級設置爲1。
遠程數據庫開發人員必須在低延遲的情況下進行工作,我們將優先級設置爲2。
中心站點與分支機構間的流量應該優先於訪問internet的流量,我們將優先級別爲3。
internet上的用戶流量相對來說具有最低的優先級將其設爲4。
 
我們將在防火牆上創建QOS腳本,這樣,可以在部署其它位置時,緩解壓力,
在設置QOS時,沒有最好的方法,只有更好的實現我們的需求。
 
從總帶寬上來看,我們將爲每條線路上的VOIP ATA設備分配32kbps的帶寬,以確保它們不會出現問題,這此帶寬應該有最高的優先級,同時,數據庫複製也是非常重要的,因此,我們將至少分配剩下的3/8的帶寬,並且可以借用其它數據的帶寬除了VOIP之外。
 
遠程開發者不需要佔用太多的帶寬,我們將爲其分配在除去VOIP帶寬情況下況帶寬的1/8,並且可以借用其它數據帶寬除了VOIP數據之外。
 
現在已經分配了在除了VOIP帶寬的前提下的一半帶寬了,剩餘的流量正常通過站點路由器,只有站點和中心的流量,餘下的爲訪問internet的流量,餘下的流量將劃分給站點也中心之前優先級爲3,以及到internet的流量優先級爲4,具體劃分方法,如下圖所示:
現在可以通過結合iptables的方法來爲POSTROUTING打標記(MARK)來區分不同的服務和流量。
在B和C站點的防火牆中,創建下列腳本來MARK數據。
#Flush Mangle chain
$IPT -t mangle -F

#mark packets for the Voip Device - value 0
$IPT -t mangle -A POSTROUTING -d $PREFIX.3 -j MARK --set-mark 1

#mark packets for Database replication - value 1
$IPT -t mangle -A POSTROUTING -s 192.168.1.2 -d $PREFIX.2 -j MARK --set-mark 2

#mark packets for remote DB developers - value 2
$IPT -t mangle -A POSTROUTING -s 1.1.4.1 -d $PREFIX.2 -j MARK --set-mark 3

#mark packets for HQ traffic - value 3
$IPT -t mangle -A POSTROUTING -s 192.168.1.0/24 -d $PREFIX.0/24 -j MARK --set-mark 4
 
現在數據情況如下:
0: VoIP traffic
1: Database Replication
2: Remote DB Developers
3: Headquarters traffic
4: Everything else is Internet traffic
 
mangle表中的POSTROUTING中的內容如下:
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MARK all -- 0.0.0.0/0 192.168.4.3 MARK set 0x1
MARK all -- 192.168.1.2 192.168.4.2 MARK set 0x2
MARK all -- 1.1.4.1 192.168.4.2 MARK set 0x3
MARK all -- 192.168.1.0/24 192.168.4.0/24 MARK set 0x4
 
接下來,通過下列腳本來創建HTB class。
#!/bin/bash

#Edit these lines to suit location

TOTALBW=1024 #Total DOWNLOAD bandwidth for the location
VBW=128 #Voice bandwidth in this location
PREFIX=192.168.4 #IP addresses in this location

#no more editing is required below this line

let BW=$TOTALBW-$VBW

#delete root qdisc - this will drop all classes
tc qdisc del root dev eth1

#create root qdisc
tc qdisc add dev eth1 root handle 1: htb default 12

#create root class
tc class add dev eth1 parent 1: classid 1:1 htb rate ${TOTALBW}kbit ceil ${TOTALBW}kbit

#add class, Add Qdisc, Add Filter
AC="tc class add dev eth1 parent"
AQ="tc qdisc add dev eth1 parent"
AF="tc filter add dev eth1 protocol ip parent 1:0 prio 1"

#VoIP should have the highest priority
$AC 1:1 classid 1:10 htb rate ${VBW}kbit ceil ${VBW}kbit prio 0
$AQ 1:10 handle 100: pfifo limit 5
$AF handle 1 fw classid 1:10

#Database Replication
#we allow a minimum of 3/8 of total bandwidth for replication
let DBW=3*$BW/8

$AC 1:1 classid 1:20 htb rate ${DBW}kbit ceil ${BW}kbit prio 1
$AQ 1:20 handle 200: pfifo limit 5
$AF handle 2 fw classid 1:20

#Remote DB application developers
 
#we allow a minimum of 1/8 of total bandwidth for remote developers

let RBW=$BW/8

$AC 1:1 classid 1:30 htb rate ${RBW}kbit ceil ${RBW}kbit prio 2
$AQ 1:30 handle 300: pfifo limit 5
$AF handle 3 fw classid 1:30

#traffic between HQ and this location
#we allow a minimum of 1/4 of total bandwidth for traffic with HQ

let I=$BW/4
$AC 1:1 classid 1:40 htb rate ${I}kbit ceil ${BW}kbit prio 3
$AQ 1:40 handle 400: pfifo limit 5
$AF handle 4 fw classid 1:40

#Internet Traffic for users
#we allow a minimum of 1/4 of total bandwidth for internet traffic
$AC 1:1 classid 1:50 htb rate ${I}kbit ceil ${BW}kbit prio 4
$AQ 1:50 handle 500: pfifo limit 5
tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 match ip dst $PREFIX.0/24 flowid 1:50
 
used $TOTALBW (X in the earlier diagram) 1024 kbps = 1 Mbps, and $VBW (Y in the same diagram) 128 kbps
 
檢驗隊列:
sitec~# tc -s class show dev eth1
 
爲了限制上傳功能,我們將對mangle表下的POSTROUTING表中的數據打標記。將在防火牆上添加下列腳本。
 
#mark packets from the Voip Device - value 0
$IPT -t mangle -A PREROUTING -s $PREFIX.3 -j MARK --set-mark 1

#mark packets for Database replication - value 1
$IPT -t mangle -A PREROUTING -d 192.168.1.2 -s $PREFIX.2 -j MARK --set-mark 2

#mark packets for remote DB developers - value 2
$IPT -t mangle -A PREROUTING -d 1.1.4.1 -s $PREFIX.2 -j MARK --set-mark 3
 
#mark packets for HQ traffic - value 3
$IPT -t mangle -A PREROUTING -d 192.168.1.0/24 -s $PREFIX.0/24 -j MARK --set-mark 4
 
具體QOS腳本如下:
#!/bin/bash

#Edit these lines to suit location

TOTALBW=1024 #Total UPLOAD bandwidth for the location
VBW=128 #Voice bandwidth in this location
PREFIX=192.168.4 #IP addresses in this location

#no more editing is required below this line

let BW=$TOTALBW-$VBW

#delete root qdisc - this will drop all classes
tc qdisc del root dev eth0

#create root qdisc
tc qdisc add dev eth0 root handle 1: htb default 12

#create root class
tc class add dev eth0 parent 1: classid 1:1 htb rate ${TOTALBW}kbit ceil ${TOTALBW}kbit

#add class, Add Qdisc, Add Filter
AC="tc class add dev eth0 parent"
AQ="tc qdisc add dev eth0 parent"
AF="tc filter add dev eth0 protocol ip parent 1:0 prio 1"

#VoIP should have the highest priority
$AC 1:1 classid 1:10 htb rate ${VBW}kbit ceil ${VBW}kbit prio 0
$AQ 1:10 handle 100: pfifo limit 5
$AF handle 1 fw classid 1:10

#Database Replication
#we allow a minimum of 3/8 of total bandwidth for replication
let DBW=3*$BW/8

$AC 1:1 classid 1:20 htb rate ${DBW}kbit ceil ${BW}kbit prio 1
$AQ 1:20 handle 200: pfifo limit 5
$AF handle 2 fw classid 1:20
 
#Remote DB application developers
#we allow a minimum of 1/8 of total bandwidth for remote developers

let RBW=$BW/8

$AC 1:1 classid 1:30 htb rate ${RBW}kbit ceil ${RBW}kbit prio 2
$AQ 1:30 handle 300: pfifo limit 5
$AF handle 3 fw classid 1:30

#traffic between HQ and this location
#we allow a minimum of 1/4 of total bandwidth for traffic with HQ

let I=$BW/4
$AC 1:1 classid 1:40 htb rate ${I}kbit ceil ${BW}kbit prio 3
$AQ 1:40 handle 400: pfifo limit 5
$AF handle 4 fw classid 1:40

#Internet Traffic for users
#we allow a minimum of 1/4 of total bandwidth for internet traffic
$AC 1:1 classid 1:50 htb rate ${I}kbit ceil ${BW}kbit prio 4
$AQ 1:50 handle 500: pfifo limit 5
tc filter add dev eth0 protocol ip parent 1:0 prio 5 u32 match ip src $PREFIX.0/24 flowid 1:50
 
更多的關於HTB的配置請參考:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章