linux QOS流量管理實例三

下面一個使用Linux作爲中小企業路由器的例子,該網絡擁有sales(銷售),accounting(財務),executive(行政),IT departments(IT部門)等幾個部門,爲了便於理解網絡,我們已經通過三臺交換機將網絡分爲了三個部分,一個銷售和財務部,一個行政部分,一個IT部門,通常情況下,使用可管理的交換機爲網絡劃分三個獨立的VLAN。
網絡規劃情況如下:
路由器通過eth0口接入internet,ip:1.1.1.1,netmask:255.255.255.252,gateway:1.1.12
路由器具有四塊快速以太網網卡,除了路由功能外,還運行着apache服務和samba服務在局域網上,因此,它是一個路由器,WEB和文件服務器。
在IT部門,除了IT經理,一個或多個網絡管理員,有一個web和mail服務器,web和mail需要靜態的公共P地址,並且所有的IT啊門員式都擁有靜態公共IP地址,爲了考慮未來增加更多的服務器,我們保留了一個64全主機的子網1.1.2.0/26,linux路由器的eth1的IP爲1.1.2.1,255.255.255.192 ,web與mail服務器的地址爲1.1.2.2,255.255.255.192,網關爲1.1.2.1,如果你願意,我們可以稱該網絡爲DMZ區域。
行政部門電腦包含了公司所有管理人員,他們表示需要最小限制可能的聊天等等,我們爲其準備一個32位主機的C類網絡1.1.2.64/27 。Linux路由器的eth2的IP爲1.1.2.65, 255.255.255.224 ,併爲他們靜態分配IP地址從1.1.2.66 to 1.1.2.94 ,子網掩碼爲255.255.255.224 ,網關爲1.1.2.65。
銷售和財務部有一個較大的網絡,公司擁有大量的銷售代理,這是網絡中最需要注意的部分,因爲大多數的IT問題都可能是由銷售部引起的,我們將在Linux路由器的eth3上運行DHCP服務我們在eth3上設置私有IP地址爲192.168.1.1,通過DHCP服務,私有IP地址爲192.168.1.2 to 192.168.1.254,網關爲192.168.1.1。
 
假設總帶寬爲6Mbps,銷售和財務部1Mbps,行政部門2Mbps,web和mail爲1Mbps,
IT部門2Mbps帶寬。
CBQ比HTB具有更多的參數,可以進行更多的性能調優,我們會在下面例子中使用參數得到最好的效果。
首先,需要爲銷售和財務部在eth3上創建CBQ qdisc,創建qdisc後,需要在接口上創建root class。
tc qdisc add dev eth3 root handle 30: cbq bandwidth 100Mbit avpkt 1000
tc class add dev eth3 parent 30:0 classid 30:1 cbq bandwidth 100Mbit rate 100Mbit allot 1514 weight 10Mbit prio 8 maxburst 20 avpkt 1000
 
現在需要爲eth3創建一個1M的子類,並在qdisc上綁定sfq,以及使用tc filter以匹配這些部門的地址。
tc class add dev eth3 parent 30:1 classid 30:100 cbq bandwidth 100Mbit rate 1Mbit allot 1514 weight 128Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth3 parent 30:100 sfq quantum 1514b perturb 15
tc filter add dev eth3 parent 30:0 protocol ip prio 5 u32 match ip dst 192.168.1.0/24 flowid 30:100
 
接下來限制行政部門帶寬,創建一個2Mbps的類和兩個子類,一個爲512Kbps,並且不允許借用其它類帶寬,另一個爲1.5Mbps,並允許最高可達到2Mbps。
首先爲eth2網卡創建CBQ qdisc和root class。
tc qdisc add dev eth2 root handle 20: cbq bandwidth 100Mbit avpkt 1000
tc class add dev eth2 parent 20:0 classid 20:1 cbq bandwidth 100Mbit rate 100Mbit allot 1514 weight 10Mbit prio 8 maxburst 20 avpkt 1000
 
接下來,我們爲兩個子類創建一個2M的父類。
tc class add dev eth2 parent 20:1 classid 20:10 cbq bandwidth 100Mbit rate 2Mbit allot 1514 weight 256Kbit prio 5 maxburst 20 avpkt 1000 bounded
 
現在在父類20:10上創建一個512Kbps的子類,並且不允許借用帶寬,並在qdisc上綁定sfq,使用tc filter匹配所有nfmark 5的數據(在之前的iptables中將所有的p2p的下載流量打上-j MARK --set-mark 5,這樣就可實現所有行政部人員在下載時帶寬不會超過512Kbps)。
tc class add dev eth2 parent 20:10 classid 20:100 cbq bandwidth 100Mbit rate 512Kbit allot 1514 weight 64Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth2 parent 20:100 sfq quantum 1514b perturb 15
tc filter add dev eth2 parent 20:0 protocol ip prio 5 handle 5 fw flowid 20:100
 
接下來,爲行政部門創建另一個1.5Mbps的子類,所有非P2P的流量都將從此類通過。
tc class add dev eth2 parent 20:10 classid 20:200 cbq bandwidth 100Mbit rate 1536Kbit allot 1514 weight 192Kbit prio 5 maxburst 20 avpkt 1000
tc qdisc add dev eth2 parent 20:200 sfq quantum 1514b perturb 15
tc filter add dev eth2 parent 20:0 protocol ip prio 5 u32 match ip dst 1.1.2.64/27 flowid 20:200
 
最後,WEB服務器和IT部門的流量控制配置方法與前面類似。
在eth1上創建qdisc和class。
tc qdisc add dev eth1 root handle 10: cbq bandwidth 100Mbit avpkt 1000
tc class add dev eth1 parent 10:0 classid 10:1 cbq bandwidth 100Mbit rate 100Mbit allot 1514 weight 10Mbit prio 8 maxburst 20 avpkt 1000
 
創建1M的子類,綁定sfq,設置匹配IP地址。
tc class add dev eth1 parent 10:1 classid 10:100 cbq bandwidth 100Mbit rate 1Mbit allot 1514 weight 128Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:100 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.2.2 flowid 10:100
 
創建2M的子類,綁定sfq,設置匹配IP地址。
tc class add dev eth1 parent 10:1 classid 10:200 cbq bandwidth 100Mbit rate 2Mbit allot 1514 weight 256Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:200 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.2.2 flowid 10:200
 
整個QOS腳本如下:
#!/bin/bash
#delete root qdisc for eth3
tc qdisc del dev eth3 root
#attach root qdisc and create the root class for eth3
tc qdisc add dev eth3 root handle 30: cbq bandwidth 100Mbit avpkt 1000
tc class add dev eth3 parent 30:0 classid 30:1 cbq bandwidth 100Mbit rate \
100Mbit allot 1514 weight 10Mbit prio 8 maxburst 20 avpkt 1000

#create the 1Mbps class for sales and accounting
tc class add dev eth3 parent 30:1 classid 30:100 cbq bandwidth 100Mbit rate \
1Mbit allot 1514 weight 128Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth3 parent 30:100 sfq quantum 1514b perturb 15
tc filter add dev eth3 parent 30:0 protocol ip prio 5 u32 match ip dst 192.168.1.0/24 flowid 30:100

#delete root qdisc for eth2
tc qdisc del dev eth2 root
#attach root qdisc and create the root class for eth2
tc qdisc add dev eth2 root handle 20: cbq bandwidth 100Mbit avpkt 1000
tc class add dev eth2 parent 20:0 classid 20:1 cbq bandwidth 100Mbit rate \
100Mbit allot 1514 weight 10Mbit prio 8 maxburst 20 avpkt 1000

#create the 2Mbps class for all traffic to executive dep.
tc class add dev eth2 parent 20:1 classid 20:10 cbq bandwidth 100Mbit rate \
2Mbit allot 1514 weight 256Kbit prio 5 maxburst 20 avpkt 1000 bounded

#the bittorrent and dc++ class - 512Kbps
tc class add dev eth2 parent 20:10 classid 20:100 cbq bandwidth 100Mbit rate \
512Kbit allot 1514 weight 64Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth2 parent 20:100 sfq quantum 1514b perturb 15
tc filter add dev eth2 parent 20:0 protocol ip prio 5 handle 5 fw flowid 20:100

#other traffic to executive dep.
tc class add dev eth2 parent 20:10 classid 20:200 cbq bandwidth 100Mbit rate \
1536Kbit allot 1514 weight 192Kbit prio 5 maxburst 20 avpkt 1000
tc qdisc add dev eth2 parent 20:200 sfq quantum 1514b perturb 15
tc filter add dev eth2 parent 20:0 protocol ip prio 5 u32 match ip dst 1.1.2.64/27 flowid 20:200

#delete root qdisc for eth1
tc qdisc del dev eth1 root

#attach root qdisc and create the root class for eth1
tc qdisc add dev eth1 root handle 10: cbq bandwidth 100Mbit avpkt 1000
tc class add dev eth1 parent 10:0 classid 10:1 cbq bandwidth 100Mbit rate \
100Mbit allot 1514 weight 10Mbit prio 8 maxburst 20 avpkt 1000

#create the 1Mbps class for the web and mail server
tc class add dev eth1 parent 10:1 classid 10:100 cbq bandwidth 100Mbit rate \
1Mbit allot 1514 weight 128Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:100 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.2.2 flowid 10:100

#create the 2Mbps class for the IT dep.
tc class add dev eth1 parent 10:1 classid 10:200 cbq bandwidth 100Mbit rate \
2Mbit allot 1514 weight 256Kbit prio 5 maxburst 20 avpkt 1000 bounded
tc qdisc add dev eth1 parent 10:200 sfq quantum 1514b perturb 15
tc filter add dev eth1 parent 10:0 protocol ip prio 5 u32 match ip dst 1.1.2.2 flowid 10:200
 
檢驗QOS配置:
root@router:~# tc -s class show dev eth1
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章