{"id":33,"date":"2014-04-06T14:14:06","date_gmt":"2014-04-06T06:14:06","guid":{"rendered":"http:\/\/blog.qiaogen.com\/?p=33"},"modified":"2014-04-06T14:14:06","modified_gmt":"2014-04-06T06:14:06","slug":"%e5%85%b3%e4%ba%8etc%e7%9a%84%e6%96%87%e7%ab%a0-%e8%bf%99%e7%af%87%e4%b8%8d%e9%94%99","status":"publish","type":"post","link":"https:\/\/www.sangqiao.com\/blog\/archives\/33","title":{"rendered":"\u5173\u4e8etc\u7684\u6587\u7ae0 \u8fd9\u7bc7\u4e0d\u9519"},"content":{"rendered":"<p>http:\/\/www.php-oa.com\/2009\/06\/23\/linux_tc.html<\/p>\n<p>\u516c\u53f8\u4e00\u53f0\u670d\u52a1\u5668,\u7f51\u7edc\u73af\u5883\u592a\u9ad8,\u90a3\u53f0\u670d\u52a1\u5668\u548c\u6e90\u670d\u52a1\u5668\u8fde\u63a5\u4e0b\u8f7d,\u5c31\u8dd1\u5230400M-500M,\u4e3a\u4e86\u63a7\u5236\u4e00\u4e0b,\u6240\u4ee5\u7814\u7a76\u4e86\u4e00\u4e0btc.\u6765\u505a\u6d41\u91cf\u63a7\u5236.\u7ed9\u4ed6\u63a7\u5236\u5230\u5c0f\u70b9,\u4e0d\u8981\u8ba9\u8fd9\u4e00\u53f0\u5360\u4e86\u6240\u6709\u7684\u7f51\u7edc.tc \u662f\u975e\u5e38\u975e\u5e38\u5f3a\u5927\u7684,\u5f88\u591a\u6240\u8c13\u7684\u786c\u4ef6\u8def\u7531\u5668,\u90fd\u662f\u57fa\u4e8e\u8fd9\u4e2a\u505a\u7684.<\/p>\n<h1><strong>tc \u4ecb\u7ecd<\/strong><\/h1>\n<p>\u5728 linux \u4e2d,tc \u6709\u4e8c\u79cd\u63a7\u5236\u65b9\u6cd5 CBQ \u548c HTB.HTB \u662f\u8bbe\u8ba1\u7528\u6765\u66ff\u6362 CBQ \u7684.HTB\u6bd4CBQ\u66f4\u52a0\u7075\u6d3b\uff0c\u4f46\u662fCPU \u5f00\u9500\u4e5f\u66f4\u5927\uff0c\u901a\u5e38\u9ad8\u901f\u7684\u94fe\u8def\u4f1a\u4f7f\u7528CBQ\uff0c\u4e00\u822c\u800c\u8a00HTB\u4f7f\u7528\u7684\u66f4\u52a0\u5e7f\u6cdb<\/p>\n<p>\u6211\u4eec\u5bf9 tc \u4e2d\u7684 HTB\u00a0 \u7684\u89c4\u5219\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u6811\u5f62\u7ed3\u6784,\u5305\u62ec\u4e09\u4e2a\u57fa\u672c\u7684\u6784\u6210\u5757\uff1a<\/p>\n<p>\u961f\u5217\u89c4\u5b9a qdisc(queueing discipline) ,\u7c7b(class)\u548c\u5206\u7c7b\u5668(Classifiers).<\/p>\n<h3>qdisc\u00a0<strong>\u961f\u5217<\/strong>\u89c4\u5219<strong>(queueing discipline):<\/strong><\/h3>\n<p>\u7528\u6765\u5b9e\u73b0\u63a7\u5236\u7f51\u7edc\u7684\u6536\u53d1\u901f\u5ea6.\u901a\u8fc7\u961f\u5217,linux\u53ef\u4ee5\u5c06\u7f51\u7edc\u6570\u636e\u5305\u7f13\u5b58\u8d77\u6765,\u7136\u540e\u6839\u636e\u7528\u6237\u7684\u8bbe\u7f6e,\u5728\u5c3d\u91cf\u4e0d\u4e2d\u65ad\u8fde\u63a5(\u5982 tcp)\u7684\u524d\u63d0\u4e0b\u6765\u5e73\u6ed1\u7f51\u7edc\u6d41\u91cf.\u9700\u8981\u6ce8\u610f\u7684\u662f,linux \u5bf9\u63a5\u6536\u961f\u5217\u7684\u63a7\u5236\u4e0d\u591f\u597d,\u6240\u4ee5\u6211\u4eec\u4e00\u822c\u53ea\u7528\u53d1\u9001\u961f\u5217,\u5373&#8221;\u63a7\u53d1\u4e0d\u63a7\u6536&#8221;.\u5b83\u5c01\u88c5\u4e86\u5176\u4ed6\u4e24\u4e2a\u4e3b\u8981 tc \u7ec4\u4ef6(\u7c7b\u548c\u5206\u7c7b\u5668).\u5185\u6838\u5982\u679c\u9700\u8981\u901a\u8fc7\u67d0\u4e2a\u7f51\u7edc\u63a5\u53e3\u53d1\u9001\u6570\u636e\u5305,\u5b83\u90fd\u9700\u8981\u6309\u7167\u4e3a\u8fd9\u4e2a\u63a5\u53e3\u914d\u7f6e\u7684 qdisc \u961f\u5217\u89c4\u5219\u628a\u6570\u636e\u5305\u52a0\u5165\u961f\u5217.\u7136\u540e,\u5185\u6838\u4f1a\u5c3d\u53ef\u80fd\u591a\u5730\u4ece qdisc\u91cc\u9762\u53d6\u51fa\u6570\u636e\u5305,\u628a\u5b83\u4eec\u4ea4\u7ed9\u7f51\u7edc\u9002\u914d\u5668\u9a71\u52a8\u6a21\u5757.<\/p>\n<p>\u6700\u7b80\u5355\u7684 QDisc \u662f pfifo \u5b83\u4e0d\u5bf9\u8fdb\u5165\u7684\u6570\u636e\u5305\u505a\u4efb\u4f55\u7684\u5904\u7406,\u6570\u636e\u5305\u91c7\u7528\u5148\u5165\u5148\u51fa\u7684\u65b9\u5f0f\u901a\u8fc7\u961f\u5217.\u4e0d\u8fc7,\u5b83\u4f1a\u4fdd\u5b58\u7f51\u7edc\u63a5\u53e3\u4e00\u65f6\u65e0\u6cd5\u5904\u7406\u7684\u6570\u636e\u5305.\u5e38\u6709\u7684\u961f\u5217\u89c4\u5219\u5305\u62ec FIFO \u5148\u8fdb\u5148\u51fa,RED \u968f\u673a\u65e9\u671f\u63a2\u6d4b,SFQ \u968f\u673a\u516c\u5e73\u961f\u5217\u548c\u4ee4\u724c\u6876 Token Bucket,\u7c7b\u57fa\u961f\u5217 CBQ,CBQ \u662f\u4e00\u79cd\u8d85\u7ea7\u961f\u5217,\u5373\u5b83\u80fd\u591f\u5305\u542b\u5176\u5b83\u961f\u5217,\u751a\u81f3\u5176\u5b83 CBQ.<\/p>\n<h3><strong>Class \u7c7b<\/strong><\/h3>\n<p>class \u7528\u6765\u8868\u793a\u63a7\u5236\u7b56\u7565.\u5f88\u663e\u7136,\u5f88\u591a\u65f6\u5019,\u6211\u4eec\u5f88\u53ef\u80fd\u8981\u5bf9\u4e0d\u540c\u7684IP\u5b9e\u884c\u4e0d\u540c\u7684\u6d41\u91cf\u63a7\u5236\u7b56\u7565,\u8fd9\u65f6\u5019\u6211\u4eec\u5c31\u5f97\u7528\u4e0d\u540c\u7684class\u6765\u8868\u793a\u4e0d\u540c\u7684\u63a7\u5236\u7b56\u7565\u4e86.<\/p>\n<h3><strong>Filter \u89c4\u5219<\/strong><\/h3>\n<p>filter \u7528\u6765\u5c06\u7528\u6237\u5212\u5165\u5230\u5177\u4f53\u7684\u63a7\u5236\u7b56\u7565\u4e2d(\u5373\u4e0d\u540c\u7684 class \u4e2d).\u6bd4\u5982,\u73b0\u5728,\u6211\u4eec\u60f3\u5bf9xxa,xxb\u4e24\u4e2aIP\u5b9e\u884c\u4e0d\u540c\u7684\u63a7\u5236\u7b56\u7565(A,B),\u8fd9\u65f6,\u6211\u4eec\u53ef\u7528 filter \u5c06 xxa \u5212\u5165\u5230\u63a7\u5236\u7b56\u7565 A,\u5c06 xxb \u5212\u5165\u5230\u63a7\u5236\u7b56\u7565 B,filter \u5212\u5206\u7684\u6807\u5fd7\u4f4d\u53ef\u7528 u32 \u6253\u6807\u529f\u80fd\u6216 IPtables \u7684 set-mark (\u5927\u591a\u4f7f\u7528iptables \u6765\u505a\u6807\u8bb0)\u529f\u80fd\u6765\u5b9e\u73b0.<br \/>\n\u76ee\u524d,tc\u53ef\u4ee5\u4f7f\u7528\u7684\u8fc7\u6ee4\u5668\u6709\uff1afwmark\u5206\u7c7b\u5668,u32 \u5206\u7c7b\u5668,\u57fa\u4e8e\u8def\u7531\u7684\u5206\u7c7b\u5668\u548c RSVP \u5206\u7c7b\u5668\uff08\u5206\u522b\u7528\u4e8eIPV6\u3001IPV4\uff09\u7b49\uff1b\u5176\u4e2d,fwmark \u5206\u7c7b\u5668\u5141\u8bb8\u6211\u4eec\u4f7f\u7528 Linux netfilter \u4ee3\u7801\u9009\u62e9\u6d41\u91cf,\u800c u32 \u5206\u7c7b\u5668\u5141\u8bb8\u6211\u4eec\u9009\u62e9\u57fa\u4e8e ANY \u5934\u7684\u6d41\u91cf .\u9700\u8981\u6ce8\u610f\u7684\u662f,filter (\u8fc7\u6ee4\u5668)\u662f\u5728QDisc \u5185\u90e8,\u5b83\u4eec\u4e0d\u80fd\u4f5c\u4e3a\u4e3b\u4f53.<\/p>\n<h2>tc \u7684\u5e94\u7528\u6d41\u7a0b<\/h2>\n<p>\u5982\u679c\u5c06HTB\u7684\u5206\u5c42\u7ed3\u6784\u770b\u4f5c\u6811\uff0c\u90a3\u4e48\u6bcf\u4e2a\u8282\u70b9\u5c31\u88ab\u79f0\u4e3a\u4e00\u4e2a class\uff0c\u6bcf\u4e2aclass\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a qdisc\uff0c\u9ed8\u8ba4\u7684\u662f tc-pfifo. \u53e6\u5916HTB\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e9b\u8fc7\u6ee4\u5668\uff0c\u901a\u8fc7\u8fd9\u4e9b\u8fc7\u6ee4\u5668\u53ef\u4ee5\u5c06\u5230\u6765\u7684\u5305\u5206\u53d1\u5230\u6307\u5b9a\u7684 class \u4e0a\u3002\u8fd9\u91cc\u8fc7\u6ee4\u5668\u901a\u5e38\u6302\u8f7d\u5728 root \u8282\u70b9(eth0\u63a5\u53e3)\uff0c\u4f46\u5339\u914d\u53ea\u80fd\u5339\u914d\u53f6\u5b50\u8282\u70b9\u3002<br \/>\n\u6570\u636e\u5305-&gt;iptables(\u5728\u901a\u8fc7iptables\u65f6,iptables\u6839\u636e\u4e0d\u540c\u7684ip\u6765\u8bbe\u7f6e\u4e0d\u540c\u7684mark)-&gt;tc(class)-&gt;tc(queue)<\/p>\n<p><strong>\u5e94\u7528<\/strong><br \/>\n\u5047\u8bbe eth0 \u4f4d\u662f\u670d\u52a1\u5668\u7684\u5916\u7f51\u7f51\u7edc\u63a5\u53e3.\u5f00\u59cb\u4e4b\u524d,\u5148\u8981\u6e05\u9664 eth0\u6240\u6709\u961f\u5217\u89c4\u5219<\/p>\n<div>\n<div id=\"highlighter_777796\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc del dev eth0 root 2&gt; \/dev\/null &gt; \/dev\/null<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>1) \u5b9a\u4e49\u6700\u9876\u5c42(\u6839)\u961f\u5217\u89c4\u5219,\u5e76\u6307\u5b9a default \u7c7b\u522b\u7f16\u53f7<\/p>\n<div>\n<div id=\"highlighter_494833\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc add dev eth0 root handle 1: htb default 2<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>2) \u5b9a\u4e49\u7b2c\u4e00\u5c42\u7684 1:1 \u7c7b\u522b (\u901f\u5ea6)<br \/>\n\u672c\u6765\u662f\u8981\u591a\u5b9a\u4e49\u7b2c\u4e8c\u5c42\u53f6\u7c7b\u522b,\u4f46\u76ee\u524d\u6765\u770b,\u8fd9\u4e2a\u5e94\u7528\u4e2d\u5c31\u53ef\u4ee5\u4e86.<\/p>\n<div>\n<div id=\"highlighter_195583\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc class add dev eth0 parent 1:1 classid 1:2 htb rate 98mbit ceil 100mbit prio 2<\/code><\/div>\n<div><code>tc class add dev eth0 parent 1:1 classid 1:3 htb rate 1mbit ceil 2mbit prio 2<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u6ce8:\u4ee5\u4e0a\u5c31\u662f\u6211\u4eec\u63a7\u5236\u8f93\u51fa\u670d\u52a1\u5668\u7684\u901f\u5ea6,\u4e00\u4e2a\u4e3a98M,\u4e00\u4e2a\u4e3a 2M.<br \/>\nrate: \u662f\u4e00\u4e2a\u7c7b\u4fdd\u8bc1\u5f97\u5230\u7684\u5e26\u5bbd\u503c.\u5982\u679c\u6709\u4e0d\u53ea\u4e00\u4e2a\u7c7b,\u8bf7\u4fdd\u8bc1\u6240\u6709\u5b50\u7c7b\u603b\u548c\u662f\u5c0f\u4e8e\u6216\u7b49\u4e8e\u7236\u7c7b.<br \/>\nprio:\u7528\u6765\u6307\u793a\u501f\u7528\u5e26\u5bbd\u65f6\u7684\u7ade\u4e89\u529b,prio\u8d8a\u5c0f,\u4f18\u5148\u7ea7\u8d8a\u9ad8,\u7ade\u4e89\u529b\u8d8a\u5f3a.<br \/>\nceil: ceil\u662f\u4e00\u4e2a\u7c7b\u6700\u5927\u80fd\u5f97\u5230\u7684\u5e26\u5bbd\u503c.<\/p>\n<p>&nbsp;<\/p>\n<p>\u540c\u65f6\u4e3a\u4e86\u4e0d\u4f7f\u4e00\u4e2a\u4f1a\u8bdd\u6c38\u5360\u5e26\u5bbd,\u6dfb\u52a0\u968f\u5373\u516c\u5e73\u961f\u5217sfq.<\/p>\n<div>\n<div id=\"highlighter_823296\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc add dev eth0 parent 1:2 handle 2: sfq perturb 10<\/code><\/div>\n<div><code>tc qdisc add dev eth0 parent 1:3 handle 3: sfq perturb 10<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>3) \u8bbe\u5b9a\u8fc7\u6ee4\u5668<br \/>\n\u8fc7\u6ee4\u5668\u53ef\u4ee5\u4f7f\u7528\u672c\u8eab\u7684 u32 \u4e5f\u53ef\u4ee5\u4f7f\u7528 iptables \u6765\u6253\u4e0a\u6807\u8bb0<br \/>\n\u6307\u5b9a\u5728root \u7c7b 1:0 \u4e2d,\u5bf9 192..168.0.2 \u7684\u8fc7\u6ee4,\u4f7f\u7528 1:2 \u7684\u89c4\u5219,\u6765\u7ed9\u4ed6 98M \u7684\u901f\u5ea6,\u5199\u6cd5\u5c31\u5982\u4e0b<\/p>\n<div>\n<div id=\"highlighter_995486\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc filter add dev eth0 protocol ip parent 1:0 u32 match ip src 192.168.0.2 flowid 1:2<\/code><\/div>\n<div><code>tc filter add dev eth0 protocol ip parent 1:0 u32 match ip src 192.168.0.1 flowid 1:3<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u5982\u679c\u662f\u6240\u6709 ip \u5199\u6cd5\u5c31\u5982:<\/p>\n<div>\n<div id=\"highlighter_697679\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc filter add dev eth0 protocol ip parent 1: prio 50 u32 match ip dst 0.0.0.0\/0 flowid 1:10<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>\u4f7f\u7528 iptables \u6765\u914d\u5408\u8fc7\u6ee4\u5668<br \/>\n\u8fd8\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5,\u4f46\u9700\u8981\u501f\u52a9\u4e0b\u9762\u7684 iptables \u7684\u547d\u4ee4\u6765\u505a\u6807\u8bb0\u4e86<\/p>\n<div>\n<div id=\"highlighter_940571\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc filter add dev eth0 parent 1: protocol ip prio 1 handle 2 fw flowid 1:2<\/code><\/div>\n<div><code>tc filter add dev eth0 parent 1: protocol ip prio 1 handle 2 fw flowid 1:3<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>iptables \u53ea\u8981\u6253\u4e0a\u8bb0\u53f7\u5c31\u884c\u4e86,\u8fd9\u79cd\u65f6\u5019\u5927\u591a\u7528\u5728\u505a\u7f51\u5173\u7684\u65f6\u5019,\u5f88\u5408\u9002\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5.<\/p>\n<div>\n<div id=\"highlighter_175623\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<\/td>\n<td>\n<div>\n<div><code>iptables -t mangle -A POSTROUTING -d 192.168.0.2 -j MARK --set-mark 10<\/code><\/div>\n<div><code>iptables -t mangle -A POSTROUTING -d 192.168.0.3 -j MARK --set-mark 20<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<br \/>\n<strong>tc\u5bf9\u6700\u5bf9\u9ad8\u901f\u5ea6\u7684\u63a7\u5236<\/strong><br \/>\nRate ceiling \u901f\u7387\u9650\u5ea6<br \/>\n\u53c2\u6570ceil\u6307\u5b9a\u4e86\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u7528\u7684\u6700\u5927\u5e26\u5bbd, \u7528\u6765\u9650\u5236\u7c7b\u53ef\u4ee5\u501f\u7528\u591a\u5c11\u5e26\u5bbd.\u7f3a\u7701\u7684ceil\u662f\u548c\u901f\u7387\u4e00\u6837<br \/>\n\u8fd9\u4e2a\u7279\u6027\u5bf9\u4e8eISP\u662f\u5f88\u6709\u7528\u7684, \u56e0\u4e3a\u4ed6\u4eec\u4e00\u822c\u9650\u5236\u88ab\u670d\u52a1\u7684\u7528\u6237\u7684\u603b\u91cf\u5373\u4f7f\u5176\u4ed6\u7528\u6237\u6ca1\u6709\u8bf7\u6c42\u670d\u52a1.(ISPS \u5f88\u60f3\u7528\u6237\u4ed8\u66f4\u591a\u7684\u94b1\u5f97\u5230\u66f4\u597d\u7684\u670d\u52a1) ,\u6ce8\u6839\u7c7b\u662f\u4e0d\u5141\u8bb8\u88ab\u501f\u7528\u7684, \u6240\u4ee5\u6ca1\u6709\u6307\u5b9aceil<br \/>\n\u6ce8: ceil\u7684\u6570\u503c\u5e94\u8be5\u81f3\u5c11\u548c\u5b83\u6240\u5728\u7684\u7c7b\u7684\u901f\u7387\u4e00\u6837\u9ad8, \u4e5f\u5c31\u662f\u8bf4ceil\u5e94\u8be5\u81f3\u5c11\u548c\u5b83\u7684\u4efb\u4f55\u4e00\u4e2a\u5b50\u7c7b\u4e00\u6837\u9ad8<\/p>\n<p>Burst \u7a81\u53d1<br \/>\n\u7f51\u7edc\u786c\u4ef6\u53ea\u80fd\u5728\u4e00\u4e2a\u65f6\u95f4\u53d1\u9001\u4e00\u4e2a\u5305\u8fd9\u4ec5\u4ec5\u53d6\u51b3\u4e8e\u4e00\u4e2a\u786c\u4ef6\u7684\u901f\u7387. \u94fe\u8def\u5171\u4eab\u8f6f\u4ef6\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u80fd\u529b\u52a8\u6001\u4ea7\u751f\u591a\u4e2a\u8fde\u63a5\u8fd0\u884c\u5728\u4e0d\u540c\u7684\u901f\u5ea6. \u6240\u4ee5\u901f\u7387\u548cceil\u4e0d\u662f\u4e00\u4e2a\u5373\u65f6\u5ea6\u91cf\u53ea\u662f\u4e00\u4e2a\u5728\u4e00\u4e2a\u65f6\u95f4\u91cc\u53d1\u9001\u5305\u7684\u5e73\u5747\u503c. \u5b9e\u9645\u7684\u60c5\u51b5\u662f\u600e\u6837\u4f7f\u4e00\u4e2a\u6d41\u91cf\u5f88\u5c0f\u7684\u7c7b\u5728\u67d0\u4e2a\u65f6\u95f4\u7c7b\u4ee5\u6700\u5927\u7684\u901f\u7387\u63d0\u4f9b\u7ed9\u5176\u4ed6\u7c7b. burst \u548ccburst \u53c2\u6570\u63a7\u5236\u591a\u5c11\u6570\u636e\u53ef\u4ee5\u4ee5\u786c\u4ef6\u6700\u5927\u7684\u901f\u5ea6\u4e0d\u8d39\u529b\u7684\u53d1\u9001\u7ed9\u9700\u8981\u7684\u5176\u4ed6\u7c7b.<br \/>\n\u5982\u679ccburst \u5c0f\u4e8e\u4e00\u4e2a\u7406\u8bba\u4e0a\u7684\u6570\u636e\u5305\u4ed6\u5f62\u6210\u7684\u7a81\u53d1\u4e0d\u4f1a\u8d85\u8fc7ceil \u901f\u7387, \u540c\u6837\u7684\u65b9\u6cd5TBF\u7684\u6700\u9ad8\u901f\u7387\u4e5f\u662f\u8fd9\u6837.<br \/>\n\u4f60\u53ef\u80fd\u4f1a\u95ee, \u4e3a\u4ec0\u4e48\u9700\u8981bursts . \u56e0\u4e3a\u5b83\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u63d0\u9ad8\u5411\u5e94\u901f\u5ea6\u5728\u4e00\u4e2a\u5f88\u62e5\u6324\u7684\u94fe\u8def\u4e0a. \u6bd4\u5982WWW \u6d41\u91cf\u662f\u7a81\u53d1\u7684. \u4f60\u8bbf\u95ee\u4e3b\u9875. \u7a81\u53d1\u7684\u83b7\u5f97\u5e76\u9605\u8bfb. \u5728\u7a7a\u95f2\u7684\u65f6\u95f4burst\u5c06\u518d&#8221;charge&#8221;\u4e00\u6b21.<br \/>\n\u6ce8: burst \u548ccburst\u81f3\u5c11\u8981\u548c\u5176\u5b50\u7c7b\u7684\u503c\u4e00\u6837\u5927.<\/p>\n<p><strong>tc\u547d\u4ee4\u683c\u5f0f\uff1a<\/strong><br \/>\n\u52a0\u5165<br \/>\ntc qdisc [ add | change | replace | link ] dev DEV [ parent qdisc-id | root ] [ handle qdisc-id ] qdisc [ qdisc specific parameters ]<\/p>\n<div>\n<div id=\"highlighter_245972\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc ... dev dev ( parent classid | root) [ handle major: ] htb [ default minor-id ] <\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><b>Qdisc\u7684\u53c2\u6570\uff1a<\/b>\u00a0<i>\u00a0<\/i><\/p>\n<p><i>parent major:minor<\/i>\u00a0\u6216\u8005\u00a0<i>root<\/i>\u3002 \u4e00\u4e2aqdisc\u662f\u6839\u8282\u70b9\u5c31\u662froot\uff0c\u5426\u5219\u5176\u4ed6\u7684\u60c5\u51b5\u6307\u5b9aparent\u3002\u5176\u4e2dmajor:minor\u662fclass\u7684handle id\uff0c\u6bcf\u4e2aclass\u90fd\u8981\u6307\u5b9a\u4e00\u4e2aid\u7528\u4e8e\u6807\u8bc6\u3002<\/p>\n<p><i>handle major:<\/i>\u00a0\uff0c\u8fd9\u4e2a\u8bed\u6cd5\u6709\u70b9\u5947\u602a\uff0c\u662f\u53ef\u9009\u7684\uff0c\u5982\u679cqdisc\u4e0b\u9762\u8fd8\u8981\u5206\u7c7b\uff08\u591a\u4e2aclass)\uff0c\u5219\u9700\u8981\u6307\u5b9a\u8fd9\u4e2ahanlde\u3002\u5bf9\u4e8eroot\uff0c\u901a\u5e38\u662f&#8221;1:&#8221;\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u5bf9\u4e8etc\u547d\u4ee4\u4e2d\u7684qdiscs\u548cclasses\uff0c\u6807\u8bc6handle(classid)\u7684\u8bed\u6cd5\u90fd\u662fx:y\uff0c\u5176\u4e2dx\u662f\u4e00\u4e2a\u6574\u6570\u7528\u6765\u6807\u8bc6\u4e00\u4e2a qdisc\uff0cy\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u7528\u6765\u6807\u8bc6\u5c5e\u4e8e\u8be5qdisc\u7684class\u3002qdisc\u7684handle\u7684y\u503c\u5fc5\u987b\u662f0\uff0cclass\u7684handle\u7684y\u503c\u5fc5\u987b\u662f\u975e 0\u3002\u901a\u5e38&#8221;1:0&#8243;\u7b80\u5199\u4e3a&#8221;1:&#8221;\uff0c\u4e5f\u5c31\u662f\u4e0a\u9762\u770b\u5230\u7684\u5199\u6cd5\u3002<\/p>\n<p><i>default minor-id<\/i>\uff0c\u672a\u5206\u7c7b\uff08\u4e0d\u80fd\u548cfilter\u5339\u914d\uff09\u7684\u6d41\u91cf\uff08\u9ed8\u8ba4\u7684\uff09\u4f1a\u88ab\u9001\u5230\u8fd9\u4e2aminor\u6240\u6307\u5b9a\u7684\u7c7b\uff08class id\u4e3amajor:minor-id\uff09\u3002<\/p>\n<div>\n<div id=\"highlighter_689477\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc class ... dev dev parent major:[minor] [ classid major:minor ] htb rate rate [ ceil rate ] burst bytes [ cburst bytes ] [ prio priority ] <\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><b>Class\u7684\u53c2\u6570\uff1a<\/b><\/p>\n<p><i>parent major:minor<\/i>\uff0c\u6307\u5b9a\u8fd9\u4e2a\u7c7b\u7684\u7236\u8282\u70b9\uff0c\u7236\u8282\u70b9\u53ef\u4ee5\u662fQdisc\uff0c\u4e5f\u53ef\u4ee5\u662fClass\uff0c\u5982\u679c\u662fQdisc\uff0c\u90a3\u4e48\u5c31\u4e0d\u7528\u6307\u5b9aminor\uff0c\u8fd9\u4e2a\u662f\u5fc5\u987b\u7684\u53c2\u6570\u3002<\/p>\n<p><i>classid major:minor<\/i>\uff0cclassid\u4f5c\u4e3aclass\u7684\u6807\u8bc6\uff0c\u8fd9\u4e2a\u662f\u53ef\u9009\u7684\u3002\u5982\u679c\u8fd9\u4e2aclass\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5c31\u53ef\u4ee5\u4e0d\u6307\u5b9a\u3002major\u662f\u7236qdisc\u7684handle\u3002<\/p>\n<p><i>prio<\/i>\u00a0\u4f4e\u4f18\u5148\u7ea7\u7684class\u4f1a\u4f18\u5148\u5339\u914d\u00a0<i>\u00a0<\/i><\/p>\n<p><i>rate<\/i>\u00a0\u8fd9\u4e2aclass\u548c\u5176\u6240\u6709\u5b50\u7c7b\u7684\u901f\u7387<\/p>\n<p><i>ceil<\/i>\u00a0\u5982\u679c\u7236\u7c7b\u6709\u7a7a\u4f59\u5e26\u5bbd\uff0c\u6700\u9ad8\u53ef\u4ee5\u5206\u914d\u7ed9\u5f53\u524dclass\u7684\u503c\uff0c\u9ed8\u8ba4\u662f\u548crate\u4e00\u6837\u3002<\/p>\n<p><i>burst<\/i>\u00a0\u5141\u8bb8\u4ee5ceil\u7684\u901f\u7387\u53d1\u9001\u7684\u5b57\u8282\u6570\uff0c\u5e94\u8be5\u81f3\u5c11\u548c\u5b50\u7c7b\u7684burst\u6700\u5927\u503c\u4e00\u6837\u3002\u00a0<i>\u00a0<\/i><\/p>\n<p><i>cburst<\/i>\u00a0\u5141\u8bb8\u4ee5\u7f51\u53e3\u7684\u6700\u9ad8\u901f\u7387\u53d1\u9001\u7684\u5b57\u8282\u6570\uff0c\u5e94\u8be5\u81f3\u5c11\u548c\u5b50\u7c7b\u7684cburst\u6700\u5927\u503c\u4e00\u6837\u3002\u529f\u80fd\u7c7b\u4f3ctbf\u4e2d\u7684peakrate\uff0c\u5f53\u8fd9\u4e2a\u503c\u9650\u5236\u5f88\u5c0f\u65f6\uff0c\u53ef\u4ee5\u907f\u514d\u7a81\u53d1\u7684\u6d41\u91cf\uff0c\u4ee5\u907f\u514d\u77ac\u95f4\u901f\u7387\u8d85\u8fc7ceil\u3002<\/p>\n<p>quantum \u6bcf\u8f6e\u5f53\u524d\u7684class\u80fd\u53d1\u9001\u7684\u5b57\u8282\u6570\uff0c\u9ed8\u8ba4\u7684\u8ba1\u7b97quantum = rate \/ r2q.\u00a0 Quantum\u5fc5\u987b\u5927\u4e8e1500 \u5c0f\u4e8e 60000\u3002quantum\u53ea\u5728class\u7684\u6d41\u91cf\u8d85\u8fc7\u4e86rate\u4f46\u662f\u6ca1\u8d85\u8fc7ceil\u65f6\u4f7f\u7528\u3002quantum\u8d8a\u5c0f\uff0c\u5e26\u5bbd\u5171\u4eab\u7684\u6548\u679c\u5c31\u8d8a\u597d\u3002\u00a0 r2q \u7528\u6765\u8ba1\u7b97quantum,r2q\u9ed8\u8ba4\u662f10\u3002<\/p>\n<p>tc filter [ add | change | replace ] dev DEV [ parent qdisc-id | root ] protocol protocol prio priority filtertype [ filtertype specific parameters ] flowid flow-id<\/p>\n<p>\u663e\u793a<br \/>\ntc [-s | -d ] qdisc show [ dev DEV ]<br \/>\ntc [-s | -d ] class show dev DEV tc filter show dev DEV<\/p>\n<p>\u67e5\u770btc\u7684\u72b6\u6001<br \/>\ntc -s -d qdisc show dev eth0<br \/>\ntc -s -d class show dev eth0<\/p>\n<p>\u5220\u9664tc\u89c4\u5219<\/p>\n<p>tc qdisc del dev eth0 root<\/p>\n<p><strong>\u5b9e\u4f8b<\/strong><\/p>\n<p><strong>\u4f7f\u7528 tc \u4e0b\u8f7d\u9650\u5236\u5355\u4e2aIP \u8fdb\u884c\u901f\u5ea6\u63a7\u5236<\/strong><\/p>\n<div>\n<div id=\"highlighter_724356\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc add dev eth0 root handle 1: htb r2q 1<\/code><\/div>\n<div><code>tc class add dev eth0 parent 1: classid 1:1 htb rate 30mbit ceil 60mbit<\/code><\/div>\n<div><code>tc\u00a0 filter add dev eth0 parent 1: protocol ip prio 16 u32 match ip dst 192.168.1.2\u00a0 flowid 1:1<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u5c31\u53ef\u4ee5\u9650\u5236192.168.1.2\u7684\u4e0b\u8f7d\u901f\u5ea6\u4e3a30Mbit\u6700\u9ad8\u53ef\u4ee560Mbit ,\u5176\u4e2d r2q,\u662f\u6307\u6ca1\u6709default\u7684root,\u4f7f\u6574\u4e2a\u7f51\u7edc\u7684\u5e26\u5bbd\u6ca1\u6709\u9650\u5236<\/p>\n<p><strong>\u4f7f\u7528 tc\u00a0\u5bf9\u6574\u6bb5 IP \u8fdb\u884c\u901f\u5ea6\u63a7\u5236<\/strong><\/p>\n<div>\n<div id=\"highlighter_239343\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc add dev eth0 root handle 1: htb r2q 1<\/code><\/div>\n<div><code>tc class add dev eth0 parent 1: classid 1:1 htb rate 50mbit ceil 1000mbit<\/code><\/div>\n<div><code>tc filter add dev eth0 parent 1: protocol ip prio 16 u32 match ip dst 192.168.111.0\/24 flowid 1:1<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u5c31\u53ef\u4ee5\u9650\u5236192.168.111.0 \u5230255 \u7684\u5e26\u5bbd\u4e3a3000k\u4e86,\u5b9e\u9645\u4e0b\u8f7d\u901f\u5ea6\u4e3a200k\u5de6\u53f3.<br \/>\n\u8fd9\u79cd\u60c5\u51b5\u4e0b,\u8fd9\u4e2a\u7f51\u6bb5\u6240\u6709\u673a\u5668\u5171\u4eab\u8fd9200k\u7684\u5e26\u5bbd.<br \/>\n\u8fd8\u53ef\u4ee5\u52a0\u5165\u4e00\u4e2asfq\uff08\u968f\u673a\u516c\u5e73\u961f\u5217\uff09<\/p>\n<div>\n<div id=\"highlighter_554100\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc add dev eth0 root handle 1: htb r2q 1<\/code><\/div>\n<div><code>tc class add dev eth0 parent 1: classid 1:1 htb rate 3000kbit burst 10k<\/code><\/div>\n<div><code>tc qdisc add dev eth0 parent 1:1 handle 10: sfq perturb 10<\/code><\/div>\n<div><code>tc filter add dev eth0 parent 1: protocol ip prio 16 u32 match ip dst 192.168.111.168 flowid 1:1<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>sfq,\u4ed6\u53ef\u4ee5\u9632\u6b62\u4e00\u4e2a\u6bb5\u5185\u7684\u4e00\u4e2aip\u5360\u7528\u6574\u4e2a\u5e26\u5bbd.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u4f7f\u7528 tc \u63a7\u5236\u670d\u52a1\u5668\u5bf9\u5916\u7684\u901f\u5ea6\u4e3a 10M<\/strong><\/p>\n<p>\u5982\u4e0b,\u6211\u8981\u7ba1\u7406\u4e00\u53f0\u670d\u52a1\u5668,\u53ea\u80fd\u5411\u5916\u53d1 10M \u7684\u6570\u636e<\/p>\n<div>\n<div id=\"highlighter_997285\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<\/td>\n<td>\n<div>\n<div><code>tc qdisc del dev eth0 root<\/code><\/div>\n<div><code>tc qdisc add dev eth0 root handle 1: htb<\/code><\/div>\n<div><code>tc class add dev\u00a0 eth0 parent 1: classid 1:1 htb rate\u00a0 100mbit ceil 100mbit<\/code><\/div>\n<div><code>tc class add dev\u00a0 eth0 parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit<\/code><\/div>\n<div><code>tc qdisc add dev\u00a0 eth0 parent 1:10 sfq perturb 10<\/code><\/div>\n<div><code>tc filter add dev eth0 protocol ip parent 1: prio 2\u00a0\u00a0 u32 match ip dst 220.181.xxx.xx\/32 flowid 1:1<\/code><\/div>\n<div><code>#\u00a0 \u4e0a\u9762\u8fd9\u53f0,\u8ba9 220.181.xxx.xx\/32 \u8fd9\u53f0\u8dd1\u9ed8\u8ba4\u7684,\u4e3b\u8981\u662f\u4e3a\u4e86\u8ba9\u8fd9\u4e2a ip \u8fde\u63a5\u8fdb\u6765\u4e0d\u88ab\u63a7\u5236<\/code><\/div>\n<div><code>tc filter add dev eth0 protocol ip parent 1: prio 50 u32 match ip dst 0.0.0.0\/0\u00a0 flowid 1:10<\/code><\/div>\n<div><code># \u9ed8\u8ba4\u8ba9\u6240\u6709\u7684\u6d41\u91cf\u90fd\u4ece\u8fd9\u4e2a\u901a\u8fc7<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u53c2\u8003\uff1ahttp:\/\/blog.chinaunix.net\/u3\/94771\/showart_1906064.html<\/p>\n<p>http:\/\/liuleijsjx.javaeye.com\/blog\/402152<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.php-oa.com\/2009\/06\/23\/linux_tc.html \u516c\u53f8\u4e00\u53f0\u670d\u52a1\u5668, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":1,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":34,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions\/34"}],"wp:attachment":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}