Memcached cluster magent single point of failure solution

Source: Internet
Author: User
1. installation steps: 1. Compile and install libevent: wgethttp: // monkey.org /~ Provos/libevent-1.4.9-stable.tar.gztarzxvflibevent-1.4.9-stable.tar.gzcdlibevent-1.4.9-stable/./configure -- prefix/

1. installation steps:
1. Compile and install libevent:
Wget http://monkey.org /~ Provos/libevent-1.4.9-stable.tar.gz
Tar zxvf libevent-1.4.9-stable.tar.gz
Cd libevent-1.4.9-stable/
./Configure -- prefix =/usr
Make & make install
Cd ../


2. Compile and install Memcached:

Wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
Tar zxvf memcached-1.2.6.tar.gz
Cd memcached-1.2.6/
./Configure -- with-libevent =/usr
Make & make install
Cd ../


3. Compile and install magent:

Mkdir magent
Cd magent/
Wget http://memagent.googlecode.com/files/magent-0.5.tar.gz
Tar zxvf magent-0.5.tar.gz
/Sbin/ldconfig
Sed-I "s # LIBS =-levent-lm # g" Makefile
Make
Cp magent/usr/bin/magent
Cd ../

 

II. instances used:

Memcached-m 1-u root-d-l 127.0.0.1-p 11211
Memcached-m 1-u root-d-l 127.0.0.1-p 11212
Memcached-m 1-u root-d-l 127.0.0.1-p 11213
Magent-u root-n 51200-l 127.0.0.1-p 12000-s 127.0.0.1: 11211-s 127.0.0.1: 11212-B 127.0.0.1: 11213

1. start three Memcached processes on ports 11211, 11212, and 11213 respectively, and enable magent on ports 12000;

2. ports 11211 and 11212 are primarily Memcached, and ports 11213 are backup Memcached;

3. connect to magent 12000, set key1 and set key2. according to the hash algorithm, key1 is written to Memcached of ports 11212 and 11213, and key2 is written to Memcached of ports 11212 and 11213;

4. when Memcached on ports 11211 and 11212 die, connect to the magent on port 12000 to retrieve data from Memcached on port 11213;

5. when Memcached on ports 11211 and 11212 is restarted and recovered, the magent will retrieve data from Memcached on ports 12000 or 11211, because no data is available after the two Memcached restart, therefore, what magent gets is a null value, even though Memcached on port 11213 has data (this problem has yet to be improved ).

 

III. entire test process:

[Root @ centos52 ~] # Telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Stats
Memcached agent v0.4
Matrix 1-> FIG: 11211, pool size 0
Matrix 2-> FIG: 11212, pool size 0
END
Set key1 0 0 8
Zhangyan
STORED
Set key2 0 0 8
Zhangyan
STORED
Quit
Connection closed by foreign host.


[Root @ centos52 ~] # Telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key1
END
Get key2
VALUE key2 0 8
Zhangyan
END
Quit
Connection closed by foreign host.


[Root @ centos52 ~] # Telnet 127.0.0.1 11212
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key1
VALUE key1 0 8
Zhangyan
END
Get key2
END
Quit
Connection closed by foreign host.


[Root @ centos52 ~] # Telnet 127.0.0.1 11213
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key1
VALUE key1 0 8
Zhangyan
END
Get key2
VALUE key2 0 8
Zhangyan
END
Quit
Connection closed by foreign host.


Simulate Memcached death on ports 11211 and 11212
[Root @ centos52 ~] # Ps-ef | grep memcached
Root 6589 1 0? 00:00:00 memcached-m 1-u root-d-l 127.0.0.1-p 11211
Root 6591 1 0? 00:00:00 memcached-m 1-u root-d-l 127.0.0.1-p 11212
Root 6593 1 0? 00:00:00 memcached-m 1-u root-d-l 127.0.0.1-p 11213
Root 6609 6509 0 000:00:00 pts/0 grep memcached
[Root @ centos52 ~] # Kill-9 6589
[Root @ centos52 ~] # Kill-9 6591
[Root @ centos52 ~] # Telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key1
VALUE key1 0 8
Zhangyan
END
Get key2
VALUE key2 0 8
Zhangyan
END
Quit
Connection closed by foreign host.


Simulate Memcached restart for ports 11211 and 11212
[Root @ centos52 ~] # Memcached-m 1-u root-d-l 127.0.0.1-p 11211
[Root @ centos52 ~] # Memcached-m 1-u root-d-l 127.0.0.1-p 11212
[Root @ centos52 ~] # Telnet 127.0.0.1 12000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Get key1
END
Get key2
END
Quit
Connection closed by foreign host.

Author: "Guo Weijun's work and study records"

Related Article

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.