memcache 主从配置

 Rehat 6.0  server 版本配置memcahed 主从关系

据说: memcached配置主从关系,必须得用repcached 版本或repcached插件 !

 下载地址: http://sourceforge.net/projects/repcached/files/repcached/

 下载memcache 2.21-1.2.8-replication2.2.1.tar.gz 带插件的版本

 安装此版本的memcached 必须有libevent支持

下载libevent-1.4.10-stable.tar.gz   切勿最新版本(可能会有replicarion-service错误!)

 下载地址:https://github.com/downloads/libevent/libevent/libevent-1.4.10-stable.tar.gz 

安装 libevent:

[root@admin tars]# tar -zxvf libevent-1.4.10-stable.tar.gz  
[root@admin tars]# cd libevent-1.4.10-stable  
[root@admin libevent-1.4.10-stable]# ./configure --prefix=/usr/local/libevent  
[root@admin libevent-1.4.10-stable]# make && make install 
[root@admin libevent-1.4.10-stable]# cp /usr/local/libevent/lib/libevent-1.4.so.2 /usr/lib/

 PS:必须把 libevent-1.4.so.2 复制到/usr/lib 目录下 否则安装memcached会报错!

安装 memcached

[root@admin tars]# tar -xzfv memcached-1.2.8.tar.gz -C /usr/local/     
[root@admin local]# cd /usr/local
[root@admin local]# mv memcached-1.2.8 memcached
[root@admin local]# cd memcached
[root@admin memcached]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent --enable-replication
[root@admin memcached]# make && make install

 按同样的方式安装到例外一台机器上.

启动memcached:

在172.19.121.125上执行

[root@admin memcached]# ./memcached -d -m 256 -x 172.19.121.162 -u root -p 11211 -v
[root@y162 memcached]# replication: connect (peer=172.19.121.162:11212)
replication: marugoto copying

  在172.19.121.162上执行

[root@y162 memcached]# ./memcached -d -m 256 -x 172.19.121.125 -u root -p 11211 -v
[root@y162 memcached]# replication: connect (peer=172.19.121.125:11212)
replication: marugoto copying

测试:

[root@y162 ~]# telnet 172.19.121.162 11211
Trying 172.19.121.162...
Connected to 172.19.121.162.
Escape character is '^]'.
set usetid 0 0 6
123456
STORED
get usetid
VALUE usetid 0 6
123456
END

查看172.19.121.125 上的memcached

[root@admin ~]# telnet 172.19.121.125 11211
Trying 172.19.121.125...
Connected to 172.19.121.125.
Escape character is '^]'.
get usetid
VALUE usetid 0 6
123456
END

至此memcached 主从配置完成。

若telnet 命令不可用,可使用yum命令安装: yum telnet install

memcacahed安装 参考:http://www.mohancheema.net/howtos/install-memcached-with-repcached-built-in-server-side-replication 

相关推荐