Build redis cluster through docker

This article will be published on my blog as soon as possible . Please indicate if you need to reprint it.

Today, let's set up a redis cluster through the docker build, record and review the reflection.

Brief introduction to redis cluster

Redis cluster, or Redis Cluster, is a distributed storage solution introduced by Redis 3.0.
The redis cluster consists of multiple nodes, and redis data is distributed among these nodes. The nodes in the cluster are divided into master nodes and slave nodes. The cluster supports master-slave replication. The master node will automatically synchronize data to the slave node, which can separate read and write, and there is no need to worry about service crashes after the master node goes down. Will be promoted from the slave node to the master node.
The slave node can also accept the connection and synchronization of other slave nodes, which can effectively offload the synchronization pressure of the master node.
The client is directly connected to the redis node and does not require an intermediate proxy layer. The client does not need to connect to all nodes in the cluster, just connect to any available node in the cluster.

Redis cluster construction

We use docker to build a redis cluster, so we need to download docker and install a redis main service node before proceeding. You can refer to the previous article to install docker and install redis . Here, we will start with installing redis in the previous article. You can check the current redis operation through docker ps . You can view the ip address of the current redis service
Insert picture description here
by calling the ContainerID of docker inspect redis . We will use the redis service currently started as the master node and record his ip address. After mine is 172.18.0.2
Insert picture description here
, two slave nodes need to be created. We use redis to build a cluster with one master and two slaves. And check their ip addresses separately.
Insert picture description hereInsert picture description here
Then create a second slave node and check its ip address as well. For 172.18.0.5,
Insert picture description here
Insert picture description here
let's docker ps to check the redis service that is already running. Make sure that all three redis have been started.
Insert picture description here
We enter the first redis server, which is to set the redis as the master node, and enter it through docker exec -it master node name /bin/bash . Call info replication to view the information of the current node, you can see that the role column is master. Of course, there is no master-slave role yet, and the role of each redis is master. Everyone can take a look.
Insert picture description here
After that, you can set the master-slave. We take out the ip of the master node recorded before, which is 172.18.0.2, Into the redis service of the slave node.
Insert picture description here
Then set the slave of 172.18.0.2 6379 to it , and set it to the slave node of the 172.18.0.2 ip address and port 6379. This 172.18.0.2 is the internal ip address of redis, not the server. If the port setting mapping is not mapping 6379:6379 when creating the redis container, here is the same setting 6379, and the port mapped to the external has nothing to do with this.
Insert picture description here
After setting the two slave servers together, we enter the master server to check the effect. You can see that the main server has two more slaves .
Insert picture description here
At this point, the master-slave replication has been successful. If you have data in the master server before setting, now the slave server also has the same data as the master server, you can go to Kangkang.

Guess you like

Origin blog.csdn.net/qq_41762594/article/details/107826476