HOWTO : Mod_Bandwidth for DA

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
************************************
Mini-Howto on installing Mod_BandWidth
Version 2.0.5
Date : 23 July 2004

Tested on Redhat 9
************************************

Step 1 - Download mod_bandwidth

#cd /usr/local/directadmin/customapache (You may change this)
#wget ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c

Step 2 - APXS Compilation
#/usr/sbin/apxs -c ./mod_bandwidth.c -o /etc/httpd/modules/mod_bandwidth.so

Step 3 - Link Directory
#mkdir /tmp/apachebw
#mkdir /tmp/apachebw/link
#mkdir /tmp/apachebw/master
#chown -R apache:apache /tmp/apachebw

Step 4 - Modify Apache Conf
#vi /etc/httpd/conf/httpd.conf

Place those lines in whatever place you want:
<IfModule mod_bandwidth.c>
BandWidthDataDir /tmp/apachebw
BandWidthModule On
</IfModule>


Step 5 - Customize Virtual Host Limitation
You may now customize each virtual host's httpd.conf located in
/usr/local/directadmin/data/user/{username}/

by adding "BandWidthModule On" (without quotes) in each <VirtualHost>, and mod_bandwidth tag like "BandWidth" inside <Directory> tag.


Step 6 - Do a safe apache restart
#service httpd restart


OK! You may now upload a huge file (enough to test) to a dummy site that you limited to test.

:)
 
may i know what does mod_bandwidth do and what's it's advantage over default DA bandwidth function and mod_throttle?

thanks.
 
if i compile this, and don't add any user, does apache work as normal, withoutany limits?
 
The module is set to be disabled unless you add

"BandWidthModule On"
:)
 
i don't get step 5:
Step 5 - Customize Virtual Host Limitation
You may now customize each virtual host's httpd.conf located in
/usr/local/directadmin/data/user/{username}/

by adding "BandWidthModule On" (without quotes) in each <VirtualHost>, and mod_bandwidth tag like "BandWidth" inside <Directory> tag.


you mean like this:
Code:
<VirtualHost 81.23.xxxx:80>

        [b]BandWidthModule On[/b]
        ServerName [url]www.xxxx.nl[/url]
        ServerAlias [url]www.xxxl[/url] dtp.fxxe.nl
        ServerAdmin webmaster@xxx
        DocumentRoot /home/xxx/domains/xx/public_html/dtp
        ScriptAlias /cgi-bin/ /home/xxx/domains/xxxnl/public_html/$

        User xxx
        Group xxx
        CustomLog /var/log/httpd/domains/xxx.bytes bytes
        CustomLog /var/log/httpd/domains/xxx.dtp.log combined
        ErrorLog /var/log/httpd/domains/xxx.nl.dtp.error.log
        <Directory /home/xxxx/domains/xxx.nl/public_html/dtp>
                Options +Includes -Indexes
                [b]BandWidth[/b]
                php_admin_flag engine ON
                php_admin_flag safe_mode OFF
        </Directory>



        #php_admin_value open_basedir /home/xxx/:/tmp/:/var/www/:/usr/loc$

</VirtualHost>

and where do i set f.i. 300 kb/s?
 
Yes.

You may set

BandWidth all 1024


where the unit of 1024 is "Bytes/s".
 
is this step from the docs for mod_bandwidth not neccessary?:
Code:
    * Add the following lines to your httpd.conf file :
      LoadModule bandwidth_module libexec/mod_bandwidth.so
      AddModule mod_bandwidth.c

      Those directives should be placed at the begining of the list so that 
the module will be given the lowest priority and be executed after others modules.
 
so this should do it:
Code:
<VirtualHost 81.23.xxxx:80>

BandWidthModule On
ServerName [url]www.xxxx.nl[/url]
ServerAlias [url]www.xxxl[/url] dtp.fxxe.nl
ServerAdmin webmaster@xxx
DocumentRoot /home/xxx/domains/xx/public_html/dtp
ScriptAlias /cgi-bin/ /home/xxx/domains/xxxnl/public_html/$

User xxx
Group xxx
CustomLog /var/log/httpd/domains/xxx.bytes bytes
CustomLog /var/log/httpd/domains/xxx.dtp.log combined
ErrorLog /var/log/httpd/domains/xxx.nl.dtp.error.log
<Directory /home/xxxx/domains/xxx.nl/public_html/dtp>
Options +Includes -Indexes
BandWidth all 25600
php_admin_flag engine ON
php_admin_flag safe_mode OFF
</Directory>



#php_admin_value open_basedir /home/xxx/:/tmp/:/var/www/:/usr/loc$

</VirtualHost>

this sets the bandwidth cap to all directories under public_html? also subdomains?
 
sander815 said:
is this step from the docs for mod_bandwidth not neccessary?:
Code:
    * Add the following lines to your httpd.conf file :
      LoadModule bandwidth_module libexec/mod_bandwidth.so
      AddModule mod_bandwidth.c

      Those directives should be placed at the begining of the list so that 
the module will be given the lowest priority and be executed after others modules.

Those lines are added by DA, but they are not loaded because mod_bandwidth is not loaded.



so this should do it:

code:--------------------------------------------------------------------------------<VirtualHost 81.23.xxxx:80>

BandWidthModule On
ServerName www.xxxx.nl
ServerAlias www.xxxl dtp.fxxe.nl
ServerAdmin webmaster@xxx
DocumentRoot /home/xxx/domains/xx/public_html/dtp
ScriptAlias /cgi-bin/ /home/xxx/domains/xxxnl/public_html/$

User xxx
Group xxx
CustomLog /var/log/httpd/domains/xxx.bytes bytes
CustomLog /var/log/httpd/domains/xxx.dtp.log combined
ErrorLog /var/log/httpd/domains/xxx.nl.dtp.error.log
<Directory /home/xxxx/domains/xxx.nl/public_html/dtp>
Options +Includes -Indexes
BandWidth all 25600
php_admin_flag engine ON
php_admin_flag safe_mode OFF
</Directory>



#php_admin_value open_basedir /home/xxx/:/tmp/:/var/www/:/usr/loc$

</VirtualHost>

When you put "bandwidth" in <directory>, that means this directory and its sub-directories are limited.
 
jeffery said:
Yes.

You may set

BandWidth all 1024


where the unit of 1024 is "Bytes/s".

its limiting indeed, on my testdomain, but it seems like i can't get more then 100 kb/s dlspeed, i am at BandWidth all 1024000, but still, 100 kb/s is max dl speed. I would like to limit at around 300 kb/s, 100 is a bit too low
 
What bandwidth to you seem to get for your test site when you turn limiting off?

Jeff
 
when i put ''bandwith all 0'' i get full speed, 100%[====================================>] 29,902,848 7.70M/s ETA 00:00


when i put ''bandwith all 262144'' i get 12% [===> ] 3,660,624 88.96K/s ETA 04:48, that should be around 256 kb/s, if i calculate right. Higher numbers produce same speed of around 90 kb/s
 
You have to use

"BandWidthPulse"

according to the author.

But I haven't test it yet! :)
 
finally found a working soplution:
add into the global httpd.conf:
BandWidthPulse 500000

so, like this:
<IfModule mod_bandwidth.c>
BandWidthDataDir /tmp/apachebw
BandWidthModule On
BandWidthPulse 500000
</IfModule>

that worked for me
 
I'm using this mod.
And everytime there is an update of DA, the directory in /tmp/apachebw gets deleted and I have to recreate before rerunning httpd.
Is there a way to recreate those directories after an update to avoid down time :s
 
Has this been resolved?

  • Hi, please could someone update this thread, especially the following question?
    BadSpeed said:
    everytime there is an update of DA, the directory in /tmp/apachebw gets deleted
    Also, what is the meaning of "BandWidthPulse", what does its value represent, and how does the value of "BandWidthPulse" relate to the value of "BandWidth"?

    TIA!
 
Back
Top