In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people are at a loss about how to use containers to achieve one-click delivery of production-level redis sharding clusters. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
How to use containers to achieve one-click delivery of production-level Redis sharding clusters
Redis has supported sharding clusters since 3. 0. Redis clusters allow data to be automatically distributed across multiple nodes. How to use Docker to implement one-click deployment delivery of Redis clusters is an interesting and valuable topic.
The editor will introduce the process-based container technology to achieve one-click deployment of Redis sharding clusters, which fully demonstrates the powerful power of containers.
What is a Redis sharding cluster
Redis (redis.io), as the most popular KV database, runs on a stand-alone machine for a long time. There are many third-party schemes about how to realize the distribution of Redis data on multiple nodes before Redis3.0 comes out. I suggest you refer to this link:
Http://redis.io/topics/partitioning
Client hash
This is the simplest implementation, which distributes data to different nodes by using a consistent hash algorithm on the client side. The disadvantage of this method is very obvious, it lacks the ability of fault automatic failover, and it is difficult to relocate the data distribution during capacity expansion.
Agent mode
One is Twemproxy, officially recommended by Redis, which is developed by twitter.
The other is the domestic pea pod open source codis.
The biggest advantage of the agent mode is that it is still developed using sdk on a single redis machine and is easy to maintain.
Redis Cluster
After the introduction of sentinel master-slave automatic failover function, redis3.0 launched the sharding cluster, which is called Redis Cluster. The main purpose of this sharing is to introduce how to achieve one-click deployment of Redis clusters.
Reference documentation:
Http://redis.io/topics/cluster-tutorial
First prepare the redis image
Redis officially provides Redis 3.2and 3.3images, both of which can be used as images for Redis clusters. 3.2is a stable version.
Currently, the alpine version of Redis image has been officially launched. The advantage of alpine image is its small size. This sharing uses the official redis:3.2-alpine image as the cluster.
Prepare to initialize the execution environment of the script
Redis officially provides a script redis-trib.rb for ruby, 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 needs a ruby environment to run. Let's build a redis-trib image. Here is the Dockerfile content of 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 & & chmod 755 / 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" = create]; then if [- f / usr/local/etc/redis-trib.conf]; then. / usr/local/etc/redis-trib.conf QUIET_MODE=1 redis-trib.rb create-- replicas $REPLICAS $NODES fifi
The above two files are used to build the redis-trib image. The logic in Dockerfile is relatively simple. Add the redis-trib.rb file in github to the image and have the script execution support non-interactive mode (QUIET_MODE).
When the mirror starts, the cluster initialization command is executed.
Prepare the redis cluster configuration file port 6379cluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000appendonly yes
We usually put the configuration files of the redis cluster under the data directory / data, and the redis process has read and write permissions to the / data directory.
Prepare redis-trib script configuration file for obtaining cluster initialization parameters
In the entrypoint.sh file, the most important thing is to read the redis-trib.conf configuration file, the format of the configuration file is very simple
REPLICAS= {{. REPLICAS_NUM}} {{$rs: = service "redis"} NODES= "{{range $I rc.IPAddr: = $rs.Containers}} {{$rc.IPAddr}}: 6379 {{end}}"
REPLICAS means that there are several slave for each shard, and one slave is generally configured, that is, REPLICAS=1NODES means each node of the cluster, including master and slave.
So if there are 10 nodes, REPLICAS=1, then there will be 5 slices.
Arrange a cluster
After preparing the above images and configuration files, we began to orchestrate the cluster
Step 1: create a template
Step 2: select an image and add a redis service
Step 3: set container parameters
! [! [container parameter-1]
Step 4: set up the health check policy
Step 5: set the redis container deployment strategy
Add redis Cluster initialization Service redis-trib step 1: select an image
Step 2: set container parameters
Step 3: set the redis-trib container deployment policy
Redis-trib does not start until the redis container is started, so the startup priority is lower than redis.
Through the above steps, the Redis-sharding application template is arranged.
Deploy Redis Cluster with one click based on Redis-sharding application template
The following is the effect of the deployment:
Looking at the initialization result of the redis-trib cluster, we can see that there is no problem with the initialization process of the cluster.
Verify: log in to any redis node and execute redis-cli info:
The above shares the process-based container technology and realizes the one-click delivery of Redis sharding.
Can you deploy it?
So easy
After sharing, the discussion is even more intense:
Q1: is it okay if I want to deploy multiple redis instances on one machine?
A1: yes
Q2: do you develop ui orchestration tools independently or based on some open source tools? What is the internal logic?
A2: independently developed.
Set and save the running parameters of the docker container through an easy-to-use interface.
The running parameters, priority and deployment strategy of each container constitute a number of services, and multiple services are combined into an application template that can be deployed with one click.
I think the docker of the Q3:redis cluster is all of the same IP address range. Is this handled by a separate docker management tool? If you only build a redis cluster without docker cluster management. How to manage this multiple redis node?
The A3:csphere platform supports network management functions and has automatic and programmable service discovery capabilities behind it, which makes it possible to deploy clusters automatically.
If you deploy manually without docker, you can follow the official documents step by step
Q4: when was the template data introduced here?
A4: there are two types of template data:
Template variables defined in the configuration file template. This kind of data is filled in by the user through the cSphere management platform when creating the application instance.
The metadata related to the cluster service, such as the IP address of each container, the parameters of the host where the container resides, etc. This kind of data is the configuration file template that the cSphere application orchestration engine automatically collects from each node of the cluster and registers to the configuration template parsing engine when creating an application instance, and then parses to generate the final configuration file, and then loads it into each container.
Q5: how does resharding handle the capacity expansion and reduction of redis-cluster?
A5: if you expand and increase the capacity of nodes, trigger the trib script to re-resharding, and if you reduce the number of nodes, you need to execute it first. The trib script contains commands to add and delete nodes.
Q6: is this your business platform? Or is it the result of openstack integrating docker?
A6: our business platform provides enterprises with an overall PaaS solution. The underlying layer of Xiyun cSphere platform is docker, and Xiyun cSphere platform can be deployed on OpenStack platform.
Q7: is the Q5 cluster scheme currently proposed by redis3.0 stable? Has it gone through a lot of data testing! How efficient is it? Because I am not professional in operation and maintenance, I am a developer interested in the knowledge of operation and maintenance, but not professional. I hope to get an answer supported by data.
A7: redis's current cluster stability is relatively good. A large number of Internet enterprises at home and abroad are using it on a large scale. As far as I know, VIPSHOP's redis cluster size is more than 500sets.
Q8: can your pass platform also allow 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 and disk IO-intensive. Through the choice of scheduling strategy, users can more deeply control the distribution of containers on the host cluster, so that the application can achieve better results.
Q9: redis uses docker for clustering. Is there anything you need to pay extra attention to in terms of memory?
A9: in terms of memory, pay attention to setting the parameters related to the kernel vm. In addition, the maximum memory size can be set in the configuration file. If you want to automate, you can automatically obtain the container memory quota or automatically calculate the memory size of the host node.
After reading the above, have you mastered how to use containers to achieve one-click delivery of production-level redis sharding clusters? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.