1. Introduction of
repcached Repcached is a Japanese-developed implementation of the memcached replication function. It is a single-master and single-slave solution, but its master/slave are both readable and writable, and can be synchronized with each other. If the master is broken, the slave detects When it detects that the connection is broken, it will automatically listen and become the master; if the slave is broken, the master will also detect that the connection is broken, and it will re-listen to wait for a new slave to join.
2.
Install the memcached service on the two servers respectively. Note that the version of libevent in this article is: libevent-1.4.13, download address: http://www.monkey.org/~provos/libevent-1.4.13-stable .tar.gz
repcached has two ways:
way 1. Download the corresponding repcached version
#wget http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz
#tar zxf memcached- 1.2.8-repcached-2.2.tar.gz #cd
memcached-1.2.8-repcached-2.2
[Method 2, download the corresponding patch version
#wget http://downloads.sourceforge.net/repcached/repcached-2.2-1.2.8.patch.gz
#gzip -cd ../repcached-2.2-1.2.8.patch. gz | patch -p1】
#./configure –enable-replication
# make
# make install
3. Start:
start master
#/usr/local/bin/memcached -v -l 192.168.0.160 -p 11211 -uroot
replication: listen (master listen)
启动salve
#/usr/local/bin/memcached -v -l 192.168.0.163 -p 11213 -uroot -x 192.168.0.160 -X 11212
replication: connect (peer=192.168.0.160:11212)
replication: marugoto copying
replication: start
After the startup is normal, the master will accept.
4. Test:
operate master
#telnet 192.168.0.160 11211
#set key1 0 0 3
blog.5sail.com
查看slave
#telnet 192.168.0.163 11213
#get key1
如果正常显示blog.5sail.com,则表示repcached配置成功
5、应用:
可以实现cache冗余,避免因cache服务器down掉而导致数据丢失。
注意:如果master down机,slave接管并成为master,这时down机的master只能启用slave,他们之间互换角色,才能保持复制功能。换句话说,master没有抢占功能。