⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 847.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 3 页
字号:
队列规定可以看作设备的流量/数据包管理器。 队列规定内封装了其他两个主要TC组件(类和分类器),控制数据的流动。 
目前,有一些设备队列规定可以用来管理设备,包括类基队列(CBQ),优先级和CSZ (Clark-Shenker-Zhang)等。CBQ 是一种超级队列,即它能够包含其它队列(甚至其它CBQ)。 
类由设备队列规定来管理。类由若干规则(rule)构成,这些规则用以管理那个类所拥有的数据。例如,某类里的全部数据包都受到 1 Mbps的速率限度,而在午夜和早上6点的一段时间段内允许最高达 3 Mbps。 
一些队列规定可以绑定到类上,包括FIFO(先进先出),RED(随机早期探测),SFQ(随机公平队列)和令牌桶(Token Bucket)。 
如果设备上未绑定队列规定,则使用基本的FIFO。另外, CBQ,CSZ和优先级也能用于类,以及类的子类。这表明使用TC,可以轻松地建造非常复杂的流量控制。管理类的队列规定可以称为类队列规定(class queueing disciplines)。 
一般地,类队列规定管理该类的数据和队列,能决定延迟、丢掉或者重新分类它管理的包。分类器或过滤器描述包,并且把他们映射到队列规定所管理的类。 
这些过滤器通常都提供简单的描述语言,指定选择包、把包映射到类的方法。 
目前,TC可以使用的过滤器有:fwmark分类器,u32分类器,基于路由的分类器和RSVP分类器(分别用于IPV6、IPV4)等;其中,fwmark分类器允许我们使用 Linux netfilter 代码选择流量,而u32分类器允许我们选择基于 ANY 头的流量 。所有的防火墙过滤器, 例如,ipchains,都能用来分类包。 
TC代码位于内核,不同的功能块既能编译为模块,也能直接编进内核。 与内核代码或模块的通信和配置由用户级程序tc完成。 
2. 示例 
2.1 编译内核 
首先要确保选中 Kernel/User netlink socket,因为只有这样 tc 才能通过 netlink 与内核通讯。 
然后,把队列规定和分类器都编进内核。这其中包括: 
QoS or fair queueing, CBQ packet scheduler, CSZ packet scheduler, the simplest PRIO pseudoscheduler, RED queue, SFQ queue, TBF queue, QoS support, rate estimator, packet classifier API, routing-tables-based classifier, U32 classifier, special RSVP classifier 和 special RSVP classifier for IPv6。 
然后就是大家熟知的编译和安装过程了。 
2.2 建立 
[因特网] ---〈E3、T3 等〉--- [Linux 路由器] --- [Office+ISP] 
eth1 eth0 
上图中的 Linux 路由器有两个接口,不妨称之为 eth0 和 eth1。eth1 连接到路由器, eth0 连接到包括公司防火墙在内的子网上。 
由于我们只能限制发送的内容,所以我们需要两套独立的、但可能非常相似的规则集。我们可以通过改变发送次序来控制传输速率。通过修改 eth0 上的队列,我们可以确定客户 的下载(download)速率;通过修改 eth1 上的队列,我们可以确定我们公司自己的用 户的上载(upload)速率。 
比如说,公司连接到因特网的线路带宽为 10 兆,同时满足外部客户和公司自己用户的需要;此时,我们就需要一种策略,来进行管理和协调。CBQ 就可以满足我们的要求。 
我们有两个主类:'ISP' 和 'Office'。我们可以决定,客户有 8 兆的带宽,Office用户有 2 兆的带宽。 
我们首先发布如下的命令: 
# tc qdisc add dev eth0 root handle 10: cbq bandwidth 10Mbit avpkt 1000 
其含义是:我们配置了 eth0 的队列规定,root 表示这是根(root)规定,其句柄 (handle)设定为 10:'。 其类型为 CBQ。带宽为 10 M,平均包大小为 1000 字节。 
下面生成根类(root class): 
# tc class add dev eth0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit rate  
  10Mbit allot 1514 weight 1Mbit prio 8 maxburst 20 avpkt 1000 
这条命令其实不比前一条命令有更多的含义。其中,1514 是 MTU 的值。  
下面生成 ISP 类:  
# tc class add dev eth0 parent 10:1 classid 10:100 cbq bandwidth 10Mbit rate  
  8Mbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 1000 bounded 
我们分配了 8 兆的带宽给它,其中 bounded 表示该类不能超过该阀值。 
下面生成 Office 类: 
# tc class add dev eth0 parent 10:1 classid 10:200 cbq bandwidth 10Mbit rate  
  2Mbit allot 1514 weight 200Kbit prio 5 maxburst 20 avpkt 1000 bounded 
为了更清晰起见,我们的类可以用下图表示: 
我们已经向内核通知了我们的类,我们还需要告诉内核如何管理队列,如下所示: 
# tc qdisc add dev eth0 parent 10:100 sfq quantum 1514b perturb 15 
  # tc qdisc add dev eth0 parent 10:200 sfq quantum 1514b perturb 15 
这里,我们使用了随机公平队列(sfq),在消耗 CPU 周期较少的情况下,其性能还是可以接受的。其它一些队列规定可能更好,但要占用较多的 CPU 资源。令牌桶过滤器也经常使用。 
下面还有一件事要作:告诉内核网络包和类的映射关系。 
# tc filter add dev eth0 parent 10:0 protocol ip prio 100 u32 match ip dst  
  150.151.23.24 flowid 10:200 
# tc filter add dev eth0 parent 10:0 protocol ip prio 25 u32 match ip dst  
  150.151.0.0/16 flowid 10:100 
这里,我们假定 Office 位于防火墙 150.151.23.24 的后面,其它 IP 地址都属于 ISP。 u32 匹配是一种比较简单的匹配,我们可以使用 netfilter 生成更加复杂的匹配规则。 
我们已经分配了下载带宽,下面是上载带宽的分配: 
# tc qdisc add dev eth1 root handle 20: cbq bandwidth 10Mbit avpkt 1000 
# tc class add dev eth1 parent 20:0 classid 20:1 cbq bandwidth 10Mbit rate  
  10Mbit allot 1514 weight 1Mbit prio 8 maxburst 20 avpkt 1000 
# tc class add dev eth1 parent 20:1 classid 20:100 cbq bandwidth 10Mbit rate  
  8Mbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 1000  
  bounded 
# tc class add dev eth1 parent 20:1 classid 20:200 cbq bandwidth 10Mbit rate  
  2Mbit allot 1514 weight 200Kbit prio 5 maxburst 20 avpkt 1000  
  bounded 
# tc qdisc add dev eth1 parent 20:100 sfq quantum 1514b perturb 15 
  # tc qdisc add dev eth1 parent 20:200 sfq quantum 1514b perturb 15 
# tc filter add dev eth1 parent 20:0 protocol ip prio 100 u32 match ip src  
  150.151.23.24 flowid 20:200 
# tc filter add dev eth1 parent 20:0 protocol ip prio 25 u32 match ip src  
  150.151.0.0/16 flowid 20:100 
这与前面的描述基本一致,所以就不做更多的解释了。 
注:  
在前面的例子中,我们注意到:即使 ISP 客户多数离线,我们的 Office 用户也仍然只 有 2 M 的带宽,这是相当浪费的。我们可以删掉 'bounded' 参数,这样,各类之间就可以相互借用带宽了。 
但是,某些类也许不希望向其它类借用带宽;比如,一条线路上的两个互为竞争对手的 ISP 的情况。在这种情况下,我们可以加上关键字 'isolated'。 
3. 结束语 
目前,Linux 所提供的 QoS(服务质量)是所有操作系统中最复杂、最完善的。另外, BSD 的 ALTQ 应该说也相当不错;但是,在复杂性、灵活性和可扩展性等方面要落后 Linux 一大截。我不太清楚微软的产品是否提供了这方面的功能。Sun 的 Solaris 提供 了 CBQ 和 RSVP 的功能。 
Linux 也支持 IETF diffserv 特征。Linux 在 QoS 方面众多的特征,将极大提升 Linux 的市场占有率。 
</FONT><br>
                                      </TD>
                                    </TR>
                                <TR>
                                <TD colSpan=2><FONT 
                                class=middlefont></FONT><BR>
                                        <FONT 
                                class=normalfont>全文结束</FONT> </TD>
                                    </TR>
                                <TR>
                                <TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2 
                                height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
                        <TD vAlign=top width="20%" 
                      background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2> 
                          <DIV align=center> 
                            <table class=tableoutline cellspacing=1 cellpadding=4 
                        width="100%" align=center border=0>
                              <tr class=firstalt> 
                                <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
                                <font class=normalfont><b>所有分类</b></font></td>
                              </tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td>    </tr>  </table></td></tr>                            </table>
                          </DIV></TD></TR>
                    <TR vAlign=top>
                        <TD width="80%"> 
                          <DIV align=center><BR>
                          </DIV>
                        </TD></TR></TBODY></TABLE></TD></TR>
                </TABLE></TD></TR>
          </TABLE>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee 
        border=0><TBODY>
        <TR>
          <TD width="50%">
              <P><FONT class=middlefont>版权所有 &copy; 2004 <A 
            href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
                违者必究. </FONT></P>
            </TD>
          <TD width="50%">
              <DIV align=right><FONT class=middlefont>Powered by: <A 
            href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
            </TD></TR></TBODY></TABLE>
      <CENTER></CENTER></TD></TR>
    </TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -