1. Cài đặt mod_cband
yum install httpd-devel
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
2. Kiểm tra xem module đã được load trong file config chưa
Mở file /etc/httpd/conf/httpd.conf xem có dòng phía dưới không, nếu ko có thì thêm vào
LoadModule cband_module /usr/lib/httpd/modules/mod_cband.so
Sau đấy restart lại httpd thì xong phần cài đặt
/etc/init.d/httpd restart
3. Sử dụng
Thêm 2 dòng sau vào file httpd.conf (chú ý 2 dòng phải phải đặt ở phần global Apache)
CBandScoreFlushPeriod 1
CBandRandomPulse On
Tiếp theo tạo thư mục như phái dướ
i
:
mkdir /var/www/scoreboard
chown apache:apache /var/www/scoreboard/
3.1 Giới hạn tốc độ download
<virtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www
CBandSpeed 1024 10 30
CBandRemoteSpeed 20kb/s 3 3
</virtualHost>
Ý nghĩa của đoạn code này:
The CBandSpeed directive limits the overall Apache performance for the www.example.com vhost to a speed of 1024kbps, max. 10 requests per second and max. 30 open connections.
The CBandRemoteSpeed is like the CBandSpeed directive, but it sets limits for any individual user (as compared to the overall settings made by CBandSpeed).
Sau đó phải restart lại Apache:
/etc/init.d/httpd restart
3.2 Giới hạn băng thông
4. Kiểm tra
<virtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www
CBandLimit 100M
CBandExceededSpeed 128 5 15
CBandScoreboard /var/www/scoreboard
CBandPeriod 4W
<location /cband-status>
SetHandler cband-status
</location>
<location /cband-status-me>
SetHandler cband-status-me
</location>
</virtualHost>
Link access http://www.example.com/cband-status và http://www.example.com/cband-status-me
Link tham khảo gốc:
http://www.howtoforge.com/mod_cband_apache2_bandwidth_quota_throttling