类别:ROS / 日期:2021-03-12 / 浏览:1011 / 评论:0

首先说说我为什么要做这个限速,一般来说,PCQ限速对于某些带宽不是很足的网吧来说,确实有点问题,必须你网吧只有15M的光纤,如果你做PCQ限速2M吧(我想2M对于100台机器来说的网吧已经是最大限度了),PCQ开启设置为14M吧,关闭设置为6M!如果有一个人用讯雷下载东西的话。网吧15马上占满,PCQ就会开启,但一旦开启后。你网速就会变到6M以下,那么PCQ就在那里不停的关闭和开启了,这样不单达不到智能限速的效果。还会增加ROS的负担!CPU占用。。所以我就一直想把智能和普通限速做在一起,让讯雷或者其他下载不会乱触发PCQ的流量,但最终还是失败了!

不过得到网盟热心朋友的启发,我想出了一个既可以动态限速,也可以静态限速的方法!例如,还是15M的光纤,100台机器的网吧。我静态设置为3M,这样的话,正常来说。4个人下载东西的话,也只占12M,那么还剩3M,足够其他玩Q和打网游的机器了!

但如果5个人下载的话?怎么办?带宽马上到了15M了。呵呵,那其他玩网游的肯定会卡死!

不用怕,我智能设置为大于14M触发另一个脚本,脚本的内容大概就是关闭原来的3M静态限速,开启1.5M的静态限速,这样一算,1.5*5=7.5M了,再加上玩网游的人,基本上就稳定在10M左右了!

然后再设置一个脚本,当总流量少于6M的话(也就算没那么多人下载了,流量下来了)那么1.5M的静态限速脚本就会自动关闭,又打开了本来3M的限速了!

基本上原理就是这样。通过这个原理,网吧宽带利用就会越来越合理!

不过。这个方法还是有一定的局限的,如果你还是用433的CPU,建议还是算了吧。呵呵,因为在2秒内完成脚本转换需要开启254条限速和开始254条限速,所以对于ROS的配置还是要讲究一点的。我的测试是在C1.8 256M内存的状态下测试的。脚本自动切换的时候ROS的CPU占用会突然升到100,但是并不影响网络,虽然在ROS上看是断流了一两秒,但实际上,我ping着163的IP并没有延时突然升高,玩网游的人也不会卡一两秒!可以说是完美切换了!

=====================================================

下面是 我叫阿当 的网友发出来的智能限速脚本,通过这个脚本,如果有心看我的文章的人应该可以写出我的智能脚本了!

动态限速

ROS动态限速(检测外网总速度进行限速开关)废话不说先看脚本原理:

以下操作全部在WINBOX界面里完成

介绍:可以实现在总速度不超过9M的情况下自动关闭所有生成的限速规则在总速度超过18M的时候自动启动所有生成的限速规则。

说明:在输入脚本内容时不要把两边的()带上,那个是为了区分非脚本字符。

         总速度=你的外网网卡当前速度。

打开 /system/scripts

脚本:

:for aaa from 1 to 254 do={/queue simple add name=(ip_ . $aaa) dst-address=(192.168.0. . $aaa) interface=wan max-limit=256000/800000 burst-limit=1000000/3000000 burst-threshold=128000/512000 burst-time=30s/1m     }

上面是生成限速树,对网段内所有IP的限速列表!

下面进入正题:

脚本名:node_on

脚本内容:(:for aaa from 1 to 254 do={/queue sim en [find name=(ip_ . $aaa)]})

脚本名:node_off

脚本内容:(:for aaa from 1 to 254 do={/queue sim dis [find name=(ip_ . $aaa)]})

scripts(脚本部分)以完成

打开 /tools/traffic monitor

新建:

名:node_18M     traffic=received     trigger=above     on event=node_on threshold:18000000

新建:

名:node_9M     traffic=received     trigger=below     on event=node_off     threshold:9000000

在输入脚本内容时不要把两边的()带上,那个是为了区分非脚本字符。

==============================================================

至于我的脚本嘛,如果这个帖子顶到200贴,我就发出来!

这几天为了优化上面脚本,苦想了好久,终于又找出了另一个方法来实验动静结合,而且不会占用ROS的CPU。呵呵。累呀!

动静结合智能限速脚本

由时间段启发不同的限速的脚本

脚本在二楼!

这个是我进网盟这么久以来第一个原创帖子,在网盟收益不浅,终于有机会贡献网盟了!

这个是完整脚本,15M为例 静态是3M,达到14.8M后启用动态是1.5M!

详细解说我迟点再注明,现在没时间!

:for aaa from 1 to 254 do={/queue simple add name=(PC . $aaa) dst-address=(192.168.0. . $aaa) limit-at=500000/500000 max-limit=3000000/3000000}

这个是建立静态限速,1to254 改为你内网的IP!比如 2 to 120!   192.168.0. 这里改为你的IP段!      limit-at=500000/500000  是平均网速500K,max-limit=3000000/3000000 是普通限速3M!

注意一下,,在网盟里,包括很多高手都把ROS的算法搞错了,在这里我抖正一下,ROS不是1KB=8Kbit!  而是 1000=1K  1000000=1M


/ ip firewall mangle

add chain=prerouting action=mark-packet new-packet-mark=all-mark \

    passthrough=yes comment="" disabled=no


这个是固定脚本!


/ queue type

add name="PCQ-up" kind=pcq pcq-rate=1500000 pcq-limit=50 \

    pcq-classifier=src-address pcq-total-limit=2000

add name="PCQ-down" kind=pcq pcq-rate=1500000 pcq-limit=50 \

    pcq-classifier=dst-address pcq-total-limit=2000


这里把1500000改为你动态限速时的全网上传速度和下载速度!其他不要改!这里是1.5M!


/ queue simple

add name="PCQ" target-addresses=192.168.0.0/24 dst-address=0.0.0.0/0 \

    interface=all parent=none packet-marks=all-mark direction=both priority=1 \

    queue=PCQ-up/PCQ-down limit-at=0/0 max-limit=15000000/15000000 \

    total-queue=default-small disabled=yes


到这里就是建立动态限速的策略了!192.168.0.0/24 改为你IP段!max-limit=15000000/15000000 这里是你总宽带,电信给你多少就填多少!其他不用改,,因为需要转跳到上面的!


/ system script

add name="PCQON" source=":if \(\[ /queue sim get \[/queue sim find \

    name=\"PCQ\"\] disable \]=true \) do={/queue sim enable PCQ}" \

    policy=ftp,reboot,read,write,policy,test,winbox,password

add name="PCQOFF" source=":if \(\[ /queue sim get \[/queue sim find \

    name=\"PCQ\"\] disable \]=false \) do={/queue sim disable PCQ}" \

    policy=ftp,reboot,read,write,policy,test,winbox,password


这个是启发脚本,就是启发动态和关闭动态的脚本!直接复制!


/ tool traffic-monitor

add name="PCQON" interface=WAN traffic=received trigger=above \

    threshold=14800000 on-event=PCQON comment="" disabled=no

add name="PCQOFF" interface=WAN traffic=received trigger=below \

    threshold=5000000 on-event=PCQOFF comment="" disabled=no


这个是流量监控,我有15M设置是14.8M启发,足够了。不会延时或者怎么的,不建议改得太少。threshold=5000000是少于5M时关闭动态!这个自己掌握好!多试试!

另外注意的是!interface=WAN   把WAN改成你外网的网卡!

上面的每一段都需要,少一段这个脚本就不完整!不然没效果不要说我!

关于时间段来启发脚本我迟点发出来,,最近实在忙,聪明的你估计也能做出来,只需要改最后一段就OK了!受之网盟,反哺网盟!

以上是天下网盟转过来的,因为有启发性。

==================

以下是本人已用的PCQ脚本

仅供个人参考

我的使用环境

电信

2:00-18:00 10M

18:00-2:00   20M

ROS   2927


/ ip firewall mangle

add chain=prerouting action=mark-packet new-packet-mark=all-mark passthrough=no


/ queue type


add name="pcq-up" kind=pcq pcq-rate=128000 pcq-limit=50 \

    pcq-classifier=src-address pcq-total-limit=2000

add name="pcq-down" kind=pcq pcq-rate=512000 pcq-limit=50 \

    pcq-classifier=dst-address pcq-total-limit=2000

add name="pcq-down20" kind=pcq pcq-rate=768000 pcq-limit=50 \

    pcq-classifier=dst-address pcq-total-limit=2000

add name="pcq-up20" kind=pcq pcq-rate=256000 pcq-limit=50 \

    pcq-classifier=src-address pcq-total-limit=2000


/ queue tree

add name="pcqdown" parent=global-in packet-mark=all-mark limit-at=0 \

    queue=pcq-down priority=8 max-limit=0 burst-limit=0 burst-threshold=0 \

    burst-time=0s disabled=yes

add name="pcqup" parent=global-out packet-mark=all-mark limit-at=0 \

    queue=pcq-up priority=8 max-limit=0 burst-limit=0 burst-threshold=0 \

    burst-time=0s disabled=yes

add name="pcqup20" parent=global-out packet-mark=all-mark limit-at=0 \

    queue=pcq-up20 priority=8 max-limit=0 burst-limit=0 burst-threshold=0 \

    burst-time=0s disabled=yes

add name="pcqdown20" parent=global-in packet-mark=all-mark limit-at=0 \

    queue=pcq-down20 priority=8 max-limit=0 burst-limit=0 burst-threshold=0 \

    burst-time=0s disabled=yes


/ tool traffic-monitor

add name="pcqon" interface=WAN traffic=received trigger=above threshold=9000000 on-event=pcqon comment="" disabled=no

add name="pcqoff" interface=WAN traffic=received trigger=below threshold=5000000 on-event=pcqoff comment="" disabled=no

add name="pcqoff20" interface=WAN traffic=received trigger=below threshold=15000000 on-event=pcqoff20 comment="" disabled=no

add name="pcqon20" interface=WAN traffic=received trigger=above threshold=19000000 on-event=pcqon20 comment="" disabled=no


/ system script


add name="pcqon" source="/queue tree enable pcqdown

/queue tree enable pcqup" policy=ftp,reboot,read,write,policy,test,winbox,password


add name="pcqoff" source="/queue tree disable pcqdown

/queue tree disable pcqup" policy=ftp,reboot,read,write,policy,test,winbox,password


add name="pcqon20" source="/queue tree enable pcqdown20

/queue tree enable pcqup20" policy=ftp,reboot,read,write,policy,test,winbox,password


add name="pcqoff20" source="/queue tree disable pcqdown20

/queue tree disable pcqup20" policy=ftp,reboot,read,write,policy,test,winbox,password


add name="19D" source="/tool traffic-monitor set [find name=pcqoff] disabled=yes

/tool traffic-monitor set [find name=pcqon] disabled=yes

/queue tree set [find name=pcqdown] disabled=yes

/queue tree set [find name=pcqup] disabled=yes

/tool traffic-monitor set [find name=pcqoff20] disabled=no

/tool traffic-monitor set [find name=pcqon20] disabled=no

/queue tree set [find name=pcqdown20] disabled=yes

/queue tree set [find name=pcqup20] disabled=yes" policy=ftp,reboot,read,write,policy,test,winbox,password


add name="2D" source="/tool traffic-monitor set [find name=pcqoff] disabled=no

/tool traffic-monitor set [find name=pcqon] disabled=no

/queue tree set [find name=pcqdown] disabled=no

/queue tree set [find name=pcqup] disabled=no

/tool traffic-monitor set [find name=pcqoff20] disabled=yes

/tool traffic-monitor set [find name=pcqon20] disabled=yes

/queue tree set [find name=pcqdown20] disabled=yes

/queue tree set [find name=pcqup20] disabled=yes" policy=ftp,reboot,read,write,policy,test,winbox,password


脚本同上


/ system script

\n/queue tree enable \e="/queue tree enable pcqdown

    pcqup" policy=ftp,reboot,read,write,policy,test,winbox,password

\n/queue tree disable \e="/queue tree disable pcqdown

    pcqup" policy=ftp,reboot,read,write,policy,test,winbox,password

\n/queue tree \f20" source="/queue tree disable pcqdown20

    disable pcqup20" policy=ftp,reboot,read,write,policy,test,winbox,password

\n/queue tree enable \rce="/queue tree enable pcqdown20

    pcqup20" policy=ftp,reboot,read,write,policy,test,winbox,password

add name="18D" source="/tool traffic-monitor set \[find name=pcqoff\] \

\n/tool traffic-monitor set \[find name=pcqon\] \

\n/queue \ree set \[find name=pcqdown\] disabled=yes

\n/tool traffic-monitor set \p\] disabled=yes

\n/tool traffic-monitor set \[find \no

\n/queue tree set \[find name=pcqdown20\] \

\n/queue tree set \[find name=pcqup20\] disabled=yes" \

    policy=ftp,reboot,read,write,policy,test,winbox,password

add name="2D" source="/tool traffic-monitor set \[find name=pcqoff\] \

\n/tool traffic-monitor set \[find name=pcqon\] \

\n/queue \ree set \[find name=pcqdown\] disabled=no

\n/tool traffic-monitor set \p\] disabled=no

\n/tool traffic-monitor set \[find \yes

\n/queue tree set \[find name=pcqdown20\] \

\n/queue tree set \[find name=pcqup20\] disabled=yes" \

    policy=ftp,reboot,read,write,policy,test,winbox,password


限时脚本

/ system scheduler

add name="18D" on-event=18D start-date=aug/23/2007 start-time=18:00:00 \

    interval=1d comment="" disabled=no

add name="2D" on-event=2D start-date=aug/23/2007 start-time=02:00:00 \

    interval=1d comment="" disabled=no

完成。

打赏

感谢您的赞助~

打开支付宝扫一扫,即可进行扫码打赏哦~

版权声明 : 本文未使用任何知识共享协议授权,您可以任何形式自由转载或使用。

 可能感兴趣的文章