Reproduced Redis Cluster Building Best Practices

Source: Internet
Author: User
Tags redis cluster

Reprinted from Http://blog.csdn.net/sweetvvck/article/details/38315149?utm_source=tuicool

To build a Redis cluster, consider the following questions first: What is the purpose of  redis cluster construction? Or why build a Redis cluster? The purpose of  redis cluster building is actually the purpose of cluster building, all clusters are mainly to solve a problem, scale-out. Before the concept of clustering, we used the hardware resources are vertical expansion, but the vertical expansion will soon reach a limit, the CPU of a single machine processing speed, memory size, hard disk size has not been able to meet the demand, and the machine vertical expansion of the cost is quite high. The emergence of a cluster is the ability to allow multiple machines to work like a machine, enabling horizontal scaling of resources.  redis is a memory-based database, when we want to store data to a certain extent, the memory of a single machine can not meet our needs, building a cluster is a good solution.   So how can redis on multiple machines work like a redis on a single machine?   need to solve the following three issues; 1. Exposing an Access Node 2. Request Shard (Sharding) 3. Shards to be reasonable (shard evenly, same request to be assigned to the same Redis node)   First, expose an access node to the outside, There may be more than one redis to work on, and it's easy to think of proxies, which only need to know the proxy for the client and interact with multiple Redis in the background through the proxy.   The second problem can be solved by using the hash algorithm, the request of a key hash value, the number of Redis to take the remainder, to allocate different redis; however, this does not satisfy the same request in 3rd to be assigned to the same redis. In this case, the consistent hash solves the problem perfectly, and the consistent hash can distribute the REDIS nodes over a 232  node through the hash algorithm, and the requested key is mapped to the ring with the same hash algorithm. Then the key value of the node in the clockwise search for the nearest Redis node, so that consistency is ensured, detailed introduction can refer to:http://blog.csdn.net/sparkliang/article/details/5279393 .   If I were to implement a Redis cluster, I would implement it using zookeeper plus a Redis daemon plus a consistent hash algorithm. But Twicer's great gods have realized and open up a redis cluster scheme, and I won't be making the wheel again; let's see what  twemproxy (Nutcracker) features are implemented by the great Gods of one of the world's largest redis cluster users. &nbSp Twemproxy, in addition to being a Redis agent, also supports the Memerycached ASCII protocol. I am here to understand Twemproxy's solution on a redis cluster. Twemproxy In addition to the perfect solution to the above three problems (also using a consistent hash algorithm), there is an important feature of it, it supports node ejection, if using Redis when the cache, not very focused on data consistency, open node Ejection can be removed from the cluster list when one of the Redis in the cluster is hung up for high availability. If your Redis cluster is a data store, or if you are concerned about data consistency, you can disable node jection, but you need to use other methods for high availability, such as Redis Sentiel. Twemproxy's detailed introduction can look at this article: Http://antirez.com/news/44 ;Twemproxy Project GitHub address: Https://github.com/twitter/twemproxy.   Nonsense said so much, to see how to install Twemproxy, build Redis cluster bar  first, follow the steps on GitHub to install Twemproxy:

To build Nutcracker from source with debug logs enabled and assertions disabled:

$ git clone [email protected]:twitter/twemproxy.git$ cd twemproxy$ autoreconf -fvi$ ./configure --enable-debug=log$ make依次输入上面的命令,然后输入:$ src/nutcracker -hIf the Help information is displayed, the installation is successful, then edit the configuration information, find a directory you like, create a configuration file, suffix yml, such as TWEMPROXY.TEST.YML, fill in the following information:
Alpha:  listen:127.0.0.1:55555  hash:fnv1a_64  distribution:ketama  auto_eject_hosts:true  Redis:true  server_retry_timeout:30000  server_failure_limit:1  servers:    -192.168.1.10:6379:1    -192.168.1.7:6379:1
Note the indentation, otherwise you will not be able to start twenproxy. Where listen: Represents the IP of the proxy and the port number, is exposed to the client use; hash: Indicates which hash method to use, Twemproxy provides a variety of ways, specifically to see GitHub introduction; distribution represents the distribution mode, There are three options: Ketama, Modula,random;auto_reject_hosts: The above mentioned, the automatic removal of the failed node; Redis: It means using a redis cluster, the rest of the configuration is simply not introduced ... With such a simple configuration, execute the./src/nutcracker-c./CONF/NUTCRACKER.TEST.YML (where you use your own installation path and profile path) to start the Twemproxy, The client only needs to be able to connect to the proxy via REDIS-CLI, using the same method as Redis (but not all commands support). So the Redis cluster is ready, is it simple enough to explode? But do not be happy too early, Twemproxy also has its shortcomings. 1. Do not support transactions and bulk operations; 2. Loss of performance compared to direct access to Redis;
Although Twemproxy has the above shortcomings, the advantages of single-phase than the benefits simply insignificant! But it also indicates that it is not applicable to all situations. Redis Cluster There are many ways to build, its official cluster has been in beta state, I believe that after understanding the Twemproxy, we will find that it is now the best choice!

Reproduced Redis Cluster Building Best Practices

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.