mod_bandwidth for apache 1.3 help required & kindly give ur views.

anay

Verified User
Joined
Dec 7, 2005
Messages
120
I am still noob in all this but I am learning..
I want to limit bandwdith per connection on server.
I found --> http://www.hostlibrary.com/Installingmod_bandwidthFortheUltimateinApacheUtilizationControl-544.html

But I am stucked at few places..
Basically.. kindly guide me how I can make it working for my CentOS 4.x with DA .

mkdir /root/modbw

cd modbw

wget ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c

/usr/local/apache/bin/apxs -c /root/mbw/mod_bandwidth.c -o /usr/local/apache/libexec/mod_bandwidth.so
I am unable to find such directory, kindly tell whre are these in terms of DA ?
(The above is all one command)

mkdir /usr/local/apache/apachebw

mkdir /usr/local/apache/apachebw/link

mkdir /usr/local/apache/apachebw/master

chown nobody:nobody -R /usr/local/apache/apachebw

pico /etc/httpd/conf/httpd.conf

Find the line that looks like this:

LoadModule rewrite_module libexec/mod_rewrite.so

And BEFORE that line, add this:

LoadModule bandwidth_module libexec/mod_bandwidth.so

Then locate the line that looks like this:

AddModule mod_env.c

and BEFORE that line, add this:

AddModule mod_bandwidth.c

Then locate the line that looks like this:

# Document types.

And BEFORE that line add this:

BandWidthDataDir "/usr/local/apache/apachebw"
BandWidthModule On

Then to enable it on a virtual host, locate the virtualhost entry for the
domain you wish to limit and just BEFORE the </virtualhost> line, add
this:

BandWidthModule On
BandWidth all 512

The 512 can be replaced with whatever rate you want to limit it to in
bytes per second.

Save the httpd.conf file.

service httpd restart

cd /usr/sbin

wget ftp://ftp.cohprog.com/pub/apache/module/cleanlink.pl

chmod 755 cleanlink.pl

pico cleanlink.pl

Change $LINKDIR as follows:

$LINKDIR="/usr/local/apache/apachebw/link";

Save the file.

perl cleanlink.pl

pico /etc/rc.d/rc.local
At the end of that file add:

# Launch Cleanlink for mod_bandwidth
perl /usr/sbin/cleanlink.pl

Save that file.
In short ..
Where is /usr/local/apache/bin
in centOs 4x running DA ?

Also, which which one is /usr/local/apache/libexec/
 
/usr/local is FreeBSD system
for CentOS try only /usr
I modify as follow.... Base on my CentOS4.4 + DA

#mkdir /justtempdir
#cd /justtempdir

wget ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c

apxs -c mod_bandwidth.c -o /usr/lib/apache/mod_bandwidth.so

mkdir /etc/apachebw
mkdir /etc/apachebw/link
mkdir /etc/apachebw/master

chown -R apache:apache /etc/apachebw
chmod 750 /etc/apachebw

pico /etc/httpd/conf/httpd.conf

Find the line that looks like this:

LoadModule rewrite_module libexec/mod_rewrite.so

And BEFORE that line, add this:

LoadModule bandwidth_module /usr/lib/apache/mod_bandwidth.so

Then locate the line that looks like this:

AddModule mod_env.c

and BEFORE that line, add this:

AddModule mod_bandwidth.c

Then locate the line that looks like this:

# Document types.

And BEFORE that line add this:

BandWidthDataDir "/etc/apachebw"
BandWidthModule On

Then to enable it on a virtual host, locate the virtualhost entry for the
domain you wish to limit and just BEFORE the </virtualhost> line, add
this:

BandWidthModule On
BandWidth all 512

The 512 can be replaced with whatever rate you want to limit it to in
bytes per second.

Save the httpd.conf file.

service httpd restart

cd /usr/sbin

wget ftp://ftp.cohprog.com/pub/apache/module/cleanlink.pl

chmod 755 cleanlink.pl

pico cleanlink.pl

Change $LINKDIR as follows:

$LINKDIR="/etc/apachebw/link";

Save the file.

perl cleanlink.pl

pico /etc/rc.d/rc.local
At the end of that file add:

# Launch Cleanlink for mod_bandwidth
perl /usr/sbin/cleanlink.pl

Save that file.
 
install mod_bandwith for apache 1.3x

my old installation on centos :

mkdir /tmp/apachebw
mkdir /tmp/apachebw/link
mkdir /tmp/apachebw/master
chown -R apache:apache /tmp/apachebw
/usr/sbin/apxs -iac mod_bandwidth.c

with apxs no need to add more in httpd.conf, should be auto added
only if you want limit server home root (sample)
sample :
<Directory /home/www>
BandWidthModule On
BandWidth all 1024
</Directory>
This will limit the bandwith for directory /home/www and all it's subdirectories to 1024Bytes/s if

in virtualhost (custom httpd configuration) just add somes directives

BandWidthModule On
BandWidth all 1024
MaxConnection 10
 
Running that cleanlink.pl is giving following error :

The script is .
#!/usr/local/bin/perl

#
# A little daemon that I use to clean links created by the bandwidth
# module for Apache when they weren't removed properly by the server.
# (Ie: when a httpd process didn't terminated in the usual way.)
#
# Change the value of TIME to how often (in seconds) you want to
# do the cleaning.
#

$TIME=120;

$PS="ps -auxw";
$LINKDIR="/tmp/apachebw/link";

unless(fork) {
unless (fork) {
sleep 1 until getppid == 1;
while (1) {
&do_clean;
sleep($TIME);
}
exit 0;
}
exit 0;
} wait;

sub do_clean {
local(%ppid);

open(INP, "$PS |");
while(<INP>) {
if (($process) =/^\S+\s+(\d+)\s+.+httpd\s/) {
$ppid{$process}=1;
}
}
close(INP);

opendir(DIR, $LINKDIR);
local(@filename)=readdir(DIR);
closedir(DIR);

for($i=0; $i <= $#filename; $i++) {
if ($filename[$i] =~ /^\d+$/) {
if (! $ppid{$filename[$i]}) {
unlink("$LINKDIR/$filename[$i]");
}
}
}
}
Error it gave :
Code:
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/
procps-3.2.3/FAQ
Does it means that cleanlink.pl is not running at all ?
Also that error is coming everytime that escrpt is executed.

Secndly I was unable to find

#Document Type

Rather I added this ..
<IfModule mod_bandwidth.c>
BandWidthDataDir "/etc/apachebw"
BandWidthModule On
</IfModule>
Between other module thingi.

Also can you tell that wht is the 512B is ie. is it 512Byte per second per connection or is it 512Bps for that virtual host ?

Actually all I want is that on a particular virtual host on my server no file should transfer more than speed of 64kBps per second per connection which means if any client with 20mbps connetion at his end won't eat up most of the available banwidth on that server.

here --> http://www.cohprog.com/v3/bandwidth/doc-en.html
I found this that setting up as follow :
Code:
Bandwidth all 65536
Minbandwidth all -1
should limit data transfer per connection at 64kBytes per second.

Also, what do you think .. that turning
Code:
BandWidthModule On
in httpd.conf turns it on on every virtual host on that server or under only those in which we specify it explicitly as mentioned in the tutorial.

By the time I have turned off this module and shall use it only after your advice.

Many many thanx.

Lastly .. can you suggest me how I can verify that this module is working ? (I can do that by downloading a large file too) but is there any other specific way in apache to find the working module..

httpd -l only shows 3 module which are there in it at comiled time but no dynamic running modules .
 
Check out first line of script !

#!/usr/local/bin/perl

It not existing!, change to...

#!/usr/bin/perl

and beware of /tmp/apachebw
all files&folders will gone after reboot.
you may also need to add mkdir in the startup script.
 
Last edited:
Thanx kke & xemaps2 .

Ya.. I changed that but actually system was already parsing it in right way.

Also i removed that "ps -auxw" to ps auxw as it was little mistake..

No error now and hope its working fine.
BTW, after bandwidth management, server seems to serving the requests more efficently.
 
Back
Top