martes 27 de noviembre de 2007

Upgrade de Apache (Redhat) y limitación de ancho de banda (2 de 2)

El upgrade anterior no era porque sí: En mi caso, la versión de apache que pretendía actualizar no traía el comando apxs (necesario para el propósito), por lo que debía incorporarlo al sistema de alguna manera.

Tal como dije en el post anterior en esta segunda parte me centro en la instalación del mod_bw:


- Instalo mod_bw

[root@localhost src]# pwd
/usr/src
[root@localhost src]# ls
mod_bw-0.8.tgz redhat rpms


- Desenzipo y destareo

[root@localhost src]# gunzip mod_bw-0.8.tgz
[root@localhost src]# tar xvf mod_bw-0.8.tar
mod_bw/
mod_bw/LICENSE
mod_bw/ChangeLog
mod_bw/mod_bw.txt
mod_bw/TODO
mod_bw/mod_bw.c
[root@localhost src]#

El fichero mod_bw.txt contiene las instrucciones de lo que hay que hacer para instalar el modulo.


- Aquí es donde hace falta el apxs

[root@localhost mod_bw]# apxs -i -a -c mod_bw.c
-bash: apxs: command not found


- Determinamos PATH para que encuentre lo que hemos compilado. Para ser más estrictos, después habría que incorporar este cambio en el profile.

[root@localhost mod_bw]# export PATH=/opt/apache2.0.52/bin:$PATH


- Retry

[root@localhost mod_bw]# apxs -i -a -c mod_bw.c
/opt/apache2.0.52/build/libtool --silent --mode=compile gcc -prefer-pic -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread -I/opt/apache2.0.52/include -I/opt/apache2.0.52/include -I/opt/apache2.0.52/include -c -o mod_bw.lo mod_bw.c && touch mod_bw.slo
/opt/apache2.0.52/build/libtool --silent --mode=link gcc -o mod_bw.la -rpath /opt/apache2.0.52/modules -module -avoid-version mod_bw.lo
/opt/apache2.0.52/build/instdso.sh SH_LIBTOOL='/opt/apache2.0.52/build/libtool' mod_bw.la /opt/apache2.0.52/modules
/opt/apache2.0.52/build/libtool --mode=install cp mod_bw.la /opt/apache2.0.52/modules/
cp .libs/mod_bw.so /opt/apache2.0.52/modules/mod_bw.so
cp .libs/mod_bw.lai /opt/apache2.0.52/modules/mod_bw.la
cp .libs/mod_bw.a /opt/apache2.0.52/modules/mod_bw.a
ranlib /opt/apache2.0.52/modules/mod_bw.a
chmod 644 /opt/apache2.0.52/modules/mod_bw.a
PATH="$PATH:/sbin" ldconfig -n /opt/apache2.0.52/modules
----------------------------------------------------------------------
Libraries have been installed in:
/opt/apache2.0.52/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 755 /opt/apache2.0.52/modules/mod_bw.so
[activating module `bw' in /opt/apache2.0.52/conf/httpd.conf]
[root@localhost mod_bw]#


- Hacemos un backup del httpd.conf, por lo que pudiera ser.

[root@localhost mod_bw]# cd /opt/apache2.0.52/conf
[root@localhost conf]# cp -p httpd.conf httpd.conf.orig


- Creo directorios de ejemplo de destino, copio fichero de descarga y cambio permisos

[root@localhost ~]# cd /opt/apache2.0.52/htdocs/
[root@localhost htdocs]# mkdir slow
[root@localhost htdocs]# mkdir fast
[root@localhost htdocs]# ls -l fast slow
fast:
total 5692
-rw-r--r-- 1 root root 5812024 Sep 13 2007 firefox.exe

slow:
total 5692
-rw-r--r-- 1 root root 5812024 Sep 13 2007 firefox.exe
[root@localhost htdocs]# ls -l
total 304
...
-rw-r--r-- 1 1262 1262 1385 May 30 2001 apache_pb.png
drwxr-xr-x 2 root root 4096 Jul 10 04:02 fast
-rw-r--r-- 1 1262 1262 1663 May 20 2002 index.html.ca
...
-rw-r--r-- 1 1262 1262 1032 May 14 2003 index.html.zh-tw.big5
drwxr-xr-x 2 root root 4096 Jul 10 04:03 slow
[root@localhost htdocs]# chown -R 1262:1262 fast slow
[root@localhost htdocs]#


- Compruebo que httpd sube

[root@localhost htdocs]# apachectl -f /opt/apache2.0.52/conf/httpd.conf -k start
[root@localhost htdocs]# netstat -npl|grep httpd
tcp 0 0 :::80 :::* LISTEN 23163/httpd


- Compruebo que httpd baja

[root@localhost htdocs]# apachectl -f /opt/apache2.0.52/conf/httpd.conf -k stop
[root@localhost htdocs]# netstat -npl|grep httpd
[root@localhost htdocs]#


- Modifico httpd.conf añadiendo lo siguiente en la seccion global

#
BandWidthModule On
ForceBandWidthModule On
#


- Y lo siguiente en la sección default:

<Directory "/opt/apache2.0.52/htdocs/slow">
Bandwidth all 102400
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Con esto limitamos directorio slow a una descarga de 100 KB/segundo


- Arranco apache de nuevo

[root@localhost conf]# apachectl -f /opt/apache2.0.52/conf/httpd.conf -k start
[root@localhost conf]# netstat -npl|grep httpd
tcp 0 0 :::80 :::* LISTEN 23344/httpd


- Finalmente compruebo velocidades de descarga, accediendo con el navegador a las URL correspondientes (sustituyendo las IP por las que correspondan, se entiende):

  • http://192.168.84.127/slow/firefox.exe que debería descagar con un ratio alrededor de 100 KB (ver imagen)
  • http://192.168.84.127/fast/firefox.exe que debería descargar sin límite de ancho de banda.

ACTUALIZACION (modificación) (2007-12-16): Donde hace referencia a la sección default del fichero httpd.conf. Se había colado un error debido a la interpretación html de los simbolos < y >, lo que provocaba que estos símbolos y lo que había encerrado en ellos (*Directory*) no pudiera verse.