一、分别在192.168.1.100、192.168.1.200编译安装
# tar -xvzf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure --prefix=/usr/local
# make && make install


# tar -xvzf tokyocabinet-1.4.47.tar.gz
# cd tokyocabinet-1.4.47
# ./configure --prefix=/usr/local/tokyocabinet --with-zlib=/usr/local
# make && make install


# tar -xvzf tokyotyrant-1.1.41.tar.gz
# cd tokyotyrant-1.1.41
#./configure --prefix=/usr/local/tokyotyrant --with-zlib=/usr/local --with-tc=/usr/local/tokyocabinet
# make && make install


# ulimit -SHn 65535
# echo "ulimit -SHn 65535" >> /etc/profile
# source /etc/profile


二、互为主从设置
在192.168.1.100上执行:
# mkdir -p /data/dbcache
# /usr/local/tokyotyrant/bin/ttserver -host 192.168.1.100 -port 11211 -thnum 8 -dmn -pid /data/dbcache/ttserver.pid -log /data/dbcache/ttserver.log -le -ulog /data/dbcache -ulim 512m -sid 1 -mhost 192.168.1.200 -mport 11211 -rts /data/dbcache/ttserver.rts /data/dbcache/database.tcb#lmemb=1024#nmemb=2048#bnum=10000000


在192.168.1.200上执行:
# mkdir -p /data/dbcache
# /usr/local/tokyotyrant/bin/ttserver -host 192.168.1.200 -port 11211 -thnum 8 -dmn -pid /data/dbcache/ttserver.pid -log /data/dbcache/ttserver.log -le -ulog /data/dbcache -ulim 512m -sid 2 -mhost 192.168.1.100 -mport 11211 -rts /data/dbcache/ttserver.rts /data/dbcache/database.tcb#lmemb=1024#nmemb=2048#bnum=10000000


三、测试
1、命令行测试
在192.168.1.100执行:
# curl -X PUT
http://192.168.1.100:11211/testkey -d "666666"


分别在192.168.1.100、192.168.1.200
# curl
http://192.168.1.100:11211/testkey
# curl http://192.168.1.200:11211/testkey


在192.168.1.200执行:
# curl -X DELETE
http://192.168.1.200:11211/testkey


2、PHP代码测试
# vim index.php
<?php
$mem = new memcache;
$mem->addserver("192.168.1.100", 11211);
$mem->addserver("192.168.1.200", 11211);
$mem->set('mytest', 'hello to here!', 0, 60);
$val = $mem->get('mytest');
echo $val;
?>


# curl http://192.168.1.100:11211/mytest
# curl http://192.168.1.200:11211/mytest