Magent Build memcached Cluster

Source: Internet
Author: User
Tags memcached

magent Build memcached Cluster



Memcached Cluster Introduction


Because there is no communication between the memcached server and the server, and no data replication backups are made, a single point of failure occurs when any server node fails, and if HA is required, it needs to be addressed in another way.


Through the magent cache proxy, to prevent the single point phenomenon, the cache proxy can also do backup, through the client connection to the cache proxy server, the cache proxy Server connection cache connection server, the cache proxy server can connect more than one memcached machine can be each memcached machine to synchronize data. If one of the cache servers is down, the system can continue to work, and if one of the memcached machines is down, the data is not lost and data integrity can be guaranteed.

Build memcached Cluster


Magent's architecture has been described in detail in the previous blog post, "Magent introduction." Now, as shown in the example schema scenario, magent How to build a memcached cluster, and in a production environment you need to design robust architecture solutions based on your business characteristics.

650) this.width=650; "title=" clip_image002 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "alt=" clip_image002 "src=" Http://s3.51cto.com/wyfs02/M00/6B/B9/wKioL1U1vTLTV6pwAACCECKu2ZM110.jpg "border=" 0 "height=" 175 "/>

Existing test machine: 192.168.11.51/52/68

First in three test machine installed libevent and memcached, start memcached instance;

Then install the Magent on 51 and 52 and start the Magent instance.

Installing and starting memcached Example


For detailed steps, please refer to the previous post "Memcached 1.4.22 installation and Configuration" to launch the following example:

/usr/local/bin/memcached-d-M 256-u memcached-l 192.168.11.51-p 11211-c 1024-p/var/run/memcached/memcached.pid/usr/ Local/bin/memcached-d-M 256-u memcached-l 192.168.11.52-p 11211-c 1024-p/var/run/memcached/memcached.pid/usr/local /bin/memcached-d-M 256-u memcached-l 192.168.11.68-p 11211-c 1024-p/var/run/memcached/memcached.pid

Installing and starting magent Example


When I test the magent-0.6.tar.gz, this version is not stable enough with the latest version of memcached, the following configuration to magent-0.5.tar.gz as an example.


1. Install Magent to/usr/local:

cd/usr/local mkdir magent cd magent wget http://memagent.googlecode.com/files/magent-0.5.tar.gz (You can download it first if you can't access it directly) Upload to the server after installing the package) tar zxvf magent-0.5.tar.gz


2. Modify the configuration:
Add at the beginning of the Ketama.h file

#ifndef Ssize_max #define SSIZE_MAX 32767 #endif


Ln-s/usr/lib64/libm.so/usr/lib64/libm.a/sbin/ldconfigsed-i "s#libs =-levent#libs =-levent-lm#g" Makefile VI make File


Will

CFLAGS =-wall-o2-g

Modified to:

CFLAGS =-lrt-wall-o2-g

Save


3. Compiling:

Make


Output the following information:

Gcc-lrt-wall-o2-g-c-o magent.o magent.c gcc-lrt-wall-o2-g-c-o ketama.o ketama.c gcc-lrt-wall-o2-g-O Magent MAGENT.O KETAMA.O-LEVENT–LM


4. View command help:

./magent–h

   

memcached agent v0.4 build-date: apr 21 2015 09:21:10     Usage:    -h this message    -u uid     -g gid    -p port, default is 11211.  (0 to  disable tcp support)     -s ip:port, set memcached  Server ip and port    -b ip:port, set backup memcached  server ip and port    -l ip, local bind ip  address, default is 0.0.0.0    -n number, set max  Connections, default is 4096    -d don ' t go to  background    -k use ketama key allocation algorithm     -f file, unix&nBsp;socket path to listen on. default is off    -i  number, set max keep alive connections for one memcached  Server, default is 20    -v verbose


5. Launch the Magent instance

/usr/local/magent/magent-u root-n 4096-l 192.168.11.51-p 11200-s 192.168.11.51:11211-s 192.168.11.52:11211-b 192.16 8.11.68:11211/usr/local/magent/magent-u root-n 4096-l 192.168.11.52-p 11200-s 192.168.11.51:11211-s 192.168.11.5 2:11211-b 192.168.11.68:11211

Testing process


Log on to Magent on 51 and store Key1 to Key5:

[[Email protected] ~]# telnet 192.168.11.51 11200Trying 192.168.11.51...Connected to 192.168.11.51.Escape character is ' ^ ] '. statsmemcached agent V0.4matrix 1, 192.168.11.51:11211, pool size 0matrix 2-192.168.11.52:11211, pool size 0 Endset key1 0 0 11STOREDset key2 0 0 222STOREDset key3 0 0 3333STOREDset key4 0 0 44444STOREDset key5 0 0 555555STOREDquit Connection closed by foreign host.


Log on to memcached on 51 and get to Key2 and Key4:

[[Email protected] ~]# telnet 192.168.11.51 11211Trying 192.168.11.51...Connected to 192.168.11.51.Escape character is ' ^ ] '. Get key1endget key2value key2 0 222ENDget key3endget key4value key4 0 44444ENDget key5endquitconnection closed by Forei GN Host.


Log on to memcached on 52 and get to Key1, Key3, and Key5:

[[Email protected] ~]# telnet 192.168.11.52 11211Trying 192.168.11.52...Connected to 192.168.11.52.Escape character is ' ^ ] '. Get key1value key1 0 11ENDget key2endget key3value key3 0 3333ENDget key4endget key5value key5 0 555555ENDquitConnectio N Closed by foreign host.


Log on to memcached on 68 and get to Key1 to Key5:

[[Email protected] ~]# telnet 192.168.11.68 11211Trying 192.168.11.68...Connected to 192.168.11.68.Escape character is ' ^ ] '. Get key1value key1 0 11ENDget key2value key2 0 222ENDget key3value key3 0 3333ENDget key4value key4 0 44444ENDget key5v Alue key5 0 555555ENDquitConnection closed by foreign host.


Stop 52 of the memcached process and get Key1 to Key5 by Magent on 51:

Kill ' Cat/var/run/memcached/memcached.pid '
[[Email protected] magent]# telnet 192.168.11.51 11200Trying 192.168.11.51...Connected to 192.168.11.51.Escape Character is ' ^] '. Get key1value key1 0 11ENDget key2value key2 0 222ENDget key3value key3 0 3333ENDget key4value Key4 0 44 444ENDget key5value key5 0 555555ENDquitConnection closed by foreign host.


Recover 52 of the memcached process, through the magent on 51, only get to Key2 and Key4:

[[Email protected] ~]# telnet 192.168.11.51 11200Trying 192.168.11.51...Connected to 192.168.11.51.Escape character is ' ^ ] '. Get key1endget key2value key2 0 222ENDget key3endget key4value key4 0 44444ENDget key5endquitconnection closed by Forei GN Host.


Through the above tests, we can draw a conclusion:

1. The value stored through the Magent connection pool will be available for all memcached of the magent agent.

2. If there is a memcached outage through the Magent proxy mode can also fetch the value.

3. If the value that is taken by the Magent proxy after the memcached repair restart is null, this is because the value inside the memcache after the reboot disappears as the Memcache service stops (because in memory), However, the magent is assigned to a machine by hashing the key, and the memcache is also taken from the machine after the reboot, and all the values taken are empty.


Workaround:

1. After each memcache outage, you can write a program that copies all of the information from other memcache in the cluster to the memcache of the current downtime fix.

2. Write the agent yourself, and then go to the other memcached when the value from a memcached service is null.


Precautions:

Magent is called in the same way as memcached, the client can switch to magent mode without changing the code.

cache vs. db the synchronization


It is more safe to do this: when querying from the cache, add, Updae, delete while operating the cache and DB.

Of course, you can also synchronize the cache and DB data regularly, different business should have different choices.

magent-0.6 version-related error rollup


The following error is generated:

Gcc-wall-g-o2-i/usr/local/include-m64-c-o magent.o magent.c 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 are report    Ed only once magent.c:729:error:for each function it appears in.) Make: * * * [MAGENT.O] Error 1


Workaround:
Add at the beginning of the Ketama.h file

#ifndef Ssize_max #define SSIZE_MAX 32767 #endif


Make again


The following error is generated:

Gcc-wall-g-o2-i/usr/local/include-m64-c-o magent.o magent.c gcc-wall-g-o2-i/usr/local/include-m64-c-o ket AMA.O ketama.c gcc-wall-g-o2-i/usr/local/include-m64-o magent magent.o ketama.o usr/lib64/libevent.a/usr/lib    64/LIBM.A gcc:/usr/lib64/libevent.a:no such file or directory gcc:/usr/lib64/libm.a:no such file or directory Make: * * * [magent] Error 1


Workaround:

Ln-s/USR/LIB64/LIBM.SO/USR/LIB64/LIBM.A VI Makefile


Find libs =/USR/LIB64/LIBEVENT.A/USR/LIB64/LIBM.A
Modify in the following format:
LIBS =/usr/<libevent Installation path >/LIBEVENT.A/USR/LIB64/LIBM.A
such as: LIBS =/USR/LIB/LIBEVENT.A/USR/LIB64/LIBM.A
Save


Make again


The following error is generated:

Gcc-wall-g-o2-i/usr/local/include-m64-o magent MAGENT.O ketama.o/usr/lib/libevent.a/usr/lib64/libm.a/usr/lib/ LIBEVENT.A (EVENT.O): in function ' gettime ':/tmp/libevent-2.0.22-stable/event.c:370:undefined reference to ' Clock_get Time '/usr/lib/libevent.a (EVENT.O): in function ' detect_monotonic ':/tmp/libevent-2.0.22-stable/event.c:340:undefin Ed reference to ' Clock_gettime ' Collect2:ld returned 1 exit status Make: * * * [magent] Error 1


Workaround:

VI Makefile

Will

CFLAGS =-wall-g-o2-i/usr/local/include $ (M64)

Modified to:

CFLAGS =-lrt-wall-g-o2-i/usr/local/include $ (M64)

Save


Make again


The output is:

Gcc-lrt-wall-g-o2-i/usr/local/include-m64-o magent MAGENT.O KETAMA.O/USR/LIB/LIBEVENT.A/USR/LIB64/LIBM.A



This article is from the SQL Server deep dives blog, so be sure to keep this source http://ultrasql.blog.51cto.com/9591438/1636374

Magent Build memcached Cluster

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.