Home > Database > Redis > body text

Introducing the three cluster modes of Redis (Cluster cluster mode)

藏色散人
Release: 2020-09-10 09:35:00
forward
3244 people have browsed it

The following column Redis Tutorial will introduce to you the three cluster modes of Redis - Cluster cluster mode. I hope it will be helpful to friends in need!

Introducing the three cluster modes of Redis (Cluster cluster mode)

Redis three cluster modes-Cluster cluster mode

1. Have you seen redis cluster deployment before? There are three solutions, but the one with the highest performance is redis-cluster, which is officially recommended by redis. It has the highest performance. The redis-cluster mode is introduced below.

1. redis-cluster

A. Using the idea of ​​decentralization, there is no central node. It uses the hash slot method to combine 16348 hashes. The slot covers all nodes. For each key value stored, use CRC16 (KEY) &16348=slot to get its corresponding hash slot,

and find its hash slot when accessing the key. On which node, the current access node will then fetch data from the node actually assigned this hash slot. The nodes use lightweight protocol communication to reduce bandwidth usage and have high performance.

Automatically implement load balancing and High availability, automatic failover and support for dynamic expansion.

B. The master-slave configuration also needs to be configured internally, and the sentinel mode is also used internally. If half of the nodes find an abnormal node, they jointly decide to change the status of the abnormal node. If the changed node is the master node, then The corresponding slave node automatically replaces the master node. When the original master node comes online, it will become a slave node.

If the master in the cluster does not have a slave node, the entire cluster will enter the fail state after the master hangs up because the slot mapping of the cluster is incomplete. If more than half of the masters in the cluster die, the cluster will enter the fail state regardless of whether there are slaves or not.

C. According to official recommendations, cluster deployment requires at least 3 master nodes. Then start the deployment

2. In each path, we add the configuration files

are: redis.conf

two , Cluster configuration 

  cd /usr/software/redis/redis-cluster/ 

 1. Create directory

   /usr/software/redis/redis-cluster/1001

   /usr/software/redis/redis-cluster/1002

     /usr/software/redis/redis- cluster/1003

  /usr/software/redis/redis-cluster/1004

  /usr/software/redis/redis-cluster/1005

  /usr/software/ redis/redis-cluster/1006

2. Modify redis.conf

cd /usr/software/redis/redis-cluster/1001

vim redis.conf

  #Modify the following key-value pairs 

################################## NETWORK #####################################
#bind 127.0.0.1protected-mode no
port 1001################################# GENERAL #####################################
daemonize yes
pidfile "/var/run/redis_1001.pid"logfile "/usr/software/redis/redis-cluster/1001/log/redis.log"################################ SNAPSHOTTING  ################################dir "/usr/software/redis/redis-cluster/1001/data"################################ REDIS CLUSTER  ###############################
cluster-enabled yes
cluster-config-file nodes-1001.conf
cluster-node-timeout 15000################################## SECURITY ###################################
requirepass "ww"
Copy after login

The configuration files of several other instances can be modified as follows (you need to create the log and data directories yourself):

port 100x"/var/run/redis_100x.pid" 
logfile "/usr/software/redis/redis-cluster/100x/log/redis.log""/usr/software/redis/redis-cluster/100x/data"-config-file nodes-100x.conf
Copy after login

3. Cluster startup

1. Use redis-server /usr/software/redis/redis-cluster/1001/redis.conf ... to start all nodes

2. After starting, we can create the cluster

Note: Redis-cli is used to create a cluster after redis5.0. Before The version uses redis-trib.rb, but the installation of ruby ​​software is relatively complicated. Compared with the previous version 5.0, there is no need to install additional software, which is convenient. For details, please refer to the redis official website https://redis.io/topics/cluster-tutorial

Create cluster command: where cluster-replicas 1 represents how many slaves there are after one master , 1 represents 1 slave node

redis-cli --cluster create 127.0.0.1:1001  127.0.0.1:1002 127.0.0.1:1003 127.0.0.1:1004 127.0.0.1:1005 127.0.0.1:1006 --cluster-replicas 1 -a ww
Copy after login

The first time because there is no -a ww to add a password, the cluster creation fails.

The following content will be prompted during the process, enter yes to continue ;

Can I set the above configuration? (type 'yes' to accept): yes

The cluster automatic allocation results are as follows:

3. Verify whether the cluster is created successfully

First check the master-slave pairing

# #Execution: redis-cli -c -p 1001 -a ww

The data is automatically allocated to the 1002 node, and the connection is also transferred to the 1002 node

4. Verify failover

The conclusion is that after the master node fails, the subordinate slave node will be upgraded to the master node and take over the slot of the master node. After the old master node comes online, it can only serve as its slave node.

Kill 1001 and find that it has been converted from node 1004 to master

 

Restart 1001 and it becomes slave node

 

The above is the detailed content of Introducing the three cluster modes of Redis (Cluster cluster mode). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template