如何使用shell限制指定用户shell程序的网络带宽

来源:互联网 发布:淘宝贷款突然没有了 编辑:程序博客网 时间:2024/05/12 15:56

在运维工作中,会遇到需要限制shell应用程序(比如wget 、crul、ftp、sftp等)连接internet的网络带宽问题。如何在不使用复杂的firewall规则情况下设置网络带宽呢。

工具trickle可以实现这个功能,

系统 Debian/ubuntu linux 使用apt-get方法即可安装

   $ sudo apt-get install trickle

系统CentOS / RHEL / Fedora Linux 安装

1. 安装epel源 地址http://www.cyberciti.biz/faq/fedora-sl-centos-redhat6-enable-epel-repo/

2. 安装# yum install trickle

使用方法

trickle -u uploadLimit programtrickle -d downloadLimit programtrickle -u {UPLOAD_LIMIT} -d {DOWNLOAD_LIMIT} program-binary
例如限制ftp 上传下载速度  trickle -u 100 -d 50 ftp  

限制wget 下载速度 trickle -d 50 wget http://ftp.openbsd.org/pub/OpenBSD/5.2/i386/install52.iso

限制所有shell程序的带宽方法 trickle -d 500 -u 250 bash 或者trickle -d 500 -u 250 ksh


trickle的参数使用方法

-h           Help (this)
-v           Increase verbosity level
-V           Print trickle version
-s           Run trickle in standalone mode independent of trickled
-d     Set maximum cumulative download rate to  KB/s
-u     Set maximum cumulative upload rate to  KB/s
-w   Set window length to  KB
-t  Set default smoothing time to  s
-l   Set default smoothing length to  KB
-n     Use trickled socket name 
-L       Set latency to  milliseconds

原创粉丝点击