memcached cluster master-slave

来源:互联网 发布:js获取app版本号 name 编辑:程序博客网 时间:2024/06/05 20:34

When I was looking for ways to replicate the contents of memcached for high-availability performance, I found thismemcached-repcached application. that has the ability to replicate the contents of one memcached to another.

Repcached key features

  • Multi master replication.
  • Asynchronous data repliacation.
  • Support all memcached command (set, add, delete, incr/decr, flush_all, cas)

People probably already know about memcached . It’s a robust, high performance key-value based memory object cache interface. but unfortunately, lack the ability to create redundancy and replication in memcached server clusters. although replication could be done at the application level. However, it all depends on each individual’s taste.

This is a quick and dirty experiment I have tried using memcached-repcached application on 2 servers.

Download memcached-repcached from repcached.lab.klab.org
Or you can download source rpm version from here
memcached-1.2.8-repcached-2.2-1.src.rpm (104)

On the first server and second server extract memcached-1.2.8-repcached-2.2.tar.gz, compile with–enable-replication option when configure.

?
1
2
3
4
$ tarxvzf memcached-1.2.8-repcached-2.2.tar.gz
$ cdmemcached-1.2.8-repcached-2.2
$ ./configure--enable-replication
$ make


On the first server, while still being in the directory when doing the compilation, run this command

?
1
2
3
4
5
[first server]$ ./memcached-u nobody -l 192.168.1.1 -p 22122 -m 64 -x 192.168.1.2 -v
replication: connect (peer=192.168.1.2:11212)
replication: marugoto copying
replication: close
replication: listen

On the second server, also run this command

?
1
2
3
4
[second server]$ ./memcached-u nobody -l 192.168.1.2 -p 22122 -m 64 -x 192.168.1.1 -v
replication: connect (peer=192.168.1.1:11212)
replication: marugoto copying
replication: start

Now, let’s try to simulate the process of replication on both memcached server.

?
01
02
03
04
05
06
07
08
09
10
11
12
13
[third server]$ telnet 192.168.1.1 22122
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is'^]'.
set hey 0 0 4
dude
STORED
get hey
VALUE hey 0 4
dude
END
quit
Connection closed by foreign host.

We stored a value “dude” with the key “hey” and verified with “get hey” command.

Now connecting to the second memcached server.

?
01
02
03
04
05
06
07
08
09
10
[third server]$ telnet 192.168.1.2 22122
Trying 192.168.1.2...
Connected to 192.168.1.2.
Escape character is'^]'.
get hello
VALUE hello 0 5
world
END
quit
Connection closed by foreign host.

We got the same result on a second memcached server. recent memcached-repcached only capable for 2 node replication setup only. but it was pretty good.:)


原创粉丝点击