Skip to content

FAQ: Installation: Memcached Server

Joe Cartonia edited this page Mar 15, 2021 · 4 revisions

Installation

Debian / Ubuntu

apt-get -y install memcached

CentOS / RedHat / Other Linux

yum -y install libevent libevent-devel memcached

Manual Installation

If none of the above works, you can install it manually.

Install Libevent

cd /usr/local/src
wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar -xzf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
./configure && make && make install

Installation was successful if the output you see looks like this:

Libraries have been installed in: /usr/local/lib

Then:

echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent.conf
ldconfig -v

Install Memcached

cd /usr/local/src
wget https://memcached.org/files/memcached-1.6.9.tar.gz
tar -xzf memcached-1.6.9.tar.gz
cd memcached-1.6.9
./configure --enable-threads --enable-64bit && make && make install

Configure 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 -e "PORT=\"11211\"\nUSER=\"memcached\"\nMAXCONN=\"1024\"\nCACHESIZE=\"64\"\nOPTIONS=\"\"" > /etc/sysconfig/memcached

Start Memcached and enable on boot

CentOS 6

service memcached start
chkconfig --add memcached
chkconfig memcached on

CentOS 7

systemctl start memcached.service
systemctl enable memcached.service

If you performed a manual installation then you may need to create a service configuration file before you can enable the service on boot.

Create a file /usr/lib/systemd/system/memcached.service with the following contents:

[Unit]
Description=Memcached
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

[Install]
WantedBy=multi-user.target