当前位置:网站首页>Hash slot of rediscluster cluster cluster implementation principle
Hash slot of rediscluster cluster cluster implementation principle
2022-06-28 07:35:00 【Huangyuewang】
Redis Clusters use data fragmentation , Instead of consistent hashing , One Redis The cluster contains 16384 Hash slot (hash slot), Use set The stored data belongs to 16384 One of the hash slots , Cluster use crc16(key) % 16384 To calculate key Which slot does it belong to .
Illustrate with examples , Now we need to build Cluster colony 6 Nodes ,redis Of Port number In turn 7000,7001,7002,7003,7004,7005,6 Nodes are divided into 3 Group , A master (master) A congruent form
Here's the picture
Calculate the hash slot sorting for each group , Each group =16384/3=5461
that :
First set of ports 7000 The hash slot of is 0-5460
First set of ports 7001 The hash slot of is 5461-10922
First set of ports 7002 The hash slot of is 10923-16383
notes : The figure below is a bit wrong , I'm too lazy to redraw

Let's prepare for practical operation :
One , Cluster Cluster building
1, The first step is to be ready 8 individual redis.conf file
linux In the environment ,redis Deployed in /application Under the table of contents , First create a good 8 Directories execute the following commands :
cd /application
mkdir rediscluster
cd rediscluster/
mkdir redis7000
mkdir redis7001
mkdir redis7002
mkdir redis7003
mkdir redis7004
mkdir redis7005
# Then dynamically add to the hash slot
mkdir redis7006
mkdir redis7007A copy of redis.conf, Modify the following :
dbfilename 7000dump.rdb
daemonize yes # Background start
protected-mode no ; ## Allow external access
port 7000 # Modify port number , from 7000 To 7007
cluster-enabled yes # Turn on cluster, Remove annotations
cluster-config-file 7000nodes.conf # Automatic generation
cluster-node-timeout 15000 # Node communication time
logfile /application/rediscluster/redis7000/redis.log"/application/rediscluster/redis7000/redis.log"Then the file is copied 8 Share , Modify the above contents in turn , Change it and put it in the corresponding folder .
Pay attention to the upper band 7000-7007 It's the port number , Each folder corresponds to the corresponding port number , for example :redis7005 In a folder redis.conf The content corresponds to
dbfilename 7005dump.rdb
port 7005 # Modify port number , from 7000 To 7007
cluster-config-file 7005nodes.conf # Automatic generation
logfile /application/rediscluster/redis7005/redis.log"/application/rediscluster/redis7005/redis.log"give the result as follows :


2, The second step , start-up 6 individual redis
/application/redis/bin/redis-server /application/rediscluster/redis7000/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7001/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7002/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7003/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7004/redis.conf
/application/redis/bin/redis-server /application/rediscluster/redis7005/redis.confCheck the process :ps -ef|grep redis

notes : No hash slot is allocated set operation , Because the data is stored in the hash slot , I haven't been assigned how to write ?
3, The third step , Assign hashico
/application/redis/bin/redis-cli --cluster create 172.16.166.122:7000 172.16.166.122:7001 172.16.166.122:7002 172.16.166.122:7003 172.16.166.122:7004 172.16.166.122:7005 --cluster-replicas 1The following figure will pop up after execution , Ask whether to set the above configuration ? Input yes

This completes the allocation of hash slots
4, Step four , View the assigned Hashi slots
First connect to 7000 Port node
#172.16.166.122 It's the intranet IP
/application/redis/bin/redis-cli -h 172.16.166.122 -p 7000 -cEnter the command : cluster nodes

You can see that there is 3 Group master, Only master To allocate Hashi slots , The cluster will automatically conduct the election , Here's the picture 7000,7001,7002 yes master node ,7000 The slave node of is 7004, Maybe some friends built it according to the above figure 7000 The children of are 7003, It's all possible , The result of the election shall prevail

7000 and 7004 How nodes are associated ? Look at the picture below to see the answer

Test cluster :
Test write operation :
# Connect to cluster
/application/redis/bin/redis-cli -h 172.16.166.122 -p 7000 -ctest set aaa 1 Data stored in [10439] Hash slot , Belong to 7001 node
test set bbb 2 Data stored in [5287] Hash slot , Belong to 7000 node

Test read operation :
test get aaa from 7001 Hashi slot of node [10439] To find the key The result is 1

边栏推荐
- DOM parsing of XML file case code sentence by sentence analysis
- Encyclopedia of scala operators
- Vivo browser rapid development platform practice - Overview
- PLC -- 笔记
- Is it safe for flush to open an account online
- 面经---测试工程师web端自动化---大厂面试题
- What is a consistent hash? What scenarios can it be applied to?
- 云原生(待更新)
- Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner
- 阿里云服务器创建快照、回滚磁盘
猜你喜欢

Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers

Practice and exploration of vivo live broadcast application technology

kubernetes删除pod的流程的源码简析

Sword finger offer|: linked list (simple)

The practice of event driven architecture in vivo content platform

Construction and exploration of vivo database and storage platform

"Three routines" of digital collection market

看似简单的光耦电路,实际使用中应该注意些什么?
面经---测试工程师web端自动化---大厂面试题

PLC -- Notes
随机推荐
ice, protobuf ,thrift -- 笔记
什么是EC鼓风机(ec blower fan)?
Safety training is the greatest benefit for employees! 2022 induction safety training for new employees
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
LLVM 与 Clang
R 语言 ggmap
HTTP Caching Protocol practice
Evaluation of inverse Polish expression < difficulty coefficient >
R language Kolmogorov Smirnov tests whether the two samples follow the same distribution.
在idea中,get和set方法爆红可能是没有安装Lombok插件
Makefile
kubernetes删除pod的流程的源码简析
[ thanos源码分析系列 ]thanos query组件源码简析
安全培训是员工最大的福利!2022新员工入职安全培训全员篇
力扣515.在每棵树行中找最大值
Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
Will Internet talents be scarce in the future? Which technology directions are popular?
股票炒股注册开户靠谱吗?安全吗?
DOM parsing of XML file case code sentence by sentence analysis
open62541直接导入NodeSet文件