java使用memcached2--集群部署

一、集群安装

  1.编译安装magent-0.5到/usr/local/下

# cd /usr/local
# mkdir magent
# cd magent/
# wget http://memagent.googlecode.com/files/magent-0.6.tar.gz
# tar zxvf magent-0.6.tar.gz

  2. # vim ketama.h

  开头添加

#ifndef SSIZE_MAX
# define SSIZE_MAX      32767
#endif

  3. # vim Makefile

CFLAGS = -Wall -O2 -g 改为 CFLAGS = -lrt -Wall -O2 -g

  4.编译

# cp /usr/lib/libevent.a /usr/lib64
# ln -s /usr/lib64/libm.so /usr/lib64/libm.a
# /sbin/ldconfig
# sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
# make
# cp magent /usr/bin/magent
# cd ..

二、使用实例

memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
memcached -m 1 -u root -d -l 127.0.0.1 -p 11213
magent -u root -n 51200 -l 127.0.0.1 -p 12000 -s 127.0.0.1:11211 -s 127.0.0.1:11212 -b 127.0.0.1:11213 

三、测试

  # telnet 127.0.0.1 12000

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set test1 0 0 5
test1
STORED
set test2 0 0 5
test2
STORED
quit
Connection closed by foreign host.

  # telnet 127.0.0.1 11211

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get test1
VALUE test1 0 5
test1
END
get test2
END
quit
Connection closed by foreign host.

  # telnet 127.0.0.1 11212

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get test1
END
get test2 
VALUE test2 0 5
test2
END
quit
Connection closed by foreign host.

  # telnet 127.0.0.1 11213

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get test1
VALUE test1 0 5
test1
END
get test2
VALUE test2 0 5
test2
END
quit
Connection closed by foreign host.

 四、java应用

  与非集群模式一致,参考

  http://www.cnblogs.com/yangmengdx3/p/4716388.html

 

posted @ 2015-08-10 14:41  一粒沙的世界  阅读(306)  评论(0编辑  收藏  举报