Installing memcached with repcached patch for HA memcache cluster

About

Repcached is an interesting patch for memcached which allows replication between 2 memcached nodes (servers). The purpose of this article is to setup 2 memcached servers that replicate each others.

Note: This article is specifically written for Ubuntu 12.04 and memcached version 1.4.13. It may or it may not work for other versions.

Setup

2x 512MB RackSpace instances called node01(IP 10.0.0.1) and node02(IP 10.0.0.2)

Patch for memcached v1.4.13:
https://github.com/usecide/repcached/blob/master/repcached-2.3.1-1.4.13.patch

Build

Prepare to build the package:

apt-get build-dep memcached
apt-get source memcached
cd memcached-1.4.13
wget https://github.com/usecide/repcached/blob/master/repcached-2.3.1-1.4.13.patch
patch -p1 -i repcached-2.3.1-1.4.13.patch

Now edit the file debian/rules and look for config.status and add –enable-replication like this:

config.status: configure
        dh_testdir
        CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) \
                                       --build=$(DEB_BUILD_GNU_TYPE) \
                                       --prefix=/usr \
                                       --mandir=\$${prefix}/share/man \
                                       --enable-replication \
                                       --infodir=\$${prefix}/share/info

Now build the package:

dpkg-buildpackage -us -uc -nc
cd ..

You should see a package named memcached_1.4.13-0ubuntu2_amd64.deb. Copy this file on both of your memcached servers and install it using this command:

dpkg -i memcached_1.4.13-0ubuntu2_amd64.deb

Configuration

You are almost done now. Kill all running memcached processes on both nodes:

killall -9 memcached
ps aux | grep memcached

On node01 do the following things:

cp /etc/memcached.conf /etc/memcached_server1.conf

Edit /etc/memcached_server1.conf and replace the line:

-l 127.0.0.1 

with

-l 10.0.0.1

and add at the end:

-x 10.0.0.2

Start memcached:

service memcached start

On node02 do something similar:

cp /etc/memcached.conf /etc/memcached_server2.conf

Edit /etc/memcached_server2.conf and replace the line:

-l 127.0.0.1 

with

-l 10.0.0.2

and add at the end:

-x 10.0.0.1

Start memcached:

service memcached start

Testing

From node01:

telnet 10.0.0.1 11211:
Escape character is '^]'.
get hello
set hello 0 0 4
abcd
get hello
VALUE hello 0 4
abcd

From node02:

telnet 10.0.0.2 11211:
Escape character is '^]'.
get hello
VALUE hello 0 4
abcd

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