|
最合理的ros动态限速脚本
网吧因客流比较大,所以网络流量变化也很大,单纯的单机限速,会造成大量的带宽被浪费掉.所以我们现在来考虑动态限速.
我们简单的分为4个限速阶段,以30M带宽为例.
1 不限速
2 单机2M限速
3 单机1M限速
4 单机512K限速
一 限速策略的创建需要分2步
1 建立新的队列类型
/queue type
add name="down_512k" kind=pcq pcq-rate=512000 pcq-limit=50 \
pcq-classifier=dst-address pcq-total-limit=2000
add name="down_1M" kind=pcq pcq-rate=1000000 pcq-limit=50 \
pcq-classifier=dst-address pcq-total-limit=2000
add name="down_2M" kind=pcq pcq-rate=2000000 pcq-limit=50 \
pcq-classifier=dst-address pcq-total-limit=2000
add name="up_512K" kind=pcq pcq-rate=512000 pcq-limit=50 \
pcq-classifier=src-address pcq-total-limit=2000
add name="up_1M" kind=pcq pcq-rate=1000000 pcq-limit=50 \
pcq-classifier=src-address pcq-total-limit=2000
add name="up_2M" kind=pcq pcq-rate=2000000 pcq-limit=50 \
pcq-classifier=src-address pcq-total-limit=2000
2 建立新的简单队列
简单队列的顺序一定要注意:按照512K在上,2M在下的原则排序(先小后大).因为此队列的执行原则是,先执行最上面的,后面的将被抛弃.
/ queue simple
add name="PCQ_512K" dst-address=192.168.0.0/24 interface=Lan parent=none \
direction=both priority=8 queue=down_512k/up_512K limit-at=0/0 \
max-limit=0/0 total-queue=default-small disabled=yes
add name="PCQ_1M" dst-address=192.168.0.0/24 interface=Lan parent=none \
direction=both priority=8 queue=down_1M/up_1M limit-at=0/0 max-limit=0/0 \
total-queue=default-small disabled=yes
add name="PCQ_2M" dst-address=192.168.0.0/24 interface=Lan parent=none \
direction=both priority=8 queue=down_2M/up_2M limit-at=0/0 max-limit=0/0 \
total-queue=default-small disabled=yes
二 脚本的制作
实际就是简单的允许某策略或不允许某策略,类似在winbox选中某策略,并点叉号或对号.这里操作的是前面建立的简单队列.来达到限速策略的开与关.
/ system script
add name="off512k" source="/queue sim disable PCQ_512k" \
policy=ftp,reboot,read,write,policy,test,winbox,password
add name="on512k" source="/queue sim enable PCQ_512k" \
policy=ftp,reboot,read,write,policy,test,winbox,password
add name="off1m" source="/queue sim disable PCQ_1M" \
policy=ftp,reboot,read,write,policy,test,winbox,password
add name="on1m" source="/queue sim enable PCQ_1M" \
policy=ftp,reboot,read,write,policy,test,winbox,password
add name="off2m" source="/queue sim disable PCQ_2M" \
policy=ftp,reboot,read,write,policy,test,winbox,password
add name="on2m" source="/queue sim enable PCQ_2M" \
policy=ftp,reboot,read,write,policy,test,winbox,password
三 流量监控
我们使用ROS自带的工具"通信监控"(tool traffic-monitor)来监视我们的网络流量.当流量达到一定数值,会自动运行前面制作的脚本.请注意:接口一定要选择你的外网网卡.
这里的数据可根据实际情况修改,我是以自己30M带宽为例。
1 小于5M 执行off2m脚本,关闭PCQ_2M策略,效果不限速
2 小于10M 执行off1m脚本,关闭PCQ_1M策略,效果限速2M
3 小于17M 执行off512脚本,关闭PCQ_512策略,效果限速1M
4 大于13M 执行on1m脚本,开启PCQ_1M策略,效果限速1M
5 大于8M 执行on2m脚本,开启PCQ_2M策略,效果限速2M
6 大于20M 执行on512脚本,开启PCQ_512策略,效果限速512K
/ tool traffic-monitor
add name="on512K" interface=Wan traffic=received trigger=above \
threshold=20000000 on-event=on512k comment=" 20M 512K " \
disabled=no
add name="off512K" interface=Wan traffic=received trigger=below \
threshold=17000000 on-event=off512k \
comment=" 17M 512K 1M " disabled=no
add name="on1M" interface=Wan traffic=received trigger=above \
threshold=13000000 on-event=on1m comment=" 13M 1M " \
disabled=no
add name="off1M" interface=Wan traffic=received trigger=below \
threshold=10000000 on-event=off1m \
comment=" 10M 1M 2M " disabled=no
add name="off2m" interface=Wan traffic=received trigger=below \
threshold=5000000 on-event=off2m \
comment=" 5M 2M " disabled=no
add name="on2m" interface=Wan traffic=received trigger=above threshold=8000000 \
on-event=on2m comment=" 8M 2M " disabled=no
红色"Wan":表示外网接口网卡名,根据实际情况修改.
兰色部分为简单队列(queue simple)中策略的名称(可自行修改其他名字),但必须和脚本中的相互对应,不然会无法完成策略允许和不允许的操作.
绿色部分为角本的名称,也可自行修改其他名字,但是必须和流量监控中的相互对应,如果这里出错,则直接无法执行脚本. |
评分
-
查看全部评分
|