You are here: Home / Debian GNU/Linux / Servers / Databases / Install Memcached on Debian

Install Memcached on Debian

by Pierre-Yves Landuré last modified Aug 09, 2013 07:28

Memcached is a key/value database server easing the cache of objects in memory. It is largely used by some PHP CMS (Wordpress, Drupal, Prestashop, ...) for it bring a visible performance boost on server with available RAM. This howto ease the installation of Memcached on Debian

This howto is tested on :

  • Debian 6.0 Squeeze
  • Debian 7.0 Wheezy

Parameters

Provide the cache size (in MB):

MEMCACHE_SIZE="128"

Installation

Install the software:

command apt-get install memcached

The server is now working.

Raise the memory cache size

Apply the configuration :

if [ -n "${MEMCACHE_SIZE}" ]; then
command sed -i -e "s/^-m .*/-m ${MEMCACHE_SIZE}/" \
    '/etc/memcached.conf'
fi

Restart the server :

/etc/init.d/memcached restart

Allow access from the network (dangerous)

This setup is dangerous and can lead to security breaches. Use it only if you know what you are doing !

In order to use the Memcached server from other network hosts, comment the "-l" option :

command sed -i -e "s/^-l /#-l /" \
    '/etc/memcached.conf'

Restart the server :

/etc/init.d/memcached restart

Note : to disable this configuration, use :

command sed -i -e "s/^#-l .*/-l 127.0.0.1/" \
    '/etc/memcached.conf'
/etc/init.d/memcached restart

Statistics

The memcached-tool command display Memcached statistics.

Disply the current memory cache state :

/usr/share/memcached/scripts/memcached-tool 127.0.0.1:11211 display

Display the server load statistics :

/usr/share/memcached/scripts/memcached-tool 127.0.0.1:11211 stats

Dump the cache contents :

/usr/share/memcached/scripts/memcached-tool 127.0.0.1:11211 dump

The Munin monitoring server can graph the Memcached server usage across time.

Thanks