Complete steps for laravel project to deploy a redis cluster using twemproxy

Source: Internet
Author: User
Tags redis cluster automake

 
Twemproxy is a proxy server that can be used to reduce the number of connections opened by the memcached or redis server.
The following article describes how to deploy a redis cluster using twemproxy in the laravel project. The sample code in this article is very detailed, for more information, see the preface. twemproxy is a redis proxy developed by Twitter. twemproxy can use multiple redis servers as one, when using twemproxy to access these redis servers, developers do not need to worry about which redis server to read K-V data or updating K-V data to a data set also solves the problem of redis sharing among multiple servers. If you use the redis master-Slave replication ensures that an entire data set still exists when any redis instance cannot work. What is the purpose of twemproxy? It can: by proxy, the number of connections of the cache server is reduced. Data is automatically shared among multiple cache servers. Different policies and hash functions support consistency. Through configuration, the failed nodes are disabled and run in multiple instance, the client can connect to the first available proxy server to support stream and batch processing of requests. This can reduce the consumption of the back and forth. The following describes how to install and configure twemproxy:1Install M4, Autoconf, automake, libtool, and GCC before installing twemproxy. Otherwise, an error is reported.
Wget http://Mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz& Tar-xzvf m4-1.4.13.tar.GZ& CD m4-1.4.13 &./configure-Prefix =/usr/Localmake& Make install
 
Install Autoconf, automake, libtool, and GCC
 
Yum-y install Autoconf automake libtool gcc
 
2Install twemproxy
GitCloneHttps://Github.com/twitter/twemproxy.gitAutoreconf-FVI#Generate the configure file.Configuremake& Make install
 
3, Edit the configuration file
 
Vim Conf/Nutcracker.Yml
ALPHA: Listen : 127.0.0.1: 22121 #  Listening port  Hash : Fnv1a_64#  Key-value hash algorithm. The default value is fnv1a_64.  Distribution : Ketama #  Distribution Algorithm  #  Ketama consistent hash algorithm; modula is very simple, that is, modulo Based on the hash value of the key value; random distribution of random  Auto_eject_hosts : True    #  Remove faulty backend nodes  Redis : True     #  Whether it is redis cache. The default value is false. Timeout 400 #  Proxy and backend timeout, in milliseconds  Server_retry_timeout 200000 #  Time (in milliseconds) for reconnecting after the faulty node is removed  Server_failure_limit : 1 #  Number of failures removed  Servers :-172.16.175.145: 6379: 1-172.16.175.122: 6379: 1
 
4. Modify the redis configuration file
The IP address and port listened by redis must correspond to twemproxy (because I only installed twemproxy on one of the machines, if both are installed, you don't have to change it ).Change the BIND option in. conf to 172.16.175.145 and 172.16.175.122 in this example.  5  Enable twemproxy  Nutcracker-T-C/twemproxy/CONF/nutcracker.Yml#  If-C is not added to the test configuration file, CONF/nutcracker. yml is detected by default.  Nutcracker-D-C/twemproxy/CONF/nutcracker. yml-p-o/data/logs/twemproxy/redisproxy.Log # Start and record logs to/data/logs/twemproxy/redisproxy. Log  6Change the redis connection in the project to the IP address and port of twemproxy. My project uses laravel.Set redis_host and redis_port in env to 127.0.0.1 and 22121 note that you also need to set the database under the config folderIn redis configuration in. php, 'database' =>0. predis performs the Select Operation on this configuration by default, which may cause a connection error. 
 
Perform a redis read/write test. If no exception occurs, twemproxy can be used normally!

Complete steps for laravel project to deploy a redis cluster using twemproxy

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.