“Redis Cluster”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第110行: | 第110行: | ||
cluster-announce-bus-port 16481 | cluster-announce-bus-port 16481 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | ==== 配置说明 ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | bind 127.0.0.1 | ||
+ | port 6379 | ||
+ | cluster-enabled yes | ||
+ | cluster-config-file nodes-6379.conf | ||
+ | cluster-node-timeout 15000 | ||
+ | cluster-announce-port 6379 | ||
+ | cluster-announce-bus-port 16379 | ||
+ | </syntaxhighlight> | ||
+ | {| class="wikitable" | ||
+ | |cluster-enabled | ||
+ | |是否开启集群 | ||
+ | |- | ||
+ | |cluster-config-file | ||
+ | |生成的 node 文件,记录集群节点信息,默认为 nodes.conf | ||
+ | |- | ||
+ | |cluster-node-timeout | ||
+ | |节点连接超时时间 | ||
+ | |- | ||
+ | |cluster-announce-port | ||
+ | |集群节点映射端口 | ||
+ | |- | ||
+ | |cluster-announce-bus-port | ||
+ | |集群节点总线端口,节点之间互相通信,常规端口+1万,记录每个 key slot 在集群中哪个节点上的 2k bitmap 心跳包用此端口进行传输 | ||
+ | |} | ||
+ | |||
2023年2月20日 (一) 03:34的版本
图解
1
每个节点主数据不同,是数据的子集
利用多台服务器构建集群提高超大规模数据处理能力
同时提供高可用支持
2
Redis Cluster 集群采用 Hash Slot(哈希槽)分配
Redis 集群预分好 16384 个槽,初始化集群时平均规划给每一台 Redis Master
为什么是 16384?
在 Redis 集群中槽分配的元数据会不间断的在 Redis 集群中分发,以保证所有节点都知晓槽的分配情况
16384=16k,在发送心跳包时使用 char 进行 bitmap 压缩后是 2k(2*8(8 bit) * 1024(1k)=16K)
通常我们不会部署超过10000个 Redis 主节点,因此16384就够用了
配置
cluster-master-0.conf
bind 127.0.0.1
port 6379
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
cluster-announce-port 6379
cluster-announce-bus-port 16379
cluster-master-1.conf
bind 127.0.0.1
port 6380
cluster-enabled yes
cluster-config-file nodes-6380.conf
cluster-node-timeout 15000
cluster-announce-port 6380
cluster-announce-bus-port 16380
cluster-master-2.conf
bind 127.0.0.1
port 6381
cluster-enabled yes
cluster-config-file nodes-6381.conf
cluster-node-timeout 15000
cluster-announce-port 6381
cluster-announce-bus-port 16381
cluster-slave-0.conf
bind 127.0.0.1
port 6479
cluster-enabled yes
cluster-config-file nodes-6479.conf
cluster-node-timeout 15000
cluster-announce-port 6479
cluster-announce-bus-port 16479
cluster-slave-1.conf
bind 127.0.0.1
port 6480
cluster-enabled yes
cluster-config-file nodes-6480.conf
cluster-node-timeout 15000
cluster-announce-port 6480
cluster-announce-bus-port 16480
cluster-slave-2.conf
bind 127.0.0.1
port 6481
cluster-enabled yes
cluster-config-file nodes-6481.conf
cluster-node-timeout 15000
cluster-announce-port 6481
cluster-announce-bus-port 16481
配置说明
bind 127.0.0.1
port 6379
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
cluster-announce-port 6379
cluster-announce-bus-port 16379
cluster-enabled | 是否开启集群 |
cluster-config-file | 生成的 node 文件,记录集群节点信息,默认为 nodes.conf |
cluster-node-timeout | 节点连接超时时间 |
cluster-announce-port | 集群节点映射端口 |
cluster-announce-bus-port | 集群节点总线端口,节点之间互相通信,常规端口+1万,记录每个 key slot 在集群中哪个节点上的 2k bitmap 心跳包用此端口进行传输 |
注意
- 集群配置中不允许出现 replicaof 的配置项,否则就会报
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\redis-cluster0.conf [31444] 20 Feb 10:59:14.659 # *** FATAL CONFIG FILE ERROR *** [31444] 20 Feb 10:59:14.659 # Reading the configuration file, at line 1345 [31444] 20 Feb 10:59:14.660 # >>> 'replicaof 127.0.0.1 6380' [31444] 20 Feb 10:59:14.660 # replicaof directive not allowed in cluster mode
启动
master-0
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\cluster-master-0.conf
[21000] 20 Feb 11:05:53.729 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
[21000] 20 Feb 11:05:53.729 # Redis version=5.0.14.1, bits=64, commit=ec77f72d, modified=0, pid=21000, just started
[21000] 20 Feb 11:05:53.729 # Configuration loaded
[21000] 20 Feb 11:05:53.732 * No cluster configuration found, I'm 74168c6581ab94338a85097768ae4cb376ef3c75
……
[21000] 20 Feb 11:05:53.927 # I have keys for unassigned slot 9231. Taking responsibility for it.
[21000] 20 Feb 11:05:53.928 # I have keys for unassigned slot 15118. Taking responsibility for it.
[21000] 20 Feb 11:05:53.928 # I have keys for unassigned slot 15901. Taking responsibility for it.
[21000] 20 Feb 11:05:53.928 # I have keys for unassigned slot 16066. Taking responsibility for it.
[21000] 20 Feb 11:05:53.977 * Ready to accept connections
master-1
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\cluster-master-1.conf
……
master-2
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\cluster-master-2.conf
……
slave-0
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\cluster-slave-0.conf
……
slave-1
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\cluster-slave-1.conf
……
slave-2
F:\下载目录\Redis-x64-5.0.14.1>.\redis-server.exe .\config\cluster\cluster-slave-2.conf
……