Memcached is a distributed, high-performance, in-memory caching system that is primarily used to speed up sites that make heavy use of databases. It can however be used to store objects of any kind. Nearly every popular CMS has a plugin or module to take advantage of memcached, and many programming languages have a memcached library, including PHP, Perl, Ruby, and Python. Memcached runs in-memory and is thus quite speedy, since it does not need to write to disk. Here’s how to install it on CentOS 6:
Memcached does have some dependencies that need to be in place. Install libevent using yum:
yum install libevent libevent-devel
The memcached install itself starts with
To start installing memcached, change your working directory to /usr/local/src and download the latest memcached source:
Uncompress the tarball you downloaded and change into the directory that is created:
tar xvzf memcached-1.4.15.tar.gz
Memcached is actively developed, so the version used in this tutorial may be out of date by the time you read this. As of this writing, 1.4.15 is the latest stable version. Check memcached.org for a newer version before proceeding with the installation.
Next, configure your Makefile. The simplest way is to run:
Additional configure flags are available and can improve performance if your server is capable. For 64-bit OSes, you can enable memcached to utilize a larger memory allocation than is possible with 32-bit OSes:
If your server has multiple CPUs or uses multi-core CPUs, enable threading:
If your server supports it, you can use both flags:
./configure --enable-threads --enable-64bit
n.b.: if the configure script does not run, you may have to install compiling tools on your server. That is as simple as
yum install gcc
yum install make
Once the configure script completes, build and install memcached:
make && make install
Last but not least, start a memcached server:
memcached -d -u nobody -m 512 -p 11211 127.0.0.1
Put another way, the previous command can be laid out like this:
memcached -d -u [user] -m [memory size] -p [port] [listening IP]
Let’s go over what each switch does in the above command:
- Tell memcached to start up as a backgrounded daemon process
- Specify the user that you want to run memcached
- Set the memory that you want to be allocated my memcached
- The port on which memcached will listen.
And that’s it. Now go forth and speed up your sites!
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.