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

Reparar todas las tablas de todas las bases de datos de MySQL en Plesk

Para reparar todas las tablas de todas las bases de datos de MySQL en Plesk (Linux) tenemos que poner en una sola linea este pedazo churro:

for database in $(mysql --skip-column-names -uadmin -p`cat /etc/psa/.psa.shadow` -e
"show databases" ); do echo "optmizing tables from $database";
for table in $(mysql --skip-column-names -uadmin -p`cat /etc/psa/.psa.shadow` -e
"show tables" $database ); do echo "-> $table " ;
mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "OPTIMIZE TABLE $table" $database ;
done ; done ;

Cómo chequear, reparar u optimizar tablas o bases de datos MySQL con mysqlcheck

El cliente mysqlcheck comprueba y repara tablas MyISAM. También puede optimizar y analizar tablas.

mysqlcheck es similar a myisamchk, pero funciona de forma distinta. La principal diferencia operacional es que mysqlcheck debe usarse cuando el servidor mysqld está en ejecución, mientras que myisamchk debe usarse cuando no lo está. El beneficio de usar mysqlcheck es que no tiene que parar el servidor para comprobar o reparar las tablas.

mysqlcheck usa los comandos SQL CHECK TABLE, REPAIR TABLE, ANALYZE TABLE, y OPTIMIZE TABLE de forma conveniente para los usuarios. Determina los comandos a usar en función de la operación que quiera realizar, luego envía los comandos al servidor para ejecutarlos.

Hay tres modos generales de invocar mysqlcheck:

shell> mysqlcheck [opciones] nombre_de_base_de_datos [tablas]
shell> mysqlcheck [opciones] –databases DB1 [DB2 DB3…]
shell> mysqlcheck [opciones] –all-databases

Si no nombra ninguna tabla o usa las opciones –databases o –all-databases, se comprueban todas las bases de datos.

mysqlcheck soporta las siguientes opciones:

Continuar leyendo «Cómo chequear, reparar u optimizar tablas o bases de datos MySQL con mysqlcheck»