Memcache+magent High-availability

Source: Internet
Author: User
Tags memcached

Memcache+magent High-availability


First, 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 (outside the wall download)
Tar zxvf magent-0.5.tar.gz
/sbin/ldconfig
Sed-i "s#libs =-levent#libs =-levent-lm#g" Makefile
Make
CP Magent/usr/bin/magent
Cd.. /

Error handling:
Make times wrong

magent.c:in function ' writev_list ':
Magent.c:729:error: ' Ssize_max ' undeclared (first use of this function)
Magent.c:729:error: (Each undeclared identifier was reported only once
Magent.c:729:error:for each function it appears in.)
Make: * * * [MAGENT.O] Error 1 Resolved:

Vim Ketama.h
Join at the beginning
#ifndef Ssize_max
#define SSIZE_MAX 32767
#endif再次make报错:

GCC:/usr/lib64/libevent.a:no such file or directory
GCC:/usr/lib64/libm.a:no such file or directory resolves:

VI Makefile
Find LIBS =/usr/lib64/libevent.a/usr/lib64/libm.a this line
Modify the installation path of the libevent to/USR/LOCAL/LIB/LIBEVENT.A
Will
CFLAGS =-wall-g-o2-i/usr/local/include $ (M64)
Switch
CFLAGS =-lrt-wall-g-o2-i/usr/local/include $ (M64)

Special note, if there is no lib64, you can mkdir one yourself, and then the required class library soft link to lib64

ln-s/usr/lib/x86_64-linux-gnu/libm.a/usr/lib64


Second, the use of examples:

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, respectively in 11211, 11212, 11213 ports to start 3 memcached process, on the 12000 port to open the Magent agent program;
2, 11211, 11212 port is the main memcached,11213 port for backup memcached;
3, connected on the 12000 Magent,set Key1 and set Key2, according to the hashing algorithm, Key1 is written to 11212 and 11213 Port Memcached,key2 is written to 11212 and 11213 Port memcached;
4, when the 11211, 11212 port memcached dead, connected to the 12000 port magent data, the data will be removed from the 11213 port memcached;
5, when the 11211, 11212 port memcached Restart Resurrection, connected to 12000 port, Magent will be from 11211 or 11212 port memcached data, because these two memcached reboot after no data, So magent will get a null value, even though there is still data on port 11213 memcached (This problem remains to be improved).


--------------------------------------------------------------------------------

Three, the entire test process:

[[Email protected] ~]# 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-127.0.0.1:11211, pool size 0
Matrix 2-127.0.0.1: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.


[[Email protected] ~]# 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.


[[Email protected] ~]# 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.


[[Email protected] ~]# 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.


Analog 11211, 11212 port memcached dead.
[Email protected] ~]# Ps-ef | grep memcached
Root 6589 1 0 01:25? 00:00:00 memcached-m 1-u root-d-L 127.0.0.1-p 11211
Root 6591 1 0 01:25? 00:00:00 memcached-m 1-u root-d-L 127.0.0.1-p 11212
Root 6593 1 0 01:25? 00:00:00 memcached-m 1-u root-d-L 127.0.0.1-p 11213
Root 6609 6509 0 01:44 pts/0 00:00:00 grep memcached
[Email protected] ~]# kill-9 6589
[Email protected] ~]# kill-9 6591
[[Email protected] ~]# 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.


Analog 11211, 11212 port memcached Restart Resurrection
[Email protected] ~]# memcached-m 1-u root-d-L 127.0.0.1-p 11211
[Email protected] ~]# memcached-m 1-u root-d-L 127.0.0.1-p 11212
[[Email protected] ~]# 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.

View memcached's data with stats items

Memcache+magent High-availability

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.