Thursday, April 5, 2012

Installing memcached on RHEL6 to use with Drupal 7

Recently I decided to switch from memcache to memcached PHP extension to be used with Drupal 7. I followed a great guide from http://www.bxtra.net/articles/2011-03-22/how-to-install-memcached-on-centos-memcached-pecl-update-20110322 but made some modifications to work with RHEL 6 / CentOs 6.
# Get libvent
wget http://monkey.org/~provos/libevent-2.0.10-stable.tar.gz
tar -xvf libevent-2.0.10-stable.tar.gz
cd libevent-2.0.10-stable
./configure;make;make install;

# Get the latest version of libmemcached
wget https://launchpad.net/libmemcached/1.0/1.0.5/+download/libmemcached-1.0.5.tar.gz
tar xvfz libmemcached-1.0.5.tar.gz
cd libmemcached-1.0.5
./configure
make && make install

# Get ZLIB headers
yum install zlib-devel

# Remount /tmp with execute permissions 
mount -o remount,exec /tmp

pecl install memcached

# Revert back to a safer configuration
mount -o remount,noexec /tmp

The last step is to add the extension to /etc/php.d/
extension=memcached.so > /etc/php.d/memcached.ini
Now you can update your settings.php in Drupal to take advantage of all the tweaks:
$conf['memcache_options'] = array(

// Turn off compression, as this takes more CPU cycles than its 
// worth for most users
Memcached::OPT_COMPRESSION => FALSE,
// Turn on consistent distribution, which allows you 
// to add/remove servers easily
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
// Highly recommended to enable this option if you want 
// to use consistent hashing
Memcached::OPT_LIBKETAMA_COMPATIBLE => TRUE, 
// Dials down the connection timeout to 50 millisecond
Memcached::OPT_CONNECT_TIMEOUT => 50,
// These are timeouts for the actual send and receive operations sent
// to the Memcached server, this time in microseconds. 
Memcached::OPT_SEND_TIMEOUT => 50000,
Memcached::OPT_RECV_TIMEOUT => 50000,
// A timeout that is used internally for polling the input and output
// streams. This one is back in milliseconds
Memcached::OPT_POLL_TIMEOUT => 50,
// Enable non-blocking sends. This means that PHP immediately regains
// control when sending a value over the wire.
Memcached::OPT_NO_BLOCK => TRUE,
// Nnumber of times to try to connect to a server 
// before ejecting it from a  pool. 
Memcached::OPT_SERVER_FAILURE_LIMIT => 20,
// The number of seconds to wait before trying to add 
// a down server back in to the pool
Memcached::OPT_RETRY_TIMEOUT => 360

);
This is mostly taken from http://blog.roundeights.com/36883753

0 comments:

Post a Comment