Redis Cluster

来自姬鸿昌的知识库
跳到导航 跳到搜索

图解

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

注意

  • 集群配置中不允许出现 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


参考

https://www.bilibili.com/video/BV1F44y1C7N8