Protección para el usuario apache

Este pequeño tip en el user apache me lo encontre en varios servidores a los que «analice» :D, esta bien pensando por el admin que se lo ingenio pero se olvido de securizar otros servicios/usuarios.

Consultamos el directorio de apache en /etc/passwd y aparece algo como
apache:x:48:48:Apache:/var/www:/bin/false
Ai se puede apreciar que su directorio del usuario es /var/www
Me dirijo a ese directorio y creo un archivo llamado .bashrc y en el solo escribo exit
lo guardo y listo; lo mismo con los otros usuarios que se deseen bloquear

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

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¡¡¡¡¡¡¡¡¡¡¡

Restablecer los permisos predeterminados en el directorio del virtualhost en Plesk

Síntomas

Algunos archivos y directorios del dominio han perdido sus permisos. Varios de ellos son propiedad del usuario “apache” o “root” de Apache.

Por ejemplo:

# ls -l /var/www/vhosts/blogofsysadmins.com/
total 48
drwx------ 5 apache     apache 4096 Mar 16 20:07 anon_ftp
drwx------ 2 root       psaserv 4096 Mar 16 20:07 bin
drwx------ 3 apache     apache 4096 Mar 16 20:07 cgi-bin
drwx------ 2 root       psaserv 4096 Aug  4 12:56 conf
drwx------ 2 root       psaserv 4096 Mar 16 20:07 error_docs
drwx------ 7 apache     apache 4096 Mar 16 20:07 httpdocs
drwx------ 7 apache     apache 4096 Mar 16 20:07 httpsdocs
drwx------ 2 root       psaserv 4096 Aug  4 12:56 pd
drwx------ 2 root       root    4096 Mar 16 20:07 private
dr-x------ 7 root       psaserv 4096 Mar 16 20:07 statistics
drwx------ 2 root       psaserv 4096 Mar 16 20:07 subdomains
drwx------ 2 root       psaserv 4096 Mar 16 20:07 web_users
~#

Cuando intento cargar archivos a través del Administrador de Archivos o de un cliente FTP, obtengo los errores «Permiso denegado» o «Acceso denegado«.

Resolución

Use la utilidad «vhostmng» para restablecer los permisos. El comando a ejecutar es el siguiente:

~# /usr/local/psa/admin/sbin/vhostmng --install-vhost --vhost-name=<domain name> --user-name=<username> --set-content-permissions

Donde <domain name> es el dominio donde deben restaurarse los permisos y <username> es el usuario FTP del dominio configurado en Parallels Plesk Panel en la página Dominios -> <domain name> -> Opciones de Alojamiento Web (versión 9.x) o Dominios -> <domain name> -> Configuración (versión 8.x).

El comando restaurará los permisos predeterminados en el directorio del virtualhost:

drwxr-x--- 5 ftp_user   psaserv 4096 Mar 16 20:07 anon_ftp
drwxr-xr-x 2 root       psaserv 4096 Mar 16 20:07 bin
drwxr-x--- 3 ftp_user   psaserv 4096 Mar 16 20:07 cgi-bin
drwxr-x--- 2 root       psaserv 4096 Aug  4 12:56 conf
drwxr-xr-x 2 root       psaserv 4096 Mar 16 20:07 error_docs
drwxr-x--- 7 ftp_user   psaserv 4096 Mar 16 20:07 httpdocs
drwxr-x--- 7 ftp_user   psaserv 4096 Mar 16 20:07 httpsdocs
drwxr-x--- 2 root       psaserv 4096 Aug  4 12:56 pd
drwx------ 2 ftp_user   root    4096 Mar 16 20:07 private
dr-xr-x--- 7 root       psaserv 4096 Mar 16 20:07 statistics
drwxr-xr-x 2 root       psaserv 4096 Mar 16 20:07 subdomains
drwxr-xr-x 2 root       psaserv 4096 Mar 16 20:07 web_users