3主3从Redis集群
搭建
使用docker搭建3主3从的Redis集群,每台主机都对应一台从机。
启动6台redis容器
构建主从关系:
进入节点1(或其中任意一个节点):
构建主从关系:
redis尝试自动进行主从节点分配
因为我们的docker容器IP相同,所以会出现警告,可以直接忽略该警告
redis自动分配结果完成后,需要输入 Yes 确认配置信息:
输入Yes确认后,redis会向其他节点发送信息加入集群,并分配哈希槽:
Plain Text
Nodes configuration updated
Assign a different config epoch to each node
Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.....
Performing Cluster Check (using node 192.168.xxx.xxx:6381)
M: f451eb48bbc0a7c31c7da022ffe80cc1696e0f37 192.168.xxx.xxx:6381
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 1fc935c12b1d34a7df50aed643c195eb29bb3435 192.168.xxx.xxx:6383
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: 05984211b8c38222a73abeff1d4e459c0fe1efbc 192.168.xxx.xxx:6382
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 0c0767e13a09ee48541738d4163592cd9842c143 192.168.xxx.xxx:6386
slots: (0 slots) slave
replicates 05984211b8c38222a73abeff1d4e459c0fe1efbc
S: f8d0de47114bf33438747acd713cce4e412ae721 192.168.xxx.xxx:6384
slots: (0 slots) slave
replicates 1fc935c12b1d34a7df50aed643c195eb29bb3435
S: de0b393c17e452d856f6de2b348e9ca4e5aa4002 192.168.xxx.xxx:6385
slots: (0 slots) slave
replicates f451eb48bbc0a7c31c7da022ffe80cc1696e0f37
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
查看集群状态:
进入容器节点1(或集群中其他节点):
Shell
运行代码
复制代码
1
docker exec -it redis-node-1 /bin/bash
使用redis-cli连接到6381节点:
Shell
运行代码
复制代码
1
redis-cli -p 6381
使用redis的相关命令查看集群状态:
Shell
运行代码
复制代码
1
cluster info
其中,分配的哈希槽数量 cluster_slots_assigned为16384,集群节点数量cluster_known_nodes为6
查看集群节点信息
Shell
运行代码
复制代码
1
cluster nodes