Redis[8] Redis6. Cluster cluster with high availability of X nodes

You and other students 2022-02-13 08:08:48 阅读数:835

redis redis6. redis cluster cluster

This article has been arranged since childhood d Class notes and java Advanced warehouse , any similarity , Most of them are written by others

java Advanced warehouse :

Redis6.X Node high availability Cluster colony

Cluster Introduction to data slicing and virtual hash slot

  • background

    • The write capacity and storage capacity of the primary node are limited

    • A single machine cannot meet the demand , Therefore, the data is stored in multiple machines

    • Similar cases :mysql Sub database and sub table

  • Common data partitioning algorithms

    • Hash modulus
      • Of choice partitioning key Calculate its hash value , The resulting hash value is the corresponding partition
    • Range fragmentation
      • Select the partition by determining whether the partition key is within a certain range
    • Uniformity Hash Partition
    • redis cluster The cluster does not adopt a consistent hash scheme , instead 【 Data fragmentation 】 To store and read data
  • What is? Redis The hashico of slot

    • Redis The cluster is prearranged 16384 Slot , When need is in Redis Place one in the cluster key-value when , according to CRC16(key) mod 16384 Value , Decided to put a key In which bucket
  • General process

    • Suppose the number of master nodes is 3, take 16384 The slots are arranged according to 【 User's own rules 】 To allocate this 3 Nodes , Each node copies a portion of the slot
      • node 1 The range of the slot position range is 0-5460
      • node 2 The range of the slot position range is 5461-10922
      • node 3 The range of the slot position range is 10923-16383
      • Be careful : The slave node has no slot , Only the master node has
    • Storage lookup
      • The key to store the lookup crc16 Hash operation , Get a value , And take the mold 16384, Determine the range of this value in which node
      • hypothesis crc16(“test_key”)%16384=3000, Node one
      • crc16 The algorithm is not simple hash Algorithm , Is a verification algorithm
  • The advantage of using hash slots is that you can easily add or remove nodes .

    • When you need to add nodes , Just move some hash slots of other nodes to the new node ;
    • When a node needs to be removed , Just move the hash slot on the removed node to another node

Cluster colony

  • explain

    • The old version needs to use ruby Language to build , new edition 5 And then use it directly redis-cli that will do
    • 6 Nodes , Three masters and two slaves , The master and slave nodes are automatically assigned , Not manually specified
    • After the primary node fails , The slave node replaces the master node
  • Be careful :

    • Put the previous rdb、aof File deletion
  • node ( Network security group open port )

  • start-up 6 Nodes

./redis-server ../conf/cluster/redis1.conf
./redis-server ../conf/cluster/redis2.conf
./redis-server ../conf/cluster/redis3.conf
./redis-server ../conf/cluster/redis4.conf
./redis-server ../conf/cluster/redis5.conf
./redis-server ../conf/cluster/redis6.conf
  • To join the cluster ( One of the nodes can execute )
    • –cluster Build all node information of the cluster
    • –cluster-replicas 1 The proportion of master and slave nodes ,1 Express 1 Lord 1 From the way

High availability shelf

Structural summary

  • A master-slave mode : Read / write separation , Backup , One Master There can be multiple Slaves
  • sentry sentinel: monitor , Automatic transfer , When the sentinel found out that the main server was hung up , It will start from slave Re - election of a primary server
  • colony : In order to solve single machine Redis The problem of limited capacity , Allocate data to multiple machines according to certain rules , Memory /QPS Not limited to a single machine , Increase concurrency .
copyright:author[You and other students],Please bring the original link to reprint, thank you.