How to use containers to achieve one-click delivery of production-grade Redis sharding clusters

Source: Internet
Author: User
Tags failover redis cluster install redis

Author Introduction:
Zhang Chunyuan

Haven Court Csphere partner, an early Docker evangelist in the country, has a wealth of hands-on experience in applying Docker to the enterprise, and is adept at using Docker to practice a devops culture. The first series of Docker video course instructor, video volume cumulative 100,000 +

Opening:

Redis started to support sharding clusters after 3.0. Redis clusters allow data to be distributed automatically across multiple nodes. How to use Docker to implement one-click deployment of Redis clusters is an interesting and valuable topic.

This article will introduce the process-based container technology to realize the one-click deployment of Redis sharding cluster, which fully demonstrates the powerful power of the container.

What is a redis sharding cluster

Redis (Redis.io) as the most popular KV database, for a long time is a stand-alone operation, about how to realize the Redis data on multiple nodes distribution, before Redis3.0 out, there are many third-party scenarios. We recommend that you refer to this link:

Http://redis.io/topics/partitioning

Client Hash

This is the simplest implementation, by using a consistent hash algorithm on the client, to distribute the data to different nodes. The shortcomings of this method are very obvious, the lack of automatic failover capability, and the relocation of data distribution during the expansion is also more laborious.

Proxy mode
    • One is the official Redis recommendation Twemproxy, which was developed by the Twitter company;

    • Another is the domestic pea pod Open source Codis;

The biggest benefit of the proxy mode is that it is still being developed using the Redis Standalone SDK and is easy to maintain.

Redis Cluster

redis3.0 after 2.8 launched Sentinel master-Slave automatic failover function, launched the sharding cluster, this is the Redis Cluster. This share is mainly about how to implement a one-key deployment of a Redis cluster.

Reference Documentation:

Http://redis.io/topics/cluster-tutorial

Prepare the Redis image first

The Redis official has provided the Redis 3.2 and 3.3 mirroring, which can be used as a mirror for the Redis cluster, and 3.2 is a stable version.

Currently the official launch of the Alpine version of the Redis image, the advantage of Alpine mirror is small size. This sharing is done using the official Redis:3.2-alpine image to do the cluster.

Prepare the execution environment for initializing scripts

Redis officially provides a ruby script redis-trib.rb, which can be used to initialize clusters, resharding clusters, rebalance clusters, and so on.

We use the official script to initialize the cluster. The script runs in a ruby environment, we build a redis-trib image, and the following is the Dockerfile content to build the Redis-trib image:

cat Dockerfile

From Ruby:2.3. 1-alpineADD https://raw.githubusercontent.com/antirez/redis/3.2.0/src/redis-trib.rb/usr/local/bin/redis-trib.rbRUN Gem Install Redis&&chmod755/usr/Local/bin/redis-trib.Rb&& \Sed- I. '/yes_or_die.msg/a return if env["quiet_mode"] = = "1" '/usr/Local/bin/redis-trib.Rbadd entrypoint.Sh/entrypoint.Shentrypoint["/entrypoint.Sh"]

Script file

cat entrypoint.sh

#!/bin/shif"$CLUSTER_CMD"then  if-fthen    . /usr/local/etc/redis-trib.conf    QUIET_MODE=1$REPLICAS$NODES  fifi

The above two files are used to build the redis-trib image, the logic in the dockerfile is relatively simple, the redis-trib.rb file in GitHub is added to the image, and the script executes to support non-interactive mode (Quiet_mode).

When mirroring starts, the cluster initialization command is executed.

Preparing the Redis cluster configuration file
6379cluster-enabled yescluster-config-file nodes.confcluster-node-timeout5000appendonly yes

configuration files for Redis clusters we typically put the data directory/data, and the Redis process has read-write permissions to the/data directory.

Prepare the Redis-trib script configuration file for cluster initialization parameter acquisition

entrypoint.sh file, the main thing is to read the redis-trib.conf configuration file, the format of the configuration file is very simple

replicas=   {{ _num }}    {{$rs : = service   "Redis" }}  nodes= " {{range  $i , $rc : = $rs. Containers }}    {{$ Rc. IPAddr }}  :6379  {{ end }}   "  

replicas means that each shard has several slave, typically configured with 1 slave, that is, replicas=1**nodes** means each node of the cluster, including master and slave.

So if there are 10 nodes, Replicas=1, then there will be 5 shards (slices).

Orchestration Cluster

Once the images and configuration files are ready, we begin to orchestrate the cluster

First step: Create a template

Step Two: Select the image and add the Redis service

Step three: Set container parameters

Fourth step: Set up a health check policy

Fifth step: Set up a Redis container deployment strategy

Add redis cluster initialization service Redis-trib first step: Select Mirror

Step two: Set container parameters

Step three: Set up the Redis-trib container deployment strategy

Redis-trib to start after the Redis container starts, the boot priority is lower than redis.

Through the above steps, the redis-sharding application template is arranged.

One-click deployment of Redis Cluster based on the redis-sharding application template

The following are post-deployment:

Review the results of Redis-trib cluster initialization, and see that the initialization process of the cluster is not a problem;

Verify: Log on to any Redis node to perform REDIS-CLI info:

The above content shares the process-based container technology, enabling a one-click delivery of Redis sharding.

Are you going to deploy it?

So easy

After sharing the discussion is more intense:

Q1: If I want to deploy multiple Redis instances on one machine?

A1: Yes

Q2: Ask if your UI orchestration tools are self-developed or based on what open source tools? What is the internal logic?

A2: self-developed.

The Docker container run parameters are set and saved through an easy-to-use interface.

Each container runs parameters and priorities, and the deployment strategy forms one service, and multiple service groups synthesize an application template that can be deployed in one click.

Q3:redis clustered Docker I think the IP is all in the same network segment. This is handled by a separate Docker management tool? If you are simply building a redis cluster, there is no Docker cluster management. How does this multiple Redis node manage?

The A3:csphere platform internally supports network management capabilities and has automated, programmable service discovery capabilities behind it, making it possible to automate the deployment of a cluster.

If you are deploying from Docker manually, follow the official documentation step-by-step

Q4: When will the template data be passed in here?

A4: There are two types of template data:

  1. Template variables defined in the profile template, which are filled in by the user through the Csphere management platform when the application instance is created;

  2. Cluster service-related metadata, such as the IP address of each container, the host parameter of the container, etc., this data is the Csphere application orchestration engine when creating an application instance, the profile template that is automatically collected from each node of the cluster and registered to the configuration template resolution engine is parsed to generate the final configuration file. and load it into every container.

Q5: Excuse me, Redis-cluster's expansion, shrinkage, resharding how to deal with it?

A5: The expansion of the node, the trigger Trib script resharding, reduce the node, you need to do before the first, Trib script to add a delete node command

Q6: Is this your business platform? Or is it the result of OpenStack integrated Docker?

A6: Our business platform provides the overall PAAs solution for the enterprise. The Haven court Csphere platform is Docker, and the Haven Court Csphere platform can be deployed on the OpenStack platform.

q7:redis3.0 is the current Q5 cluster scheme stable? Have not undergone a lot of data testing! How efficient? Because I am not a professional to do operations, I am doing the development of the knowledge of operations is more interested but not professional, hoping to get a data-backed answer

A7:redis the current cluster stability is relatively good, there are a large number of Internet enterprises at home and abroad to use large-scale, as far as I know, only the product will be the Redis cluster size of more than 500 units

Q8: Your pass platform can also refer to enabling users to customize deployment strategies when deploying containers? What is the purpose of this?

A8: Different types of applications have different resource preferences, such as CPU-intensive, disk IO-intensive, through the selection of scheduling policies, users can more deeply control the distribution of containers in the host cluster, so that the application to achieve better performance.

Q9:redis Do you use Docker as a cluster, where is there anything extra attention in memory?

A9: Memory considerations to set the kernel VM-related parameters, in addition to the configuration file can be added to the maximum size of memory settings, etc., if you want to automate, you can automatically get the memory quota of the container or the memory size of the host node automatically calculated

How to use containers to achieve one-click delivery of production-grade Redis sharding clusters

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.