sky_cheng

导航

 

一、安装epel源

yum install epel-release

二、查看是否安装成功

Complete!
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total 56
-rw-r--r--  1 root root 2323 Oct 26 14:38 CentOS-Base.repo
-rw-r--r--  1 root root 1664 Oct 26 14:34 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 Nov 23  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Nov 23  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Nov 23  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Nov 23  2018 CentOS-Media.repo
-rw-r--r--  1 root root  998 Dec 11  2018 CentOS-SCLo-scl.repo
-rw-r--r--  1 root root  971 Oct 29  2018 CentOS-SCLo-scl-rh.repo
-rw-r--r--. 1 root root 1331 Nov 23  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23  2018 CentOS-Vault.repo
-rw-r--r--  1 root root  978 Jun 29 16:50 dell-system-update.repo
-rw-r--r--  1 root root  951 Oct  3  2017 epel.repo
-rw-r--r--  1 root root 1050 Oct  3  2017 epel-testing.repo

三、安装trickle

[root@localhost yum.repos.d]# yum install trickle

四、运行trickle

[root@localhost yum.repos.d]# trickle -help
Usage: trickle [-hvVs] [-d <rate>] [-u <rate>] [-w <length>] [-t <seconds>]
               [-l <length>] [-n <path>] command ...
        -h           Help (this)
        -v           Increase verbosity level
        -V           Print trickle version
        -s           Run trickle in standalone mode independent of trickled
        -d <rate>    Set maximum cumulative download rate to <rate> KB/s
        -u <rate>    Set maximum cumulative upload rate to <rate> KB/s
        -w <length>  Set window length to <length> KB 
        -t <seconds> Set default smoothing time to <seconds> s
        -l <length>  Set default smoothing length to <length> KB
        -n <path>    Use trickled socket name <path>
        -L <ms>      Set latency to <ms> milliseconds
[root@localhost yum.repos.d]# 

-d <rate> 设置最大累计下载速率为 <rate> KB/s 

-u <rate> 设置最大累计上传速度为 <rate> KB/s 

-w <length> 设置窗口长度为 <length> KB 。默认512KB。 

-t <seconds> 设置默认的平滑时间 <seconds> s 。平滑时间决定多少时间间隔trickle将尝试让应用程序传输数据。较小的值(0.1 - 1秒)会导致更连续(平滑)会话,非常适合于交互式应用。而较大的值(1 - 10秒)可能会产生一阵阵的发送和接收数据,对需要大量带宽的应用程序更好。 

-l <length> 设置默认的平滑长度 <length> KB 。 默认10 KB。 

-n <path> 指定trickled socket名称 <path> 。 默认/tmp/.trickled.sock 。 

-L <ms> 设置延时。

Trickle通过控制socket数据读写量来控制和限制应用的上传/下载速度。它使用另一个版本的BSD套接字API,但是区别是trickle还管理socket调用。要注意的是trickle使用动态链接和加载,所以它只对于使用"Glibc库"的程序有用。由于trickle可以设置数据在socket上的传输延迟,所以它可以用来限制一个应用的网络带宽。Trickle不能用于限制使用UDP协议的应用的带宽,它只可用于TCP连接,但是你要知道它也并不是对所有的TCP。

可以通过ldd命令来查看某个应用程序是否使用了libc.so库。如果应用程序使用了这个库,就可以用trickle来限制网络带宽,否则不行

[root@localhost yum.repos.d]# ldd /usr/bin/wget |grep libc.so     
        libc.so.6 => /lib64/libc.so.6 (0x00007f9231c28000)
[root@localhost yum.repos.d]# 

五、限制wget的下载速度为10KB/S

[root@localhost src]# trickle -d 10 wget http://www.keepalived.org/software/keepalived-1.3.4.tar.gz --no-check-certificate
trickle: Could not reach trickled, working independently: No such file or directory
--2021-12-03 11:09:25--  http://www.keepalived.org/software/keepalived-1.3.4.tar.gz
Resolving www.keepalived.org (www.keepalived.org)... 91.121.30.175
Connecting to www.keepalived.org (www.keepalived.org)|91.121.30.175|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.keepalived.org/software/keepalived-1.3.4.tar.gz [following]
--2021-12-03 11:09:25--  https://www.keepalived.org/software/keepalived-1.3.4.tar.gz
Connecting to www.keepalived.org (www.keepalived.org)|91.121.30.175|:443... connected.
WARNING: cannot verify www.keepalived.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
  Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 655420 (640K) [application/octet-stream]
Saving to: ‘keepalived-1.3.4.tar.gz.348% [===========================================>                                               ] 318,981     11.4KB/s  eta 29s 

可以看到下载速度控制在10KB左右

不使用trickle进行wget下载

[root@localhost src]# wget http://www.keepalived.org/software/keepalived-1.3.4.tar.gz --no-check-certificate              
--2021-12-03 11:11:00--  http://www.keepalived.org/software/keepalived-1.3.4.tar.gz
Resolving www.keepalived.org (www.keepalived.org)... 91.121.30.175
Connecting to www.keepalived.org (www.keepalived.org)|91.121.30.175|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.keepalived.org/software/keepalived-1.3.4.tar.gz [following]
--2021-12-03 11:11:00--  https://www.keepalived.org/software/keepalived-1.3.4.tar.gz
Connecting to www.keepalived.org (www.keepalived.org)|91.121.30.175|:443... connected.
WARNING: cannot verify www.keepalived.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
  Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 655420 (640K) [application/octet-stream]
Saving to: ‘keepalived-1.3.4.tar.gz.456% [==================================================>                                        ] 368,133     99.0KB/s  eta 4s     

下载速度到100KB左右

六、限制一个shell的网络带宽下载10KB/S,上传10KB/S

[root@localhost src]# trickle -d 10 -u 10 -s bash
[root@localhost src]#  wget http://www.keepalived.org/software/keepalived-1.3.4.tar.gz --no-check-certificate 
--2021-12-03 11:14:15--  http://www.keepalived.org/software/keepalived-1.3.4.tar.gz
Resolving www.keepalived.org (www.keepalived.org)... 91.121.30.175, 2001:41d0:1:71af::1
Connecting to www.keepalived.org (www.keepalived.org)|91.121.30.175|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.keepalived.org/software/keepalived-1.3.4.tar.gz [following]
--2021-12-03 11:14:15--  https://www.keepalived.org/software/keepalived-1.3.4.tar.gz
Connecting to www.keepalived.org (www.keepalived.org)|91.121.30.175|:443... connected.
WARNING: cannot verify www.keepalived.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
  Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 655420 (640K) [application/octet-stream]
Saving to: ‘keepalived-1.3.4.tar.gz.518% [===============>                                                                           ] 122,373     12.4KB/s  eta 42s   

可以看到限速为10KB左右

 

posted on 2021-12-03 11:15  sky_cheng  阅读(1351)  评论(0编辑  收藏  举报