how to install memchached 1.2.2 from source

I have installed an instance of memchached version 1.2.2 on one of our servers (Debian etch) today and to keep you from spending a whole afternoon, see my everything-step-by-step instruction below.

Memchached is a distributed hash map, which can be used for example to speed up any kind of web application, see website for details. In our case, we want to use it as temporary data store. I will report about the experiences in a latter post.

introduction

Always refer to this page for details, but I created a version with less text but including steps to really start from scratch.

All lines starting with # are command lines, i.e. you need to type into a linux shell.
Output of any kind is always surrounded by ” even if it is multiline output.

content

a. get libevent (needed to install memcached)
b. get memcached and verify installation
c. use and test memcached within Java with junit/ant

a. installing libevent 1.3

a.1. check for current version of libevent

a.1a.

Log in as root or get super user rights by calling su

# updatedb
# locate libevent

If there is output including “libevent1” and/or “libevent-1” (ignore package files like *.deb) -> a.1b, otherwise a.2

a.1b. removing old libevent version

# apt-get remove –purge libevent1
# Y

# updatedb
# locate libevent
Should now return nothing or package files only, i.e. you are ready for installation

a.2. installing libevent 1.3

a.2a downloading and unpacking

# cd /usr/local/src
# wget http://monkey.org/~provos/libevent-1.3b.tar.gz
# tar zxvf libevent-1.3b.tar.gz
# cd libevent-1.3b

a.2b. configuring

# ./configure
check the output, if it contains something like “configure: error: no acceptable C compiler found in $PATH” -> a.2c. otherwise a.2d.

a.2c. compiling

# apt-get install gcc

Redo a.2b.
I got output like “C compiler cannot create executables”, reading file ‘config.log’ did not help me at all. Googling finally did, as I found a forum entry, pointing out a missing lib.
So try this:

# apt-get install libc-dev

Redo a.2b.
If that did  not solve it… sorry … google on, there is no sense in going on without solving this issue. :-/

a.2d. make it!

# make && make install

If you get something like “-bash: make: command not found” -> A.2e, otherwise A.3.

a.2e.

# apt-get install make

Redo a.2d.

a.3. configuration

Press the Esc key as you read [esc] in the commands below.

# vim /etc/ld.so.conf.d/libevent-i386.conf
# i/usr/local/lib/[esc]:wq
# ldconfig

b. install memchached and verify installation

b.1. download, unpack and install memchached

# cd /usr/local/src
# wget http://danga.com/memcached/dist/memcached-1.2.2.tar.gz
# tar zxvf memcached-1.2.2.tar.gz
# cd memcached-1.2.2
# ./configure
# make && make install

After installing gcc and libc-dev in section a, this one went easily for me – if you skipped section a and run in problems here, please install gcc and libc-dev (see a.2c).

b.2. verify installation of memchached

b.2a. start memchached server

# memcached -u www-data -vv

Output should end with line “<3 server listening”. Perfect! 🙂

b.2b test server

I will refer to this shell in front of you as server shell below. Now, open another shell on the same machine, I will refer to it a client shell.

# telnet localhost 11211

You should see something like “<7 new client connection” on the server shell, switch back to client shell.

# set test1 1 10000 1
# a

You should see “STORED” on client shell and the two following lines on server shell
“<7 set test1 1 10000 1
>7 STORED”

Perfect!
You did it, your memcached is up and running 🙂

c. memcached and Java

I wrote a little test package using a Java client library for memcached from here, together with junit and ant. You can download it to have a look how simple using memcache is and to verify your installation with an included  junit test, automated with an ant build file.