找回密码
 骑士注册

QQ登录

微博登录

搜索
❏ 站外平台:

Linux中国开源社区 技术 查看内容

Memcached无单点解决方案

2012-07-05 07:54    收藏: 1    

三.Repcached和Magent结合

安装memcached 1.2.8、repcached 2.2.1、magent 0.5

测试流程:

1、启动memcached和magent

开启代理,代理端口为12000,设置127.0.0.1:11211为主,127.0.0.1:11212为从。

magent -u root -p 12000 -s 127.0.0.1:11211 -b 127.0.0.1:11212

启动两个memcached进程,做数据同步,同步端口为11111。

./memcached -u root -d -l 127.0.0.1 -p 11211 -x 127.0.0.1 -X 11111

./memcached -u root -d -l 127.0.0.1 -p 11212 -x 127.0.0.1 -X 11111

2、从代理写入数据,在两台memcached上查看

[root@localhost bin]# telnet 127.1 12000
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set key1 0 0 1
a
STORED
quit
Connection closed by foreign host.
[root@localhost bin]# telnet 127.1 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get key1
VALUE key1 0 1
a
END
quit
Connection closed by foreign host.

 

3. 模拟主或从memcached宕机后,数据是否存在

[root@localhost bin]# ps aux|grep memcached
root    15314  0.0 0.4 3556  2108 ?     Ss   16:03   0:00 ./memcached -u root -d -l 127.0.0.1 -p 11211 -x 127.0.0.1 -X 11111
root    15318  0.0 0.3 3556  1836 ?     Ss   16:04   0:00 ./memcached -u root -d -l 127.0.0.1 -p 11211 -x 127.0.0.1 -X 11111
root    15370  0.0 0.1 4016   696 pts/3 R+   16:09   0:00 grep memcached
[root@localhost bin]# kill 15314
[root@localhost bin]# ps aux|grep memcached
root    15318  0.0 0.3 3556  1836 ?     Ss   16:04   0:00 ./memcached -u root -d -l 127.0.0.1 -p 11211 -x 127.0.0.1 -X 11111
root    15370  0.0 0.1 4016   696 pts/3 R+   16:09   0:00 grep memcached
[root@localhost bin]# telnet 127.1 12000
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set key1 0 0 1
a
STORED
quit
Connection closed by foreign host.
[root@localhost bin]# telnet 127.1 11212
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get key1
VALUE key1 0 1
a
END
quit
Connection closed by foreign host.

4. 模拟主或从memcached恢复后,数据是否存在/同步

[root@localhost bin]# ./memcached -u root -d -l 127.0.0.1 -X 11111
[root@localhost bin]# ps aux|grep memcached
root    15318  0.0 0.4 3556  2112 ?     Ss   16:04   0:00 ./memcached -u root -d -l 127.0.0.1 -p 11211 -x 127.0.0.1 -X 11111
root    15380  0.0 0.3 3556  1808 ?     Ss   16:11   0:00 ./memcached -u root -d -l 127.0.0.1 -p 11211 -x 127.0.0.1 -X 11111
root    15384  0.0 0.1 4016   700 pts/3 R+   16:11   0:00 grep memcached
[root@localhost bin]# telnet 127.1 12000
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set key1 0 0 1
a
STORED
quit
Connection closed by foreign host.
[root@localhost bin]# telnet 127.1 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get key1
VALUE key1 0 1
a
END
quit
Connection closed by foreign host.

优点:

  1. 数据冗余
  2. 两台memcached都可进行读写操作
  3. 可以做多主或多从(未测试)

缺点:

  1. 只支持memcached 1.2.x版本
12
查看其它分页:

最新评论

我也要发表评论

收藏

返回顶部

分享到微信

打开微信,点击顶部的“╋”,
使用“扫一扫”将网页分享至微信。