linux QOS流量管理实例三
时间:2009-03-23 来源:sjhf
下面一个使用Linux作为中小企业路由器的例子,该网络拥有sales(销售),accounting(财务),executive(行政),IT departments(IT部门)等几个部门,为了便于理解网络,我们已经通过三台交换机将网络分为了三个部分,一个销售和财务部,一个行政部分,一个IT部门,通常情况下,使用可管理的交换机为网络划分三个独立的VLAN。
![]() 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 |
相关阅读 更多 +