No space left on device: mod_rewrite… Solución para servidor web Apache

servidor apache

servidor apache

En alguna ocasión me he topado con que al reiniciar Apache después de matar todos los procesos con killall -9 httpd el servidor Apache no quiere arrancar, Apache start [FALLA], dando en el log el error de más arriba. Se trata de que Apache no ha liberado recursos del sistema y debemos hacerlo nosotros. En concreto se trata de semáforos. Linux tiene dos comandos que me ayudan a hacer esto (ipcs e ipcrm). Por si acaso antes vamos a eliminar los procesos zoombie:

Ver procesos zoombie:

# ps -A -ostat,ppid,pid,cmd | grep -e ‘^[Zz]’

Matar procesos zoombie (tardará un poco):

# kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e ‘^[Zz]’ | awk ‘{print $2}’`

Este es el error al reiniciar o arrancar Apache:

[crit] (28) No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed

Solución:

Revisar los semáforos de Apache

# ipcs -s | grep apache

Eliminamos todos los semáforos de los procesos de Apache

# ipcs -s | grep apache | perl -e ‘while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}’

Iniciar Apache

# service httpd start

Script en bash para cambiar el puerto de Apache en todos los dominios en Plesk

Si quereis cambiar el puerto en todos los vhost`s en Plesk, tendreis que cambiar el numero 80 (puerto Apache default de Plesk) dentro del archivo httpd.include de cada vhosts, y si teneis muchos vhosts en el servidor o servidores… como no tengais este pequeño script en bash, os podeis morir en el intento

#!/bin/bash
MY_FILEPATH="/var/www/vhosts"
MY_FILE="httpd.include"
MY_REPLACE=":81"
find $MY_FILEPATH  -name $MY_FILE -exec perl -p -i -e "s[:80][$MY_REPLACE]g" {} \;
service httpd restart"

Funciones a deshabilitar en php.ini – Tips para securizar php

Y es que, cada vez se ven mas destrozos a causa de las webs mal hechas (o poco actualizadas) en php . Que si postnuke, que si phpnuke, phpbb, mybb y un larguisimo etc. Ya que esto es un dolor de cabeza para cualquier sysadmin, algo a tener en cuenta es el deshabilitar ciertas funciones de php en el php.ini, y el que las quiera.. que las habilite en el .htaccess de su virtualhost bajo su responsabilidad, no? Empezamos:

Editamos fichero de configuración de PHP php.ini

#vi /etc/php.ini

buscamos la linea que contiene disable_functions. Posiblemente tenga un ; delante, que sirve para inutilizarla. Eliminamos el ; y dejamos la linea de esta forma:

disable_functions = system, exec, popen, passthru, shell_exec, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate

Asi, nos cargamos unas cuantas funciones peligrosas que a mas de uno le han dejado sin dormir.

Por otro lado, es de esperar el estar atentos a cosas como el safe_mode, allow_url_fopen y demas… pero creo que eso ya lo puse en otro post anterior 🙂

Instalar Memcached en CentOS 5.3

Memcached is a generic purpose distributed high performance memory object caching system to use in speeding up dynamic database driven websites by caching data and objects in memory to reduce the amount the database needs to be read.

Memcached was originally developed by Danga Interactive for LiveJournal but is now used by many popular and large community driven websites like Slashdot, Wikipedia, SourceForge, GameFAQs, Facebook, Digg, Fotolog, Kayak and like. It is being distributed under a permissive free software licence. Know more about who all are using memcached

Things to consider before Installing memcached.

  1. First, decide how much memory you want to give memcached to use for caching.
  2. Then decide if you want to run memcached on the default port (11211) or not.
  3. Next decide if you want memcached to listen to a specific IP address if you have multiple IP addresses on your server
  4. Finally decide, what user you want to run memcached as; typically, you want to run it using Apache user so that Apache processes can access memcache data

Installation Process

1. If you don’t have rpmforge installed, follow this step.

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm –install rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum install –enablerepo=rpmforge memcached

2. Start memcached.

memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody

The “-m SIZE” is the flag for setting the memory requirements in MBs. Once this cache is filled memcache will just start to overwrite with newer content. Please experiment with this setting to find what works best for you.

3. Install PHP extension.

wget http://pecl.php.net/get/memcache-2.2.5.tgz

4. Extract tar file.

tar -xvf memcache-2.2.5.tgz

5. Open the directory.

cd memcache-2.2.5

6. Install the memchaced PHP extension.

phpize && ./configure –enable-memcache && make

7.  Copy the extension.

cp modules/memcache.so {PHP extension directory}

8. Edit your php.ini and add the following line.

extension=memcache.so

9. Last is restart your webserver.

10. If you check your server using a phpinfo page you should now see a MemCache section on the page. You can now fully use the MemCache functionality in your PHP.

memcached pre-requissites

yum -y install libevent libevent-devel

How to make memcached run automatically when you restart your server?. Add this line to rc.local

#!/bin/sh
echo “# Start memcached” >> /etc/rc.local
echo “/usr/local/bin/memcached -d -m 1024 -u httpd -l 127.0.0.1″ >> /etc/rc.local

How to have a multiple memcached server.

Create LocalSettings.php file and this line.

$wgMainCacheType = CACHE_MEMCACHED;
$wgParserCacheType = CACHE_MEMCACHED; # optional
$wgMessageCacheType = CACHE_MEMCACHED; # optional
$wgMemCachedServers = array( “127.0.0.1:11211″ );

$wgSessionsInMemcached = true; # optional

To use multiple servers (physically separate boxes or multiple caches on one machine on a large-memory x86 box), just add more items to the array. To increase the weight of a server (say, because it has twice the memory of the others and you want to spread usage evenly), make its entry a subarray:

$wgMemCachedServers = array(“127.0.0.1:11211″, # one gig on this box
array(“127.0.0.1:11211″, 2 ) # two gigs on the other box
);

Security Note:

Memcached has no security or authentication. Please ensure that your server is appropriately firewalled,
and that the port(s) used for memcached servers are not publicly accessible. Otherwise, anyone on the internet can put data into and read data from your cache.

ENJOY FRIENDS AND MAKE EASY¡¡¡¡¡¡¡¡¡¡¡