Libevent-repcached-memcached
由于 Memcached 没有防止单点的措施,因为为了保障 Memcached 服务的高可用,实现高可用的功能,本文引入 Repcached ,通过使用该工具我们可以完成 Memcached 服务的主从功能。
安装顺序:
1. 先安装libevent,因为memcached依赖它; 2. 给memcached打上repcached补丁,支持主从结构,实现高可用; 3. 安装memcached,启用replication;
1. libevent
# wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz -P /tools # ./configure --prefix=/usr/local/ # make && make install
2. repcached && memcached
当前补丁最新位1.4.13,memcached的版本应该一致,否则会出现异常;
# wget https://memcached.googlecode.com/files/memcached-1.4.13.tar.gz -P /tools # wget http://mdounin.ru/files/repcached-2.3.1-1.4.13.patch.gz -P ./ # tar zxvf memcached-1.4.13.tar.gz -C /tools # gzip -d repcached-2.3.1-1.4.13.patch.gz # cd /tools/memcached-1.4.13 # patch -p1 -i ../repcached-2.3.1-1.4.13.patch # ./configure --prefix=/usr/local/ --with-libevent=/usr/local/ --enable-replication # make && make install
3. memcached (with repcached) 主从测试
在本机的两个不同的端口上启动两个memcached实例,一主一从,然后测试相互之间的数据同步。 memcached主从测试在本机的两个不同的端口上启动两个memcached实例,一主一从,然后测试相互之间的数据同步。
3.1 启动两个memcached实例
# memcached -d -m -p 11211 -u root -l 192.168.0.130 -x 192.168.0.129 -X 11222 -P /tmp/localhost_master.pid -vv # memcached -d -m -p 11212 -u root -l 192.168.0.129 -x 192.168.0.130 -X 11222 -P /tmp/localhost_slave.pid -vv
两个实例的端口分别为11211和11212,共同的监听端口为11222。
3.2 通过telnet测试数据的同步
进入master,set两个值
[root@localhost tmp]# telnet 192.168.0.130 11211 Trying 192.168.0.130... <34 new auto-negotiating client connection Connected to 192.168.0.130. Escape character is ‘^]‘. set name 0 0 7 34: Client using the ascii protocol <34 set name 0 0 7 shining >34 STORED replication: pop replication: pop STORED
进入slave,get刚才设置的值
[root@localhost tmp]# telnet 192.168.0.129 11211 Trying 192.168.0.129... <33 new auto-negotiating client connection Connected to 192.168.0.129. Escape character is ‘^]‘. get name 33: Client using the ascii protocol <33 get name >33 sending key name >33 END VALUE name 0 7 shining END
本文出自 “shiningliliang” 博客,请务必保留此出处http://shiningliliang.blog.51cto.com/4984800/1562461
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。