Friday, December 23, 2011

Apache qos module in Ubutu Linux machine

To install qos module in the apache server, at first you need to down load the qos module from sourceforge.net. The latest version of qos is available in this link: http://sourceforge.net/projects/mod-qos/files/latest/download?source=files

To install that the following should write:
cd /tmp/
wget http://sourceforge.net/projects/mod-qos/files/latest/download?source=files


The file will be downloaded in the tmp folder. The file name would be download?source=files. you should unzip the files.

tar xvfz download?source=files




After this command, new folder will be created. The folder name is mod_qos-9.76. The folder name would be changed with the change of the qos module version.

A tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server.

Now we need apxs which a tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server. For apxs, we need to install the appropriate dev package and gcc of course, ie:
sudo apt-get install apache2-threaded-dev gcc



We need to change the directory for that

cd mod_qos-9.76/apache2/




To install the qos module , the following command is useful:
sudo apxs2 -i -c mod_qos.c



If everything works fine then you can this in the below:

If everything worked fine you'll get something like this:
----------------------------------------------------------------------
Libraries have been installed in:
/usr/lib/apache2/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 644 /usr/lib/apache2/modules/mod_qos.so



Now qos module is installed in the apache. We need to add two files called qos.load and qos.conf in the /etc/apache2/mods-available/ folder. For that:
cd /etc/apache2/mods-available/
sudo gedit qos.load



Add the command in the textpad and save before close that.
LoadModule qos_module /usr/lib/apache2/modules/mod_qos.so





Next command will be :
sudo gedit qos.conf




In the text pad you should add the texts and save that before close.


## QoS Settings
<IfModule mod_qos.c>
# handles connections from up to 100000 different IPs
QS_ClientEntries 100000
# will allow only 50 connections per IP
QS_SrvMaxConnPerIP 50
# maximum number of active TCP connections is limited to 256
MaxClients 256
# disables keep-alive when 70% of the TCP connections are occupied:
QS_SrvMaxConnClose 180
# minimum request/response speed (deny slow clients blocking the server, ie. slowloris keeping connections open without requesting anything):
QS_SrvMinDataRate 150 1200
# and limit request header and body (carefull, that limits uploads and post requests too):
# LimitRequestFields 30
# QS_LimitRequestBody 102400
</IfModule>



Now you need to enable the module and restart apache:

sudo a2enmod qos
sudo /etc/init.d/apache2 restart




All the things are done. If you want to check the server status just write the following in the web browser address bar:
http://localhost/server-status



If you use real ip, then use your IP-address instead of localhost.

After this command the browser will show like this
Apache Server Status for localhost
Server Version: Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.7 with Suhosin-Patch mod_qos/9.76
Server Built: Nov 3 2011 02:35:16

Current Time: Friday, 23-Dec-2011 08:59:22 EST
Restart Time: Friday, 23-Dec-2011 08:25:51 EST
Parent Server Generation: 0
Server uptime: 33 minutes 30 seconds
Total accesses: 4 - Total Traffic: 1 kB
CPU Usage: u0 s0 cu0 cs0
.00199 requests/sec - 0 B/second - 256 B/request
1 requests currently being processed, 5 idle workers
W_____..........................................................
................................................................
................................................................
................................................................

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
0-0 5118 0/0/0 W 0.00 0 0 0.0 0.00 0.00 127.0.0.1 localhost.localdomain GET /server-status HTTP/1.1
1-0 5119 0/4/4 _ 0.00 1932 0 0.0 0.00 0.00 127.0.0.1 localhost.localdomain NULL

Srv Child Server number - generation
PID OS process ID
Acc Number of accesses this connection / this child / this slot
M Mode of operation
CPU CPU usage, number of seconds
SS Seconds since beginning of most recent request
Req Milliseconds required to process most recent request
Conn Kilobytes transferred this connection
Child Megabytes transferred this child
Slot Total megabytes transferred this slot

mod_qos 9.76

localhost.localdomain:0 (base)
connections
free ip entries 255
current connections 1
connection settings
max connections -
max connections with keep-alive 180
max connections per client ip 50
min. data rate (bytes/sec) (min/max/current) 150/1200/154


localhost.localdomain:80 (virtual)
uses base server settings



Apache/2.2.16 (Ubuntu) Server at localhost Port 80




If all the things are okay, then you are done the qos module setup.

1 comment:

Karol said...

replace
sudo apxs2 -i -c mod_qos.c with
sudo apxs2 -i -c mod_qos.c -lcrypto