Configure Memcache server and implement master slave replication (repcached)

  • 2020-05-06 12:00:19
  • OfStack

1, repcached introduces
repcached is the Japanese development of memcached replication function, it is a single master single slave solution, but its master/slave are all readable and synchronous, if master is broken, slave detected a broken connection, it will automatically listen master; If slave fails, master will also detect a broken connection, and it will wait for a new slave to join

2, install
On both servers installation memcached service respectively, the other note libevent version of this article: libevent - 1.4.13, download address: http: / / www monkey. org / ~ provos/libevent - 1.4.13 - stable. tar. gz
repcached comes in two forms:
Method 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.. Es56en-2.2-1.2.8. patch. gz #. / configure � enable - replication
# make
# make install

3, boot:
Start the master
#/usr/local/bin/memcached -v -l 192.168.0.160 -p 11211 -uroot
replication: listen (master listening)

starts 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 starting normally, master will accept.

4. Test:
Operating master
#telnet 192.168.0.160 11211
#set key1 0 0 3
blog.5sail.com

Check the slave
#telnet 192.168.0.163 11213
#get key1
If blog.5sail.com is displayed normally, repcached configuration of
is successful
5. Application:
Redundancy of cache can be realized to avoid data loss caused by cache server down dropping.

Note: if master down machine, slave takes over and becomes master, then master on down machine can only enable slave, and they switch roles to maintain replication. In other words, master does not preempt.

Related articles: