Install Latest Memcached on CentOS 6.x/7.x

We start with installing Memcached via yum. Although the distros install Memcached 1.4.4, its easier to let yum configure startup scripts etc. and upgrade the binary later.

yum install memcached

Memcached requires libevent

mkdir /downloads
cd /downloads
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xvzf lib*
cd lib*
./configure --prefix=/usr
make
make install

Next, install Memcached. Note the prefix. By default it installs to /usr/local folder, by defining prefix option we overwrite the yum copy.

cd /downloads
wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
tar -xvzf mem*
cd mem*
./configure --prefix=/usr
make
make install

Check your Memcached version

memcached -h

If you get this error;

error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

you need to create a link

ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

Check memcached version, if it works you can enable it as a service.

chkconfig memcached on

Finally, to install the PHP module

pecl install memcache

If you want to configure/optimize Memcached

nano /etc/sysconfig/memcached
#Defaults
PORT="11211"
USER="memcached"
MAXCONN="20480"
#Max memory for cache (MB)
CACHESIZE="4096"
# Use -k if you have lots of memory, it locks down all paged memory
# Set -t the number of CPUs
OPTIONS="-k -t 4 -c 1024 -l 127.0.0.1"

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *