当前位置:网站首页>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 redis7007
A 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.conf
Check 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 1
The 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 -c
Enter 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 -c
test 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
边栏推荐
- R语言绘制 ggplot2 季节性图
- ABAP skill tree
- 8 张图 | 剖析 Eureka 的首次同步注册表
- Unity-UI-shadow组件
- Server body 18: understanding and thinking of UDP reliable transmission (feeling from reading Yunfeng blog)
- Is it reliable to register and open an account for stock speculation? Is it safe?
- XML序列化向后兼容
- This keyword details
- Leetcode+ 66 - 70 high precision, two sub topics
- Open62541 import nodeset file directly
猜你喜欢
No suspense about the No. 1 Internet company overtime table
安全培训是员工最大的福利!2022新员工入职安全培训全员篇
MySQL installation steps - Linux configuration file JDK installation (II)
es6箭头函数中return的用法
Recommended system series (Lecture 5): Optimization Practice of sorting model
推荐系统系列精讲(第五讲): 排序模型的调优实践
open62541直接导入NodeSet文件
Evolution of vivo push platform architecture
Hack the box:routerspace
看似简单的光耦电路,实际使用中应该注意些什么?
随机推荐
剑指Offer||:链表(简单)
Flutter realizes the function of "shake"
Is it safe for flush to open an account online
Can okcc call centers work without computers?
自律挑战30天
SQL statement optimization steps (1)
goland IDE和delve调试位于kubernetes集群中的go程序
MySQL installation steps - how to create a virtual machine under Linux (1)
Optimization steps of SQL statements (II) -- MySQL statement optimization
ES6 use of return in arrow function
Detailed explanation of collection class methods____ (4) Judgment and assignment, etc
R语言绘制 ggplot2 季节性图
异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
R language Kolmogorov Smirnov tests whether the two samples follow the same distribution.
R 语言 Kolmogorov-Smirnov 检验 2 个样本是否遵循相同的分布。
Modifying MySQL user name root under Linux
ice - 资源
剑指offer II 091.粉刷房子
NDK cross compilation
kubelet驱逐机制的源码分析