Memcached memory replication/master-slave mode-mecached1.4.13, memcached master-slave
Repcached Introduction
Repchched Project address: http://repcached.sourceforge.net/
Repcached
"Repcached" is a patch set that adds the data replication feature to memcached 1.2.x.
Main Purpose
Implement the redundant memcached System
Main functions
Multi-master replication and asynchronous data replication support all memcached commands (set, add, delete, incr/decr, flush_all, cas ).
Memcached 1.4.x Repcached patch
Address: http://mdounin.ru/
Latest Patch: http://mdounin.ru/files/repcached-2.3.1-1.4.13.patch.gz
Working Principle
Repcached implements the memcached replication function. It is a single master single slave solution, but the master/slave can be read and written and can be synchronized with each other, if the master node breaks down the slave and detects that the connection is disconnected, it will automatically listen and become the master node. In this case, the crashed master node can only be enabled as the slave node, and roles can be exchanged between them to maintain the replication function. In other words, the master node does not have the preemption function. If the slave fails, the master node will detect a disconnection and relisten will wait for the new slave to join.
Application scenarios
When memcached is used for session sharing or other services, there will be a single point of failure (spof) of memcached. If memcached is down, the entire system user cannot log on to the session ).
Based on this situation, use repcached for memcached master-slave Redundancy
Warning the repcached memory replication plug-in version must be the same as the memcached version. Otherwise, various errors such as version incompatibility may occur!
The repcached plug-in must be installed on both the master and slave machines.
Wget https://memcached.googlecode.com/files/memcached-1.4.13.tar.gz wget http://mdounin.ru/files/repcached-2.3.1-1.4.13.patch.gz tar zxvf memcached-1.4.13.tar.gz gzip-d repcached-2.3.1-1.4.13.patch.gz cd memcached-1.4.13 patch-p1-I .. /repcached-2.3.1-1.4.13.patch the following command path to switch to your own installation directory, and. /configure -- prefix =/usr/local/mecached -- with-libevent =/usr/local/libevent -- enable-replication make & make install
Errors and solutions:
Error 1:
The following error occurs when extracting the repcached file:
Gzip: stdin: not in gzipFormat
Tar: Child returned status 1
Tar: Exited due to the previous delay error
This is because the download link of an object is not directly directed to the object, but to a page first, which is the actual download link. Therefore, you can directly Save the object on the previous page, actually, a page is saved.
Solution:
First, use the file command to view the real attributes of the file. Select the decompress command based on the actual attributes to solve the problem. If such an error occurs, remember to view the real attributes of the file, here I get file properties file repcached-2.3.1-1.4.13.patch.gz is actually html file type, good guy, no wonder it will prompt not gzip type file, the original download link is the html page Jump address downloaded under wget. Enter (as shown below) in the browser and press enter to get the original real repcached gzip package.
http://mdounin.ru/files/repcached-2.3.1-1.4.13.patch.gz
Error 2:
The following Google memcached source code package cannot be opened:
wget https://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
Try to use http instead of https.
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
If the source code package cannot be opened yet, Google may have been blocked or the address has been migrated. Download the package from the following link:
Csdn memcached-1.4.13: http://download.csdn.net/detail/liaowuxukong/4578543
After the installation is complete, start the master-slave memcached server. The host is port 127.0.0.1 11211, And the slave is port 11222 of the 10.0.2.15 server.
/Usr/local/memcached/bin/memcached-d-m-p 11211-u nobody-l 127.0.0.1-x 10.0.2.15-X 11222-P/tmp/localhost_master.pid-vv
/Usr/local/memcached/bin/memcached-d-m-p 11222-u nobody-l 10.0.2.15-x 127.0.0.1-X 11211-P/tmp/localhost_slave.pid-vv
Parameter description:
-X sets the IP address from which to synchronize data.
-X indicates the data synchronization port.
View port
Netstat-tupln | grep memcached
Tcp 0 0 127.0.0.1: 11211 0.0.0.0: * LISTEN 12242/memcached
Udp 0 0 127.0.0.1: 11211 0.0.0.0: * 12242/memcached
Verify Data Synchronization
Create data on the Master:
[Root @ test01 bin] # telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key1
END
Set key1 0 0 2
Aa
STORED
Quit
Connection closed by foreign host.
Get data in Slave:
[Root @ test02 bin] # telnet 10.0.2.15 11222
Trying 10.0.2.15...
Connected to 10.0.2.15.
Escape character is '^]'.
Get key1
END
Get key1
VALUE key1 0 2
Aa
END
Quit
Connection closed by foreign host.
Create data in Slave:
[Root @ test02 bin] # telnet 10.0.2.15 11222
Trying 10.0.2.15...
Connected to 10.0.2.15.
Escape character is '^]'.
Get key2
END
Set key2 0 0 3
B
STORED
Get key2
VALUE key2 0 3
B
END
Quit
Connection closed by foreign host.
Obtain data from the Master:
[Root @ test01 bin] # telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key2
VALUE key2 0 3
B
END
Quit
Connection closed by foreign host.
Memcached High Availability
When starting Master and Slave, do not add the-l parameter to specify the listening address. Otherwise, keepalived cannot listen to the VIP address.
Then, keepalived can be configured as high availability.
For more information about how to install the Mecached and php memcached extensions, see another blog on the top of the sky: http://blog.csdn.net/zqtsx/article/details/26720849.
The software package used in this tutorial
Memcached1.4.13
Http://download.csdn.net/detail/zqtsx/8910705
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.