电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 在线教程-> 网管专栏
ProFTPD和WU-FTP的BANDWIDTH控制-网管专栏,FTP服务
作者:网友供稿 点击:20
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 

在/etc/ftpaccess里面加上:
throughput /home/ftp * * 64000 0.5 *

意思是下载带宽对所有ip(最后那个*)限制在64k,每下一个文件速度减半(那个0
.5).

我用的是2.5.x,man page里面很全的.
用man ftpaccess就可以.:-)


◇ proftpd 流量控制
----------------------------------------------------------------------
----------发信人: charley.bbs@swallow.twbbs.org (喘气中...), 看板: lin
ux
标 题: proftpd 流量控制
发信站: 临风小□ bbs 站 (tue mar 9 15:55:30 1999) @cyndi.cis.nctu.edu
.tw
转信站: maxwell!bbs.ee.ntu!freebsd.ntu!news.cs.nthu!news.cis.nctu!wind

 

这是自己改的 proftpd 1.2.0pre2 流量控制的 patch.
需要原来 proftpd source!
相关程式可以在 ftp://swallow.twbbs.org/linux/ftp/ 下找到

用法:
1. 如果你的 proftpd-1.2.0pre2.tar.gz 解在 proftpd-1.2.0pre2/

将本 patch 放跟 proftpd-1.2.0pre2/ 同一层目录, 打
patch < proftpd-1.2.0pre2-bandwidth.patch
如果放在 proftpd-1.2.0pre2/ 下
patch -p1 < proftpd-1.2.0pre2-bandwidth.patch
2. 重新 make 你的 source!

系统设定:
1. 提供三个控制流量功能(只有下传)
可以设在 server config,,

bandwidth : 总频宽
maxbandwidth : 每线最大频宽
minbandwidth : 每线最小频宽

必需为整数,代表 位元组/秒(bytes/second)

三个功能的关系: minbandwidth > maxbandwidth > bandwidth

2. □例1.
设定 bandwidth 4096

如果有4人在线上,每个人的流量为 4096%424 位元组/秒


□例2.
设定 bandwidth 4096
maxbandwidth 3072

如果有1人在线上,每个人的流量为 3072 位元组/秒
如果有2人在线上,每个人的流量为 4096%2 48 位元组/秒

以下类推

□例3.
设定 bandwidth 3072
minbandwidth 1024

如果有1人在线上,每个人的流量为 3072 位元组/秒
如果有2人在线上,每个人的流量为 3072%236 位元组/秒

如果有3人在线上,每个人的流量为 3072%324 位元组/秒

如果有4人在线上,每个人的流量为 1024 位元组/秒
以下类推

详细的说明请看 patch 过的 mod_xfer.c

--- start proftpd-1.2.0pre2-bandwidth.patch ---

--- proftpd-1.2.0pre2.orig/modules/mod_xfer.c fri feb 19 15:11:11 19
99
+++ proftpd-1.2.0pre2/modules/mod_xfer.c mon feb 22 14:38:19 19
99
@@ -31,10 +31,140 @@
*
*/

+/********************************************************************
********
+ * title : bandwidth management
+ * file : mod_xfer.c (need orig source from proftpd-1.2.0pre2.
tar.gz)
+ * author : albert chiu (albert@swallow.twbbs.org.tw)
+ * date : 22 feb 1999
+ * version : 0.9p2
+ *
+ * description :
+ * provide bandwidth usage limitation on per connection.
+ *
+ * revision :
+ * ver 0.9p2
+ * - add bandwidth and minbandwidth.
+ * ver 0.9p1
+ * - fix unpredictable disconnect bugs.
+ * - port patch to proftpd-1.2.0pre2
+ * ver 0.9
+ * - first patch version base on proftpd-1.2.0pre1.
+ * - only include maxbandwidth.
+ *
+ ********************************************************************
*******
+ * copyright (c)1999 albert chiu ( chiu yang-li ). all rights reserve
d.
+ * modify for the proftpd group by :
+ *
+ * albert chiu
+ * albert@swallow.twbbs.org.tw
+ * http://swallow.twbbs.org.tw/~albert
+ *
+ * i get some idea and good function from apache module collection. i
d looked
+ * at mod_bandwidth, this one is almost what i want, so i use the ide
a and
+ * rewrite it for proftpd 1.2.0pre1.
+ * but i find the select() function which mod_bandwidth use is usuall
y bad
+ * performance, so i use setitimer() to replace it.
+ *
+ * you can get the collection from apache homepage (http://www.apache
.org/).
+ * mod_bandwidth 1.0 is written by yann stettler (stettler@cohprog.co
m).
+ *
+ ********************************************************************
*******/
+
+/*
+ * instruction :
+ * -------------
+ *
+ * note : this modify was writen for proftpd 1.2.0pre2 and tested on
it
+ *
+ * installation :
+ *
+ * just make all source again is enough. :>
+ *
+ *
+ * server configuration directive :
+ * -----------------------------------
+ * - bandwidth
+ * syntax : bandwidth
+ * default : none
+ * context : server config,,
+ *
+ * limit the total bandwidth for file-transfer (retr only)
+ * final each rate is depend of the number of connections.
+ *
+ * the is in bytes/second.
+ * a of "0" means no bandwidth limit.
+ *
+ * example :
+ * bandwidth 4096
+ *
+ * if there are 4 users online , this will limit the bandwith
+ * for file-transfer to 4096/4 □24bytes/sec.
+ *
+ * note : if transfer file size is lower than the "bandwidth"/"users"
rate,
+ * it will ignore the limit.
+ *
+ * - maxbandwidth
+ * syntax : maxbandwidth
+ * default : none
+ * context : server config,,
+ *
+ * limit the bandwidth for file-transfer (retr only)
+ * this over-ride bandwidth rules as well as the calculated rate
+ * based on the number of connections.
+ *
+ * the is in bytes/second.
+ * a of "0" means no bandwidth limit.
+ *
+ * example :
+ * if bandwidth is set to "4096" (4kbytes/sec) and maxbandwidth
+ * is set to "3072" (2kbytes/sec) that means :
+ * - if there is one connection, the file will be transfered
+ * at 3072 bytes/sec. (maximal of 3072 bytes/sec).
+ * - if there is two connections, each files will be transfered

+ * at 2048 bytes/sec.
+ * - if there is three or more connections, each files will be

+ * transfered at "4096/connections" bytes/sec.
+ *
+ * note : if transfer file size is lower than the "maxbandwidth" rate
,
+ * it will ignore the limit.
+ *
+ * - minbandwidth
+ * syntax : minbandwidth
+ * default : none
+ * context : server config,,
+ *
+ * set a minimal bandwidth to use for file-transfer. (retr only)
+ * this over-ride both bandwidth and maxbandwidth rules as well
+ * as the calculated rate based on the number of connections.
+ *
+ * the is in bytes/second.
+ * a of "0" means no bandwidth limit.
+ *
+ * example :
+ * if bandwidth is set to "3072" (2kbytes/sec) and minbandwidth
+ * is set to "1024" (1kbytes/sec) that means :
+ * - if there is one connection, the file will be transfered
+ * at 3072 bytes/sec.
+ * - if there is two connections, each files will be transfered

+ * at 1536 bytes/sec.
+ * - if there is three or more connections, each files will be

+ * transfered at 1024 bytes/sec. (minimal of 1024 bytes/sec).

+ *
+ * note : if transfer file size is lower than the "minbandwidth" rate
,
+ * it will ignore the limit.
+ *
+ */
+
#include "conf.h"
#ifdef have_regex_h
#include
#endif
+#include
+
+#undef timerisset
+#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_us
ec)
+#undef timerclear
+#define timerclear(tvp) ((tvp)->tv_sec tvp)->tv_usec □


extern module auth_module;
extern pid_t mpid;
@@ -51,6 +181,7 @@
static int stor_fd;
static int retr_fd;

+
module xfer_module;

static void _log_transfer(char direction)
@@ -129,6 +260,48 @@
retr_file ull;
}

+static struct timeval timediff(struct timeval *a, struct timeval *b)

+{
+ struct timeval rslt, tmp;
+
+ tmp a;
+
+ if ((rslt.tv_usec mp.tv_usec - b->tv_usec) < 0) {
+ rslt.tv_usec +□00000;
+ --(tmp.tv_sec);
+ }
+ if ((rslt.tv_sec mp.tv_sec - b->tv_sec) < 0) {
+ rslt.tv_usec □
+ rslt.tv_sec □
+ }
+ return (rslt);
+}
+
+void handler(int sig)
+{
+ return;
+}
+
+int sleep_msec(struct timeval *a)
+{
+ struct timeval tmp;
+ struct itimerval itimer;
+ void handler();
+
+ tmp a;
+
+ if (timerisset(&tmp)) {
+ signal(sigalrm,handler);
+ timerclear(&itimer.it_interval);
+ itimer.it_value.tv_usecp.tv_usec;
+ itimer.it_value.tv_secp.tv_sec;
+ setitimer(itimer_real,&itimer,(struct itimerval *)0);
+ pause();
+ timerclear(&itimer.it_value);
+ setitimer(itimer_real,&itimer,(struct itimerval *)0);
+ }
+}
+
/* cmd_pre_stor is a pre_cmd handler which checks security, etc, and

* places the full filename to receive in cmd->private [note that we
cannot
* use cmd->tmp_pool for this, as tmp_pool only lasts for the duratio
n
@@ -384,9 +557,11 @@
struct stat sbuf;
char *lbuf;
int bufsize,len;
+ long cur_rate □max_rate □min_rate □cur_user □
unsigned long respos □cnt □cnt_steps □cnt_next □
privdata_t *p;
-
+ struct timeval opt_time, last_time, now, timespent, timeout;
+
p od_privdata_find(cmd,"retr_filename",null);

if(!p) {
@@ -433,10 +608,53 @@
cnt espos;
log_add_run(mpid,null,session.user,null,0,session.xfer.file_size,
0,null);

+ /* calculate bandwidth transfer time
+ *
+ * if "bandwidth" , "maxbandwidth" or "minbandwidth" not be defin
ed or
+ * be defined error. i will turn off bandwidth limit.
+ */
+
+ cur_user long)get_param_int(cmd->server->conf,"current-clients",f
alse)+1;
+ cur_rate long)get_param_int(cmd->server->conf,"bandwidth",false);

+ max_rate long)get_param_int(cmd->server->conf,"maxbandwidth",fals
e);
+ min_rate long)get_param_int(cmd->server->conf,"minbandwidth",fals
e);
+
+ cur_rate □r_rate / cur_user;
+
+ if(max_rate <□)
+ max_rate □;
+ if(min_rate <□)
+ min_rate □;
+ if(cur_rate <□)
+ {
+ if(max_rate > 0l)
+ cur_rate ax_rate;
+ else if(min_rate > 0l)
+ cur_rate in_rate;
+ else
+ cur_rate □;
+ }
+
+ if((cur_rate > max_rate) && (max_rate > 0l))
+ cur_rate ax_rate;
+ if(min_rate > cur_rate)
+ cur_rate in_rate;
+
+ if(cur_rate > 0l) {
+ opt_time.tv_sec long int) bufsize / cur_rate;
+ opt_time.tv_usec long int) ((float) bufsize * 1000000 / cur_rat
e - opt_time.tv_sec * 1000000);
+ log_debug(debug1, "current bandwidth : %ld bytes/sec",cur_rate)
;
+ }
+
while((len s_read(retr_file,retr_fd,lbuf,bufsize)) > 0) {
if(xfer_aborted)
break;

+ /* record transfer start time */
+ if(cur_rate > 0l) {
+ gettimeofday(&last_time, (struct timezone *) 0);
+ }
+
len □ta_xfer(lbuf,len);
if(len < 0) {
_retr_abort();
@@ -450,6 +668,21 @@
log_add_run(mpid,null,session.user,null,0,session.xfer.file_
size,cnt,null);
}
}
+
+ /* calculate spent time and set up timer */
+ if((cur_rate > 0l) && (session.xfer.file_size > cur_rate)) {
+ gettimeofday(&now, (struct timezone *) 0);
+ timespent imediff(&now, &last_time);
+ timeout imediff(&opt_time, ×pent);
+ log_debug(debug5, "bandwidth : sleep : %ld/%ld (op time : %ld
/%ld spent : %ld/%ld)",
+ timeout.tv_sec, timeout.tv_usec, opt_time.tv_sec,
opt_time.tv_usec,
+ timespent.tv_sec, timespent.tv_usec);
+ /* we sleep... */
+ sleep_msec(&timeout);
+ if(timeoutidle)
+ reset_timer(timer_idle,any_module);
+ }
+
}

if(xfer_aborted) {
@@ -519,6 +752,57 @@
return declined(cmd);
}

+modret set_bandwidth(cmd_rec *cmd)
+{
+ long s_cur_rate
+
+ check_args(cmd,1);
+ check_conf(cmd,conf_root|conf_virtual|conf_global);
+
+ s_cur_rate □oi(cmd->argv[1]);
+
+ if(s_cur_rate < 0)
+ conf_error(cmd,"value must be lager then 0");
+
+ add_config_param_set(&cmd->server->conf,"bandwidth",1,(void*)s_cur_
rate);
+
+ return handled(cmd);
+}
+
+modret set_maximumbandwidth(cmd_rec *cmd)
+{
+ long s_cur_rate
+
+ check_args(cmd,1);
+ check_conf(cmd,conf_root|conf_virtual|conf_global);
+
+ s_cur_rate □oi(cmd->argv[1]);
+
+ if(s_cur_rate < 0)
+ conf_error(cmd,"value must be lager then 0");
+
+ add_config_param_set(&cmd->server->conf,"maxbandwidth",1,(void*)s_c
ur_rate);
+
+ return handled(cmd);
+}
+
+modret set_minimumbandwidth(cmd_rec *cmd)
+{
+ long s_cur_rate
+
+ check_args(cmd,1);
+ check_conf(cmd,conf_root|conf_virtual|conf_global);
+
+ s_cur_rate □oi(cmd->argv[1]);
+
+ if(s_cur_rate < 0)
+ conf_error(cmd,"value must be lager then 0");
+
+ add_config_param_set(&cmd->server->conf,"minbandwidth",1,(void*)s_c
ur_rate);
+
+ return handled(cmd);
+}
+
static int _noxfer_timeout(callback_frame)
{
if(session.flags & sf_xfer)
@@ -542,6 +826,13 @@
return 0;
}

+static conftable xfer_config[]
+ { "bandwidth", set_bandwidth, null }
,
+ { "maxbandwidth", set_maximumbandwidth, null }
,
+ { "minbandwidth", set_minimumbandwidth, null }
,
+ { null, null, null }

+};
+
cmdtable xfer_commands[]
{ cmd, c_type, g_none, cmd_type, true, false, cl_misc
},
{ pre_cmd, c_retr, g_read, pre_cmd_retr, true, false },
@@ -562,7 +853,7 @@
null,null, /* always null */
0x20, /* api version */
"xfer", /* module name */
- null, /* no config */
+ xfer_config, /* config name */
xfer_commands,
null,
null,xfer_init_child

--- end proftpd-1.2.0pre2-bandwidth.patch ---


文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·如何查看本机打开的端口是被哪个程序使用的-网管专栏,操作系统
·如何在多台电脑上同时安装Windows-网管专栏,操作系统
·网管人员必备的网络命令(转贴)-数据库专栏,SQL Server
·Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP完全指南(新版)-网管专栏,邮件服务
·一个IP建多个Web站点--主机头名法-网管专栏,WEB服务
·WinXP/2003网络服务详解-网管专栏,操作系统
·电信网管中的Java客户端(二)-JSP教程,Java技巧及代码
·Resin在Windows系统下的安装-网管专栏,WEB服务
·在Win2k3下配置Apache+php+mysql-网管专栏,WEB服务
·服务器配置SSL-网管专栏,操作系统

最新文章
·如何查看本机打开的端口是被哪个程序使用的-网管专栏,操作系统
·服务器配置SSL-网管专栏,操作系统
·一个IP建多个Web站点--主机头名法-网管专栏,WEB服务
·如何在多台电脑上同时安装Windows-网管专栏,操作系统
·Linux内核技术分析-网管专栏,操作系统
·在Win2k3下配置Apache+php+mysql-网管专栏,WEB服务
·在Redhat Enterprise AS 3 下源码安装配置 MONO-网管专栏,WEB服务
·网管人员必备的网络命令(转贴)-数据库专栏,SQL Server
·WinXP/2003网络服务详解-网管专栏,操作系统
·Apache安装设置-网管专栏,WEB服务




版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号