[文章作者:张宴 本文版本:v1.0 最后修改:2009.01.19 转载请注明原文链接:http://blog.zyan.cc/post/393/]

  magent是一款开源的Memcached代理服务器软件,其项目网址为:

  http://code.google.com/p/memagent/

  一、安装步骤:
  1、编译安装libevent:
wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
tar zxvf libevent-1.4.9-stable.tar.gz
cd libevent-1.4.9-stable/
./configure --prefix=/usr
make && make install
cd ../


  2、编译安装Memcached:
wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
tar zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6/
./configure --with-libevent=/usr
make && make install
cd ../


  3、编译安装magent:
mkdir magent
cd magent/
wget http://memagent.googlecode.com/files/magent-0.5.tar.gz
tar zxvf magent-0.5.tar.gz
/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

  1、分别在11211、11212、11213端口启动3个Memcached进程,在12000端口开启magent代理程序;
  2、11211、11212端口为主Memcached,11213端口为备份Memcached;
  3、连接上12000的magent,set key1和set key2,根据哈希算法,key1被写入11212和11213端口的Memcached,key2被写入11212和11213端口的Memcached;
  4、当11211、11212端口的Memcached死掉,连接到12000端口的magent取数据,数据会从11213端口的Memcached取出;
  5、当11211、11212端口的Memcached重启复活,连接到12000端口,magent会从11211或11212端口的Memcached取数据,由于这两台Memcached重启后无数据,因此magent取得的将是空值,尽管11213端口的Memcached还有数据(此问题尚待改进)。



  三、整个测试流程:
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
memcached agent v0.4
matrix 1 -> 127.0.0.1:11211, pool size 0
matrix 2 -> 127.0.0.1:11212, pool size 0
END
set key1 0 0 8
zhangyan
STORED
set key2 0 0 8
zhangyan
STORED
quit
Connection closed by foreign host.


[root@centos52 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.


[root@centos52 ~]# telnet 127.0.0.1 11212
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
END
quit
Connection closed by foreign host.


[root@centos52 ~]# telnet 127.0.0.1 11213
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.


模拟11211、11212端口的Memcached死掉
[root@centos52 ~]# ps -ef | grep memcached
root      6589     1  0 01:25 ?        00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
root      6591     1  0 01:25 ?        00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
root      6593     1  0 01:25 ?        00:00:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11213
root      6609  6509  0 01:44 pts/0    00:00:00 grep memcached
[root@centos52 ~]# kill -9 6589
[root@centos52 ~]# kill -9 6591
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 8
zhangyan
END
get key2
VALUE key2 0 8
zhangyan
END
quit
Connection closed by foreign host.


模拟11211、11212端口的Memcached重启复活
[root@centos52 ~]# memcached -m 1 -u root -d -l 127.0.0.1 -p 11211
[root@centos52 ~]# memcached -m 1 -u root -d -l 127.0.0.1 -p 11212
[root@centos52 ~]# telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
END
get key2
END
quit
Connection closed by foreign host.






技术大类 » Cache与存储 | 评论(97) | 引用(8) | 阅读(106077)
shz Email
2022-8-4 22:07
Two full thumbs up for this magneficent article of yours. I've really enjoyed reading this article today and I think this might be one of the best article that I've read yet. Please, keep this work going on in the same quality.  Scam Risk
shz Email
2022-8-4 22:12
Cool stuff you have and you keep overhaul every one of us  Scam Risk
shzz Email
2022-8-4 22:14
It is imperative that we read blog post very carefully. I am already done it and find that this post is really amazing.  Scam Risk
shzz Email
2022-8-4 22:30
I’ve read some good stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to create such a great informative website.  Scam Risk
shz Email
2022-8-27 23:07
Super site! I am Loving it!! Will return once more, Im taking your food likewise, Thanks.  iPage
shzz Email
2022-8-27 23:10
Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long. I will need this post to total my assignment in the college, and it has exact same topic together with your write-up. Thanks, good share.  Banyan Hill
shz Email
2022-8-27 23:10
I just couldn't leave your website before telling you that I truly enjoyed the top quality info you present to your visitors? Will be back again frequently to check up on new posts.  Chad Kimball
shzz Email
2022-8-27 23:15
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!  Banyan Hill
shz Email
2022-8-27 23:15
The article posted was very informative and useful. You people are doing a great job. Keep going.  Chad Kimball
shz Email
2022-8-27 23:17
Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me  Chad Kimball
shzz Email
2022-8-27 23:18
Thumbs up guys your doing a really good job.  Banyan Hill
shzz Email
2022-8-27 23:23
If your looking for Online Illinois license plate sticker renewals then you have need to come to the right place.We offer the fastest Illinois license plate sticker renewals in the state.  Jamil Damji
shz Email
2022-8-27 23:24
When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your.  Jamil Damji
shzz Email
2022-8-27 23:35
Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.  Jamil Damji
candy Email
2022-9-30 17:35
It is a top-notch website. It was wonderful to read your essay on mapquest driving directions. For me, this is an excellent document. I bookmarked this page and will return to read any new entries.
abel1303 Email Homepage
2023-5-15 11:15
The article is well-organized rankdle and structured, making it easy to navigate.
Tekek Email Homepage
2023-6-1 19:18
"I'm constantly on the lookout for thought-provoking blogs, and yours definitely stands out. The way you challenge conventional wisdom and provide alternative perspectives is truly inspiring. You've gained a loyal reader in me!"Legendaparafotosozinha.comпоздравлениесднемрождения.com
Lucky cola
2024-2-7 15:06
Step into the arena and prove your gaming prowess.  Lucky cola
Resso MOD APK Email
2024-3-13 23:29
If you want to get fresh music listening experience then visit https://ressomodapk.io/ and download the latest Resso MOD APK on your android device.
分页: 5/6 第一页 上页 1 2 3 4 5 6 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]