使用mod_cband管理Apache 2带宽和流量

About the module

mod_cband is an Apache 2 module provided to solve the problem of limiting users’ and virtualhosts’ bandwidth usage. The current versions can set virtualhosts’ and users’ bandwidth quotas, maximal download speed (like in mod_bandwidth), requests-per-second speed and the maximal number of simultaneous IP connections (like in mod_limitipconn)

I advise using mod_cband by hosting companies, which would like to limit data transfer for their users, such as “10 Gb of traffic per month”. There already exists the mod_curb module, which can limit data transfers, but it doesn’t work with virtualhosts and Apache 2, so I wrote my own module fully compatible with Apache 2 API and supporting per-user and per-virtualhost bandwidth limiting

FreeBSD ports path and pkg-descr info
/usr/ports/www/mod_cband
mod_cband is an Apache 2 module provided to solve the problem of limiting virtualhosts bandwidth usage. When the configured virtualhost’s transfer limit is exceeded, mod_cband will redirect all further requests to a location specified in the configuration file.

简译:
mod_cband是一个通过Apache 2模块来解决限制用户和虚拟主机带宽问题的应用,当前版本可以调整虚拟主机和用户带宽限额,最高下载速度(like in mod_bandwidth),每秒访问请求速度和最高并发访问ip连接数(like in mod_limitipconn)。
我告诉主机服务提供商使用mod_cband,想要限制他们用户数据传输,像“每月10 Gb流量”这样。但已有了mod_curb模块,可以限制流量,但无法工作在虚拟主机和Apache 2下,所以我写了自己的模块完全适合于Apache 2 API同时支持每用户和每虚拟主机带宽限制。

好了,说到这里我想这个模块的精髓之处在于完美的支持Apache 2并实现了原有两个模块的全部功能(2in1)且支持每用户和每虚拟主机带宽限制。这在进行web平台应用与整合之时给我们提供了又一易用的方法。准备动手吧!文中实例与系统平台均基于freebsd6.1平台。

提示:

在进行实际操作之前请确保你的ports tree已经同步到当前版本。具体方法请参考这里,关于freebsd和apache2的安装本文不予介绍,同时假定你已经安装并配置了所需环境。

安装:
#cd /usr/ports/www/mod_cband
#make install clean
安装结束后末尾输出:
chmod 755 /usr/local/libexec/apache2/mod_cband.so
[activating module `cband’ in /usr/local/etc/apache2/httpd.conf]
===> Registering installation for mod_cband-0.9.7.3
此时cband_module已经自动添加到你的httpd.conf文件中并开启了。
LoadModule cband_module libexec/apache2/mod_cband.so
至此mod_cband安装已经完成,让我们继续后面的操作。之前说mod_cband易用是相对的,主要是看你如何配置让他为你所用。一些基础配置还是很容易完成,但是要发挥它的强大和灵活配置还是要好好看看documentation,充分理解良好驾驭。不啰嗦了,下面看看如何进行基本配置和使用并观测实际效果。以我这个blog为实例,看看基本情况:
<VirtualHost *:80>
DocumentRoot “/other/blog/wordpress”
ServerName blog.citygrit.cn
<Directory “/other/blog/wordpress”>
allow from all
Options +Indexes
</Directory>
# 100MB virtualhost bandwidth limit
CBandLimit 100M
# Maximal 1024kbps speed for this virtualhost
# Maximal 10 requests per second for this virtualhost
# Maximal 30 open connections for this virtualhost
CBandSpeed 1024 10 30
# Maximal 10kB/s speed, 3 requests/s and 2 open connections for any remote client
CBandRemoteSpeed 10kb/s 3 2
# a period of time after which the scoreboard will be cleared (4 weeks)
CBandPeriod 4W
#Then you can access the status page with a URL like:http://server_name/cband-status
<Location /cband-status>
SetHandler cband-status
</Location>
#Then you can access the status page with a URL like:http://server_name/cband-status-me
<Location /cband-status-me>
SetHandler cband-status-me
</Location>
</VirtualHost>
为了便于理解将上面内容里与mod_cband相关设置予以说明,(约定“#”为注释标记)。
# 100MB virtualhost bandwidth limit
CBandLimit 100M
限制虚拟主机总访问带宽为100Mb。
# Maximal 1024kbps speed for this virtualhost
# Maximal 10 requests per second for this virtualhost
# Maximal 30 open connections for this virtualhost
CBandSpeed 1024 10 30
限制此虚拟主机最高访问速度1024kbps
限制此虚拟主机每秒最高接受请求数10个
限制此虚拟主机最高并发连接30个
# Maximal 10kB/s speed, 3 requests/s and 2 open connections for any remote client
CBandRemoteSpeed 10kb/s 3 2
限制来自远端访问速度10kB每秒,3个请求每秒,2个连接。
# a period of time after which the scoreboard will be cleared (4 weeks)
CBandPeriod 4W
设定多久对所记录的全局访问带宽进行重设(清零)。
4W=4 weeks 4周(一个月)
#Then you can access the status page with a URL like:http://server_name/cband-status
<Location /cband-status>
SetHandler cband-status
</Location>
开启了mod_cband的实时监测功能,可以通过http://server_name/cband-status进行直观的观测。(全局监测)
#Then you can access the status page with a URL like:http://server_name/cband-status-me
<Location /cband-status-me>
SetHandler cband-status-me
</Location>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值