Memcached Study

I studied the memcached since yesterday. It’s a good cache implementation used by Twitter,Facebook..etc. Because the official site doesn’t provide the rpm for download and i can’t get the latest version from yum. I learn how to build it from source and also try the repached(for memcached replication but not official)

how to install memcached from source

You can refer to link(i didn’t find this post until i solve the installation XD)

install libevent dependency

I try download the libevent source from website and build it. But i found yum is the easiest. Don’t worry if your libevent version is 1.4.x not 2.0.x. memcached-1.4.15 can be build with libevent-1.4.x

1
yum install libevent-devel

download the memcached-1.x.x.tar from memcached.org and untar

1
tar zxvf memcached-1.x.x.tar

make it

1
2
3
4
5
./configure --prefix=/usr/local/memcached-1.4.x/

make

make install

you may fail in configure and show no libevent dependency. you should add --with-libevent=/usr/local/libevent/(your libevent library folder) in configure

start memcached

1
2
3
cd /usr/local/memcached-1.4.x/bin/

./memcached -u nobody -p 11211 -P /usr/local/memcached-1.4.x/bin/mem.pid -d -v

stop memcached

find the process id from /usr/local/memcached-1.4.x/bin/mem.pid and kill it

how to make memcached cluster

Each memcached node is configured independently in the cluster. They don’t communicate or exchange data. It’s the client’s job to decide which server from the cluster. Clients may use the consistent-hash to choose a memcached node and write/read data.
Memcached make your application performance better but your application have to work correctly even the memcached servers crash. Memcached is not the storage solution.

install memcached with repcache

I upload the related repache patch and memcached-1.4.4 source to Dropbox. You can download from it.

1
wget --no-check-certificate https://dl.dropboxusercontent.com/u/60216960/memcached-1.4.4.zip

patch source before configure

1
patch -p1 -i repcached-2.2-1.4.4.patch

make it

1
2
3
4
5
./configure --enable-replication --prefix=/usr/local/memcached-1.4.4-rep/

make

make install

start memcached with repcache

For example, we have two servers: server 1(192.168.0.103) and server 2(192.168.0.101)
In server 1

1
./memcached -u nobody -v -p 11211 -X 11212

In server 2

1
./memcached -u nobody -v -p 11211 -x 192.168.0.103 -X 11212

test the replication

add key in server 1

1
2
3
telnet 192.168.0.103 11211
add hello 0 0 2
99

read in server 2

1
2
telnet 192.168.0.101 11211
get hello

Comments