Magent:Memcached集群代理
Magent是一款开源的Memcached代理服务器软件,其项目网址为 http://code.google.com/p/memagent/,防止单点现象,缓存代理也可以做备份,通过客户端连接到缓存代理服务器,缓存代理服务 器连接缓存服务器。
Notes:¶
- current magent's speed is about 80% of memcached's. finding way to speed it up(not good)
- adding backup server does no harm to magent's performance. (good)
- magent's cpu usage is less than memcached's and has very little memory usage. (good)
一、安装步骤:
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还有数 据(此问题尚待改进)。