How to install Memcached on CentOS

Memcached (Daemon) Installation on CentOS:

  1. Try to install with yum:
    # yum install libevent libevent-devel

    If this succeeds skip to #5. If this fails, then let’s compile. Download and extract the latest stable version:

    # cd /usr/local/src && wget http://monkey.org/~provos/libevent-2.0.14-stable.tar.gz && tar -xzf libevent-2.0.12-stable.tar.gz && cd libevent-2.0.12-stable
  2. Let’s compile:
    # ./configure && make && make install
  3. In the output you should see:
    Libraries have been installed in: /usr/local/lib

    If so you can:

    # echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent.conf
  4. Configure your server for the new install:
    # ldconfig -v
  5. Now find the latest stable memcached, download and extract:
    # cd /usr/local/src && wget http://memcached.googlecode.com/files/memcached-1.4.6.tar.gz && tar -xzf memcached-1.4.6.tar.gz && cd memcached-1.4.6
  6. Let’s compile:
    # ./configure && make && make install
  7. Make sure memcached is starts automatically on server boot:
    # touch /etc/init.d/memcached
    # echo '#!/bin/sh -e' >> /etc/init.d/memcached
    # echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody -l localhost' >> /etc/init.d/memcached
    # chmod u+x /etc/init.d/memcached
    # echo '/etc/init.d/memcached' >> /etc/rc.local
  8. And finally, let’s start memcached:
    # /etc/init.d/memcached