网卡限速工具之WonderShaper

1.什么是WonderShaper

WonderShaper是用来对特定网卡进行快速限速的工具,它实际是对Linux的tc命令进行封装后的shell脚本,所以使用成本比tc更低,更容易上手,以下配合测速工具speedtest一起使用

2.如何安装WonderShaper

#直接拉取wondershaper,开箱即用
git clone https://github.com/magnific0/wondershaper.git

root@****-5491:/home/soft/wondershaper# ./wondershaper -v
Version 1.4.1
root@****-5491:/home/soft/wondershaper

#网速测试工具speedtest安装(Ubuntu)
apt install speedtest-cli
--yum install speedtest-cli (centos) 

3.WonderShaper使用帮助

root@****-5491:/home/soft/wondershaper# ./wondershaper -h
USAGE: ./wondershaper [-hcs] [-a <adapter>] [-d <rate>] [-u <rate>]

Limit the bandwidth of an adapter

OPTIONS:
   -h           Show this message 【帮助信息】
   -a <adapter> Set the adapter  【指定网卡接口】
   -d <rate>    Set maximum download rate (in Kbps) and/or 【限制下载速度(Kbps)】
   -u <rate>    Set maximum upload rate (in Kbps)   【限制上传速度(Kbps)】
   -p           Use presets in "/etc/systemd/wondershaper.conf"
   -f <file>    Use alternative preset file
   -c           Clear the limits from adapter 【清除指定网卡规则,用于取消限速】
   -s           Show the current status of adapter 【显示当前网卡的状态】
   -v           Show the current version  【显示当前版本】

   Configure HIPRIODST in "/etc/systemd/wondershaper.conf" for hosts
   requiring high priority i.e. in case ssh uses dport 443.

MODES:
   wondershaper -a <adapter> -d <rate> -u <rate>
   wondershaper -c -a <adapter>
   wondershaper -s -a <adapter>

EXAMPLES: 【使用示例】
   wondershaper -a eth0 -d 1024 -u 512  【设置网卡eth0的上行速度为512kbps,下行速度为1024kbps】
   wondershaper -a eth0 -u 512 【只设置上行速度为512kbps】
   wondershaper -c -a eth0 【清除网卡eth0的规则】
   wondershaper -p -f foo.conf 【设置指定的配置文件】

4.WonderShaper使用示例

4.1查看网卡状态

root@****-5491:/home/soft/wondershaperifconfig eno1
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.5.103  netmask 255.255.255.0  broadcast 192.168.5.255
        inet6 fe80::2c93:21f9:1931:304  prefixlen 64  scopeid 0x20<link>
        ether c8:f7:50:7e:50:48  txqueuelen 1000  (Ethernet)
        RX packets 7748809  bytes 1034513376 (1.0 GB)
        RX errors 0  dropped 439  overruns 0  frame 0
        TX packets 15528838  bytes 4784318169 (4.7 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0x91500000-91520000 
        
root@****-5491:/home/soft/wondershaper# ./wondershaper -s -a eno1
qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
 Sent 4528052159 bytes 14890189 pkt (dropped 0, overlimits 0 requeues 4224) 
 backlog 0b 0p requeues 4224
  maxpacket 66616 drop_overlimit 0 new_flow_count 35953 ecn_mark 0
  new_flows_len 0 old_flows_len 0

--测试网速
root@****-5491:/home/soft/wondershaperspeedtest
Retrieving speedtest.net configuration...
Testing from China Telecom (120.36.98.11)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Fuzhou China Mobile,Fujian (Fuzhou) [589.19 km]: 14.449 ms
Testing download speed................................................................................
-- 下载网速是171.43 Mbit/s,
Download: 171.43 Mbit/s
Testing upload speed......................................................................................................
-- 上传网速是4.15 Mbit/s
Upload: 4.15 Mbit/s

4.2限制网卡速度(单位Kbps)

-- 下行2048kbps=2 Mbit/s,上行 1024kbps=1 Mbit/s
root@****-5491:/home/soft/wondershaper# ./wondershaper -a eno1 -d 2048 -u 1024
--测试网速
root@****e-5491:/home/soft/wondershaperspeedtest
Retrieving speedtest.net configuration...
Testing from China Telecom (120.36.98.11)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Far EasTone Telecom (Miaoli City) [722.10 km]: 174.383 ms
Testing download speed................................................................................
-- 下行速度
Download: 1.80 Mbit/s
Testing upload speed......................................................................................................
--上行速度
Upload: 1.28 Mbit/s
root@****-5491:/home/soft/wondershaper

4.3取消限速

--取消限速
root@****-5491:/home/soft/wondershaper./wondershaper -c -a eno1
-- 查看网卡状态
root@****-5491:/home/soft/wondershaper./wondershaper -s -a eno1
qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
 Sent 123022 bytes 471 pkt (dropped 0, overlimits 0 requeues 0) 
 backlog 0b 0p requeues 0
  maxpacket 0 drop_overlimit 0 new_flow_count 0 ecn_mark 0
  new_flows_len 0 old_flows_len 0

-- 测试网速
root@****-5491:/home/soft/wondershaper# speedtest
Retrieving speedtest.net configuration...
Testing from China Telecom (120.36.98.11)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Far EasTone Telecom (Miaoli City) [722.10 km]: 173.886 ms
Testing download speed................................................................................
Download: 11.29 Mbit/s
Testing upload speed......................................................................................................
Upload: 2.93 Mbit/s
root@****-5491:/home/soft/wondershaper#

5.WonderShaper在测试中的应用

测试项目:某内部数据库迁移工具

测试目的:数据迁移中,对目标端进行限速,当取消限速后,传输速度可以恢复

测试步骤:起迁移进程,在目标端服务器上用WonderShaper工具进行限速:

-- 只限制下行速度
[#22#root@**** ~/wondershaper]22  ./wondershaper -a enp0s3  -d 100

测试结果:限速后,写目标库单位写入行数和单位写入字节数都急剧下降,如下图:

网卡限速工具之WonderShaper
取消限速,恢复网络后,传输速率慢慢恢复:
网卡限速工具之WonderShaper
网卡限速工具之WonderShaper

6.网速单位转换

1KB/s = 8kbps = 8kb/s
比如一般100M的宽带,实际是100Mbps=(100/8) MB/s=12.5 MB/s

7.总结

使用WonderShaper对网卡进行限速,在测试时可以针对性的指定网卡,指定上传速度或者指定下载速度,在测试中上传和下载速度是互不影响的,可以只限制一方;且WonderShaper工具操作简单好入手,是个不错的工具。

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/9778

(0)
杰斯的头像杰斯
上一篇 2023年9月28日 上午2:17
下一篇 2023年10月8日 下午5:20

相关推荐

  • Grafana如何自定义告警消息

    以下是一个使用pushgateway获取磁盘健康状态的报警消息。 可以看到,grafana默认的模板有很多无用内容。 获取数据 在grafana的报警预览中,只有state和info两个列显示。 info内容看起来是一个键值对类型的数据,其实只是一个字符串,无法从中获取我们想要的键值对。 我们通过go templete语法,提取字符串里的数据。 将该内容填写…

    2022年12月8日
    1.9K00
  • 宝塔安装composer,出现 putenv() has been disabled for security reasons

    在宝塔安装composer,出现 putenv() has been disabled for security reasons 方法一:打开配置文件php.ini,找到disable_functions字符串,把后面的putenv删除即可正常安装。 方法二:宝塔面板的话,我的版本是7.2,就找到 PHP7.2管理→禁用函数→删除putenv,重载配置文件后…

    2023年2月14日
    56400
  • ubuntu20.04 删除linux中软raid的方法

    取消软件 RAID 可能涉及到几个步骤,具体取决于你的操作系统和使用的软件。在大多数 Linux 系统中,mdadm 是用于管理软件 RAID 的常见工具。以下是在 Linux 中取消软件 RAID 的一般步骤: 请注意:在执行这些步骤之前,请确保你已经备份了所有重要数据,因为取消 RAID 可能会导致数据丢失。 查看当前 RAID 状态: 使用以下命令查看…

    2023年11月24日
    20900
  • redis 集群 CLUSTERDOWN Hash slot not served 报错解决思路

    背景:  因机房故障,导致redis-cluster 集群中 有个节点 down 了 ,再从新拉起节点加入集群后,就没在意 过来小许,服务器磁盘告警来了,我看了下 应用服务器上的tomcat 的日志,不停的刷,日志内容 报redis 错误, CLUSTERDOWN Hash slot not served 吓得我 立马 去 redis 集群上去 检…

    2023年5月16日
    35700
  • Linux下查找并删除挖矿程序实例

    症状表现 从外网连接服务器时,间接性断开特别频繁。在断开的时候,从内网也连接不上 排查方法 从链路等硬件方面去排查 通过zabbix监控的服务器的端口,发现这个服务器一直在间断性占用1000M带宽,实际客户购买的带宽15M,这就是客户间断性频繁断网的原因。 在排除了线路等相关问题后,将问题锁定在客户系统内。 在软件中排查 在Linux系统中,我们可以使用to…

    2022年6月14日
    65500

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信
网卡限速工具之WonderShaper