Repcached implements memcached memory replication + keepalived Master/Slave Mode

Source: Internet
Author: User

Repcached implements memcached memory replication + keepalived Master/Slave Mode

Repcached Introduction

Repchched Project address: http://repcached.sourceforge.net/

Repcached

"Repcached" is a patch set. It adds the data replication function to memcached 1.4.13, but most of the files circulating on the network are for memcached1.2.8 repcached, this article uses the latest version of memcached1.4.13 as an example to describe the compatibility memory replication function of repcached.

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.13 Repcached patch (Note: The memcached version must be consistent with the memcached-compatible version corresponding to repcached. Otherwise, various incompatibility bugs may occur)

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, there is
./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 gzip format

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 remove https mode switch to http mode try wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz if you can not open the source package, may be Google was blocked, or address migration, please download from the following link address: 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 the local port 192.168.1.10 11211, And the slave is the port 11211 of the 192.168.1.11 server.
/Usr/local/memcached/bin/memcached-d-m-p 11211-u nobody 192.168.1.10-x 192.168.1.11-X 11212-P/tmp/localhost_master.pid-vv

/Usr/local/memcached/bin/memcached-d-m-p 11211-u nobody 192.168.1.11-x 192.168.1.10-X 11212-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 192.168.1.10: 11211 0.0.0.0: * LISTEN 12242/memcached
Udp 0 0 192.168.1.10: 11211 0.0.0.0: * 12242/memcached

Verify Data Synchronization

Create data on the Master:
[Root @ test01 bin] # telnet 192.168.1.10 11211

Trying 192.168.1.10...
Connected to 192.168.1.10.
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 192.168.1.11 11211

Trying 192.168.1.11...
Connected to 192.168.1.11.
Escape character is '^]'.
Get key1
VALUE key1 0 2
Aa
END
Quit
Connection closed by foreign host.

Create data in Slave:
[Root @ test02 bin] # telnet 192.168.1.11 11211

Trying 192.168.1.11...
Connected to 192.168.1.11.
Escape character is '^]'.
Get key2
END
Set key2 0 0 3
Bbb
STORED
Get key2
VALUE key2 0 3
Bbb
END
Quit
Connection closed by foreign host.

Obtain data from the Master:
[Root @ test01 bin] # telnet 192.168.1.10 11211

Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
Get key2
VALUE key2 0 3
Bbb
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.
The following are keppalived configuration information, which is not a majority here. I believe everyone is familiar with the role of keepalived.
MASTER host configuration information
! Configuration File for keepalived

Global_defs {
Notification_email {
Happy.yin@qq.com
}
Notification_email_from zqtsx@email.com
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}

Vrrp_instance VI_1 {
State MASTER
Interface eth1
Virtual_router_id 51
Priority 101 host is 101
Advert_int 1
Authentication {
Auth_type PASS verification type
Auth_pass 1111 verify that the password is changed by yourself. Remember that the password on the master and backup machines must be consistent.
}
Virtual_ipaddress {
192.168.1.120 virtual IP Address
}
}

SLAVE Configuration
! Configuration File for keepalived

Global_defs {
Notification_email {
Happy.yin@qq.com
}
Notification_email_from zqtsx@email.com
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}

Vrrp_instance VI_1 {
State MASTER
Interface eth1
Virtual_router_id 51
Priority 100 slave is 100
Advert_int 1
Authentication {
Auth_type PASS verification type
Auth_pass 1111 verify that the password is changed by yourself. Remember that the password on the master and backup machines must be consistent.
}
Virtual_ipaddress {
192.168.1.120 virtual IP Address
}
}

Use a virtual IP address to access memcached
[Root @ localhost happy] # telnet 192.168.1.12011211
Trying 192.168.1.120...
Connected to 192.168.1.120.
Escape character is '^]'.
Set key 0 0 6
123456
STORED
Get key
VALUE key 0 6
123456
END
Get key1
VALUE key1 0 2
Aa
END
Quit
Connection closed by foreign host.
OK keepalived + memcached the Master/Slave mode has been set up. Next we will stop the keepalived simulation down machine on one machine, and then use the virtual IP address 192.168.1.120 to link memcached and read and write it, check whether the memcached data can be accessed normally, and check whether the Master/Slave Mode is sound.
[Root @ localhost happy] # telnet 192.168.1.12011211
Trying 192.168.1.120...
Connected to 192.168.1.120.
Escape character is '^]'.
Get key
VALUE key 0 6
123456
END
Get key1
VALUE key1 0 2
Aa
END
Quit
Connection closed by foreign host.

OK MEMCACHED: Everything is normal. Not only does memcached implement memory replication, but keepalived also runs normally. So far, a complete and reliable memcached Master/Slave mode has been built...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.