Deployment of a lightweight memcached proxy twemproxy

Source: Internet
Author: User

light weight of memcached Agent Twemproxy the deployment



Twemproxy (also known as Nutcracker) is a lightweight redis and memcached agent that is primarily used to reduce the number of connections to the back-end cache server. The Cache server cluster management tool, which is open source by Twitter, is primarily used to compensate for the deficiencies identified by Redis and memcached for cluster (cluster) management.

Twemproxy is a fast single-threaded agent that supports the Memcached ASCII protocol and the updated Redis protocol.

The great thing about Twemproxy is that it can unload the node when it fails, and then try to connect again after a while, or you can strictly follow the corresponding relationship between the keys written in the configuration file and the server.

Installation deployment



Existing test machine: 192.168.11.51/52/68

First install the libevent and memcached on the 51 and 52 test machines, and start two memcached instances respectively;

Then install the Twemproxy on 68, configure the parameters, and start the Twemproxy 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 128-u memcached-l 192.168.11.51-p 11211-c 1024-p/var/run/memcached/memcached1.pid/usr /local/bin/memcached-d-M 128-u memcached-l 192.168.11.51-p 11212-c 1024-p/var/run/memcached/memcached2.pid/usr/loc Al/bin/memcached-d-M 128-u memcached-l 192.168.11.52-p 11211-c 1024-p/var/run/memcached/memcached1.pid/usr/local/b In/memcached-d-M 128-u memcached-l 192.168.11.52-p 11212-c 1024-p/var/run/memcached/memcached2.pid

Installing and starting Twemproxy Example



1 , installation autoconf

Cd/tmpwget Http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gztar zxvf AUTOCONF-2.69.TAR.GZCD autoconf-2.69./ Configure--prefix=/usr/make && make install

2 , installation Twemproxy

Cd/tmpwget Https://github.com/twitter/twemproxy/archive/master.zipunzip master.zip-d/USR/LOCAL/CD/USR/LOCALMV Twemproxy-master TWEMPROXYCD twemproxycflags= "-ggdb3-o0" autoreconf-fvi./configure--prefix=/usr/local/twemproxy-- Enable-debug=logmake && make Install

3 , view Help

[[email protected] twemproxy]# ./sbin/nutcracker -h 
This is nutcracker-0.4.0usage: nutcracker [-?hvddt] [-v verbosity level]  [-o output file][-c conf file] [-s stats port] [-a stats  addr][-i stats interval] [-p pid file] [-m mbuf size]options:-h,  --HELP : THIS HELP-V, --VERSION : SHOW VERSION AND EXIT-T,  --test-conf : test configuration for syntax errors and exit-d,  --daemonize : run as a daemon-D, --describe-stats : print  stats description and exit-v, --verbose=n : set logging level  ( DEFAULT: 5, MIN: 0, MAX: 11)-o, --output=s : set logging  file  (Default: stderr)-c, --conf-file=s : set configuration file  ( Default: conf/nutcracker. Yml)-s, --stats-port=n : set stats monitoring port  (default: 22222)-A , --stats-addr=s : set stats monitoring ip  (default: 0.0.0.0)-i,  --stats-interval=n : set stats aggregation interval in msec  (Default:  30000 MSEC)-p, --pid-file=s : set pid file  (Default: off)-M,  --mbuf-size=N : set size of mbuf chunk in bytes  (Default:  16384 bytes)

4 , modify the configuration file

MKDIR/ETC/NUTCRACKERCP./conf/nutcracker.yml/etc/nutcracker/vi/etc/nutcracker/nutcracker.yml
Memcached:listen:192.168.11.55:22121hash:fnvla_64distribution:ketamatimeout:400backlog:1024preconnect:trueauto _eject_hosts:trueserver_retry_timeout:30000server_failure_limit:3servers:-192.168.11.51:11211:1- 192.168.11.51:11212:1-192.168.11.52:11211:1-192.168.11.52:11212:1

Parameter resolution:

Listen: Start the IP and port of the Twemproxy service

Hash: Specify a specific hash function

Distribution: Specifying a specific hash algorithm

Preconnect: A Boolean value if the control's Nutcracker front-end connection is started on all server processes on this pool. Default value is False

Auto_eject_hosts: Do you want to remove the node temporarily when the node is not responding?

Server_retry_timeout: Time to retry (MS)

Server_failure_limit: How many times the node fault is removed

Servers: The following represents all memcached nodes (IP: Port number: Weight)

5 , configure to start with a service

CP./scripts/nutcracker.init/etc/init.d/nutcrackerchmod 755/etc/init.d/nutcrackervi/etc/init.d/nutcracker

1. New Definition Daemo

daemon= "/usr/local/twemproxy/sbin/nutcracker"

2. Replace All

Daemon--user ${user} ${prog} $OPTIONS

For

${daemo} $OPTIONS
Chkconfig--add nutcrackerchkconfig--level Nutcracker Onchkconfig--list Nutcracker
Vi/etc/profile

Add in:

Export path= "$PATH:/usr/local/twemproxy/sbin"
. /etc/profileecho $PATH

6 , test the configuration, and start the service

Nutcracker-t-c/etc/nutcracker/nutcracker.ymlservice Nutcracker Start

Data Write Test

[[Email protected] init.d]# telnet 192.168.11.55 11211
Trying 192.168.11.55...Connected to 192.168.11.55.Escape character is ' ^] '. Set key1 0 0 11STOREDset key2 0 0 222STOREDset Key3 0 0 3333STOREDset key4 0 0 44444STOREDset key5 0 0 555555STOREDquitConnection closed by foreign host.
[[Email protected] ~]# telnet 192.168.11.51 11211
Trying 192.168.11.51...Connected to 192.168.11.51.Escape character are ' ^] '. Get Key1endget key2endget Key3endget Key4endget Key5endquitconnection closed by foreign host.
[[Email protected] ~]# telnet 192.168.11.51 11212
Trying 192.168.11.51...Connected to 192.168.11.51.Escape character are ' ^] '. Get Key1endget key2endget Key3endget Key4endget Key5endquitconnection closed by foreign host.
[[Email protected] ~]# telnet 192.168.11.52 11211
Trying 192.168.11.52...Connected to 192.168.11.52.Escape character are ' ^] '. Get Key1endget key2endget Key3endget Key4endget Key5endquitconnection closed by foreign host.
[[Email protected] ~]# telnet 192.168.11.52 11212
Trying 192.168.11.52...Connected to 192.168.11.52.Escape character is ' ^] '. Get key1value key1 0 11ENDget key2value key2 0 222ENDget key3value Key3 0 3333ENDget key4value key4 0 44444ENDget key5value key5 0 555555ENDquitConnection closed by fore IGN host.


You can see that the data is all fetched from 52 of 11212 ports.

Now stop 52 of the 11212-port service.

Continue to write data to the agent.

[[Email protected] init.d]# telnet 192.168.11.55 11211
Trying 192.168.11.55...Connected to 192.168.11.55.Escape character is ' ^] '. Set username 0 0 6ryanxuSTOREDset aa 0 0 2aaSTO Redquitconnection closed by foreign host.
[[Email protected] init.d]# telnet 192.168.11.55 11211
Trying 192.168.11.55...Connected to 192.168.11.55.Escape character is ' ^] '. Get Key1server_error Connection Refusedconnection closed by foreign host.
[[Email protected] init.d]# telnet 192.168.11.55 11211
Trying 192.168.11.55...Connected to 192.168.11.55.Escape character is ' ^] '. Get Key1server_error Connection Refusedconnection closed by foreign host.
[[Email protected] init.d]# telnet 192.168.11.55 11211
Trying 192.168.11.55...Connected to 192.168.11.55.Escape character is ' ^] '. Get Key1endget Key2endget Key3endquitconnection closed by foreign host.

After a memcached is hung off, twemproxy can be removed automatically. After recovery, Twemproxy can be automatically identified, recovered, and re-added to the memcached group for reuse.


Summary of issues


1). A space is required after each parameter value pair delimiter ":" In the Yml configuration file.

2) Different levels of parameters need to be indented to distinguish, it is best to use the TAB key indentation, otherwise the Nutcracker process cannot start.

3) in Auto_eject_hosts:true, when you close a memcached instance, write the data or prompt "(error) ERR Connection refused". This is related to the Server_retry_timeout parameter setting is too small, 30000 is a good choice.



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

Deployment of a lightweight memcached proxy twemproxy

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.