Limit cPanel bandwidth using mod_cband - Do it now









Are you trying to Limit cPanel bandwidth using mod_cband?

This guide is for you.

Sometimes, most websites may consume huge bandwidth. For servers using Apache2, we can use the mod_cband module to limit data transfer for a website.
mod_cband helps us to set user’s and VirtualHost's bandwidth quota and limit requests per second speed.
It can also set maximal download speed and the maximum number of simultaneous IP connections.
Here are Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix bandwidth related issues.

How to limit cPanel bandwidth using mod_cband ?

i. To configure the mod_cband module on CentOS/RedHat/Fedora we need apxs installed first.
We can do this with the following command:

$ yum install httpd-devel

Also, we need to have executable permission for the directory in which we wish to install mod_cband.
The option “CBandExceededSpeed”, in the mod_cband module allows us to bring down the speed and the maximum number of connections per second.
We can also keep a track of all the connections by creating a scoreboard (database) i.e "/home/user/domains/website.com/public_html/scoreboard".
It has also got an option for splitting up the bandwidth usage per week.

ii. We can add the following codes in the VirtualHost directory section:

CBandLimit 6G
CBandPeriod 4W
CBandPeriodSlice 1W
CBandSpeed 500kbps 10 30

It means that 6GB is split up in 4-week slices, so we can get 1.5GB of bandwidth per week. And the maximum speed is 500kbps, with 10 requests/second and a max of 30 connections.

iii. Next, we can download and install mod_cband  using the following commands:

# cd /tmp
# wget http://pkgs.fedoraproject.org/repo/pkgs/mod_cband/mod-cband-0.9.7.4.tgz/ff635d7b55bf7ca648d319247dfb45e3/mod-cband-0.9.7.4.tgz
# tar xzvf mod-cband-0.9.7.4.tgz
# cd mod-cband-0.9.7.4
# ./configure
# make
# make install
# vi /etc/httpd/conf/httpd.conf


iv. Check if we can find a line like the one given below:

LoadModule cband_module /usr/lib64/httpd/modules/mod_cband.so

(If this line is not present, add it manually)

v. Finally restart Apache:

# /etc/init.d/httpd restart


Tips to resolve Common mod_cband installation error ?

One of the common error looks like the one given below:

Error: apxs:Error: Command failed with rc=65536

Sometimes, we will get this error while executing make:

apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c
/usr/local/apr/build-1/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache/include -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-1 -Wall -DDST_CLASS=3 -c -o src/mod_cband.lo src/mod_cband.c && touch src/mod_cband.slo
src/mod_cband.c: In function 'mod_cband_create_traffic_size':
src/mod_cband.c:1046: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c:1046: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c:1050: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c:1050: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c: In function 'mod_cband_get_dst':
src/mod_cband.c:1325: error: 'conn_rec' has no member named 'remote_ip'
src/mod_cband.c: In function 'mod_cband_get_remote_host':
src/mod_cband.c:1354: error: 'struct conn_rec' has no member named 'remote_ip'
src/mod_cband.c:1355: error: 'struct conn_rec' has no member named 'remote_ip'
src/mod_cband.c:1357: error: 'struct conn_rec' has no member named 'remote_addr'
apxs:Error: Command failed with rc=65536
.
make: *** [src/.libs/mod_cband.so] Error 1


On Source Directory

# ls

AUTHORS conf config.status doc libpatricia.copyright Makefile src
Changes config.log configure INSTALL LICENSE Makefile.in


Open mod_cband.c file under src folder:

# vim mod_cband.c

1. First we must change the variable name "remote_ip" to "client_ip".
2. After search and change the given below line:

else
addr = c->remote_addr->sa.sin.sin_addr.s_addr;

to

else
addr = c->client_addr->sa.sin.sin_addr.s_addr;

3. Save and exit the file.

Now try to compile the program from the mod_cband root directory.

# make
# make install

We must keep in mind that even though mod_cband is a useful module to throttle bandwidth usage, it can sometimes turn weird if the website that we are trying to throttle has got MP3 downloads.

[Still facing Linux related issues? – We can help you. ]

Conclusion

This article covers how to limit cPanel bandwidth using mod_cband. In order to compile mod_cband, we must have apxs2 installed.
We can achieve that by doing this:
$ apt-get install apache2-prefork-dev

Next we download and install mod_cband like this:
cd /tmp
wget http://cband.linux.pl/download/mod-cband-0.9.7.4.tgz
tar xzvf mod-cband-0.9.7.4.tgz
cd mod-cband-0.9.7.4
./configure
make
make install

The make install command should have added the mod_cband module to /etc/apache2/httpd.conf. Run:
$ vi /etc/apache2/httpd.conf
and check if you find a line like this:
LoadModule cband_module       /usr/lib/apache2/modules/mod_cband.so

Finally restart Apache:
/etc/init.d/apache2 restart
The mod_cband installation is now finished.




Keep In Touch

We hope to hear from you.

Accept File Type: jpg,jpeg,png,txt,pdf,doc,docx