I spent hours trying to get mod_bandwidth to work simply because I have used it for years. But now with Apache 2.0 times have changed and there is a better option for Linux and it’s free. The new mod to regulate bandwidth and more is called Mod_cband I’m not sure what cband means but I can guess channel bandwidth.
Here is how to get it set up with Cantos 5.3 easily.
I wanted to host for my brother the latest WoW patch, but at a hefty 450 MB, I didn’t want to blow all my bandwidth on it either. I am setting a limit for the download at 2.5 TB of bandwidth, and limiting it to 5mbs at 10 connections a second. My hardware is RHEL 4 running on a P4 with Plesk 8. In the guide to follow, you’ll see a few steps that wouldn’t be needed on a non-plesk system. To setup bandwidth limiting for the host, we need to be able to compile a new apache module against our system, and then install and configure it.
Step 1: The prereqs
First I needed to setup a yum repository for FC4. This can be accomplished by issuing an RPM command:
rpm -ivh http://rpm.livna.org/livna-release-4.rpm
Now that you can access the RPM packages, we need to install http-devel using yum:
yum install httpd-devel
If all went well, we can now extract, compile, and install mod_cband for apache:
tar xzvf mod-cband-0.9.7.4.tgz
If all went well, restart apache with the new module (you can check httpd.conf to make sure the module is going to be loaded):
Step 2: Configuration
Here’s where the Plesk part gets annoying. We can’t just edit our vhosts file, because plesk writes over it all the time. Instead, we edit a /home/httpd/vhosts/*/subdomains/*/conf/vhost.conf file. Mine looks like this:
CBandSpeed 5000 5 10
CBandRemoteSpeed 1600 3 1
What does this mean? (1) Use /var/www/scoreboard to log usage and limits (2) Reset the limit count every 4 weeks (3) Throw a 509 error when the limits are exceeded (4) Allow 2.5TB per period (5) Allow 5mbs with 5 requests a second and 10 connections at a time oeverall (6) Allow 1.6mbs with 3 requests a second and 1 connections at a time per client (7) Allow us to access a page at /cband-status to view the status.
You’ll also need to issue commands to make the scoreboard directory, and to allow apache to own it:
chown apache:apache /var/www/scoreboard
Finally, Plesk requires you to inform it of your work:
/usr/local/psa/admin/sbin/websrvmng -u –vhost-name=yourdomain.com
If you restart Apache now, everything should work!
Step 3: An Example
You can take a peek at my status page right now if you’d like. It looks a bit like this:
A quick note, I simply just added:
CBandSpeed 12000 40 80
CBandRemoteSpeed 6400 12 4
Now this set the limit to about 12 megs (MPS) a second which is a lot, but this customer is paying $250 a month to cover it. Most websites should max at about 5 MPS. I left out the other options because I didn’t need them and it’s less load on the server without them.