tar zxvf memcached-1.2.8-repcached-2.2.1.tar.gz
cd memcached-1.2.8-repcached-2.2.1
./configure --enable-replication --program-transform-name=s/memcached/repcached/
make
make install
如果之前没有安装libevent-dev的话,一定编译不过,自然也不能install,如果安装了的话,也不一定能编译过,呵呵。编译错误提示如下
memcached.c:1128:9: 警告: 格式 ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
memcached.c:1135:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1139:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1140:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1141:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1142:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1143:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1144:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1145:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1146:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1147:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘size_t’ [-Wformat]
memcached.c:1150:9: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c:1155:9: 警告: 格式 ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long int’ [-Wformat]
memcached.c: 在函数‘process_get_command’中:
memcached.c:1334:19: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
memcached.c: 在函数‘do_add_delta’中:
memcached.c:1576:5: 警告: 格式 ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ [-Wformat]
原因也很明显,代码的移植性并没有考虑到在多个多个不同的系统上uint64_t这个类型的定义,我的系统是ubuntu 64位。当然,还有其他类型不匹配的地方,如果你有代码洁癖的话,可以逐个去改,并不麻烦,如果像我一样只是想试用一下功能而已的话呢,就当warning不存在,继续用吧。
下面是启动repcached,同样,很多参数用默认
telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set hello 0 0 3
123
STORED
telnet localhost 11212
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get hello
VALUE hello 0 3
123
END
也可以测试删除或者其他什么的,不贴了,基本和单机差不多。下面模拟一下其中一个repcached挂了,假设是master挂了,用kill干掉master的进程,连接master的telnet立刻就提示连接被关闭,这时候去看slave上的数据
get hello
VALUE hello 0 3
123
END
数据依然在,这时候再去启动master似乎恢复不了shutdown之前的状况,这是因为我们在启动的时候没有指定复制端口号,用-X选项
get hello
VALUE hello 0 3
123
END
至此,repcached的试用结束,虽然在某些程度上repcached已经实现了某种程度上的高可用,但是这种实现并不足够。比如,repcached只支持1.2.x版本的memcached,如果想用的话,还要把高版本的memcached删掉;再比如,repcached只支持两个进程互相传数据,再启一个进程就不能复制数据。这些在试用中都不能完成