WonderShaper是一個用於對特定網卡進行帶寬限速的腳本,它封裝了linux的tc命令,可是使用起來更加簡單和方便,若是你對限速要求很少,能夠用wondershaper知足你大部分需求。linux
使用場景
像有些作流量控制的軟件都會涉及到此類限速場景,好比測試一些離線上傳功能,在網卡帶寬較小的狀況下,是否可以優雅處理完全部離線數據上報。github
弱網測試,好比手機鏈接linux機器的共享網絡,能夠經過這種方式限速作弱網測試vim
安裝
Ubuntu:微信
sudo apt-get updatesudo apt install -y wondersharper
Centos網絡
yum install epel-release -ysudo yum install -y wondersharper
使用二進制運維
1)下載wondershaper工程ssh
git clone https:cd wondershaper #直接運行wondershaper ./wondershaper
2)全局安裝wondershaper(可選)ide
cd wondershapersudo make install幫助
輸入:./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 //指定網卡接口,經過ifconifg或者ip show addr查看:好比eth0-d <rate> Set maximum download rate (in Kbps) and/or //限制下載的速度-u <rate> Set maximum upload rate (in Kbps) //限制上傳的速度-p Use presets in "/etc/systemd/wondershaper.conf"-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: //針對以上示例給出的example wondershaper -a eth0 -d 1024 -u 512 //限制eth0上行速度512kbps,下行速度1024kbpswondershaper -a eth0 -u 512 //僅限制eth0上行速度512kbpswondershaper -c -a eth0 //清除爲eth0設定的wondershaper的相關規則例子
1.限制eth0的上行帶寬爲100Mbps,下行帶寬爲100Mbps
wondershaper -a eth1 -d 94000 -u 94000
2.限制eth0的上行帶寬爲100Mbps
wondershaper -a eth1 -u 94000
3.清理eth0上的帶寬限制規則
wondershaper -c -a eth0
4.查看eth0當前的狀態
wondershaper -s -a eth0
5.使用systemd管理wondershaper
1) 安裝到系統目錄:sudo make install
如圖所示,wondershaper一鍵被添加到systemd進行管理了。
2)相關操做
#啓動限流操做 service wondershaper start #中止限流操做 service wondershaper stop
3)設置相關規則
sudo vim /etc/systemd/wondershaper.conf,修改以下內容:
[wondershaper] # Adapter IFACE="eth0" //至關於命令中的-a對應值設置 # Download rate in Kbps DSPEED="2048" //至關於命令中的-d對應值設置 # Upload rate in Kbps USPEED="512" //至關於命令中的-u對應值設置FAQ
執行命令報錯:Operation not permitted
命令加上sudo,提高權限
快送門:各類學習資料與大廠招聘
博主:測試生財(一個不爲996而996的測開碼農)
座右銘:專一測試開發與自動化運維,努力讀書思考寫做,爲內卷的人生奠基財務自由。
內容範疇:技術提高,職場雜談,事業發展,閱讀寫做,投資理財,健康人生。
csdn:https://blog.csdn.net/ccgshigao
博客園:https://www.cnblogs.com/qa-freeroad/
51cto:https://blog.51cto.com/14900374
微信公衆號:測試生財(按期分享獨家內容和資源)