# 进入容器redis-node-1并为6台机器构建集群关系

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/19028.html | 发布：2023-03-29 | 更新：2023-03-29 | 分类：建站教程

1.进入容器  
 docker exec -it redis-node-1 /bin/bash  
   
2.#注意，进入docker容器后才能执行一下命令，且注意自己的真实IP地址  
 redis-cli --cluster create IP地址:6381 IP地址:6382 IP地址:6383 192.168.111.147:6384 IP地址:6385 IP地址:6386 --cluster-replicas 1  
 #--cluster-replicas 1 表示为每个master创建一个slave节点  
   
3.#3主3从搞定

 

**运行结果**

 

**[root@localhost home]# docker exec -it redis-node-1 /bin/bash  
root@localhost:/data# redis-cli --cluster create 192.168.153.138:6381 192.168.153.138:6382 192.168.153.138:6383 192.168.153.138:6384 192.168.153.138:6385 192.168.153.138:6386 --cluster-replicas 1  
>>> Performing hash slots allocation on 6 nodes... #hash槽对这六个节点经行分配  
Master[0] -> Slots 0 - 5460 #如上图对16384个槽位分配 0 - 5460 5461 - 10922 10923 - 16383  
Master[1] -> Slots 5461 - 10922  
Master[2] -> Slots 10923 - 16383  
Adding replica 192.168.153.138:6385 to 192.168.153.138:6381  
Adding replica 192.168.153.138:6386 to 192.168.153.138:6382  
Adding replica 192.168.153.138:6384 to 192.168.153.138:6383  
>>> Trying to optimize slaves allocation for anti-affinity  
[WARNING] Some slaves are in the same host as their master  
M: d9b335b44e89e3a46f30466e70867de7fdd3d5ad 192.168.153.138:6381 #主  
 slots:[0-5460] (5461 slots) master  
M: 7a876fd455a6e77923e0ab340335c430f25ed11f 192.168.153.138:6382 #主  
 slots:[5461-10922] (5462 slots) master  
M: fbacfaed169736db5278e4f685adf44a9bcd55ea 192.168.153.138:6383 #主  
 slots:[10923-16383] (5461 slots) master  
S: 798440dfeb0aa728aba2f4a9f783eb20edeaa09c 192.168.153.138:6384 #从  
 replicates fbacfaed169736db5278e4f685adf44a9bcd55ea  
S: 37299c5efbf061f019bf24780661144a171c24df 192.168.153.138:6385 #从  
 replicates d9b335b44e89e3a46f30466e70867de7fdd3d5ad  
S: ece2d11584c4d7a0b1d9699c90aa2016fcf75924 192.168.153.138:6386 #从  
 replicates 7a876fd455a6e77923e0ab340335c430f25ed11f  
Can I set the above configuration? (type 'yes' to accept): yes  
>>> 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.153.138:6381)  
M: d9b335b44e89e3a46f30466e70867de7fdd3d5ad 192.168.153.138:6381  
 slots:[0-5460] (5461 slots) master  
 1 additional replica(s)  
S: ece2d11584c4d7a0b1d9699c90aa2016fcf75924 192.168.153.138:6386  
 slots: (0 slots) slave  
 replicates 7a876fd455a6e77923e0ab340335c430f25ed11f  
M: fbacfaed169736db5278e4f685adf44a9bcd55ea 192.168.153.138:6383  
 slots:[10923-16383] (5461 slots) master  
 1 additional replica(s)  
M: 7a876fd455a6e77923e0ab340335c430f25ed11f 192.168.153.138:6382  
 slots:[5461-10922] (5462 slots) master  
 1 additional replica(s)  
S: 37299c5efbf061f019bf24780661144a171c24df 192.168.153.138:6385  
 slots: (0 slots) slave  
 replicates d9b335b44e89e3a46f30466e70867de7fdd3d5ad  
S: 798440dfeb0aa728aba2f4a9f783eb20edeaa09c 192.168.153.138:6384  
 slots: (0 slots) slave  
 replicates fbacfaed169736db5278e4f685adf44a9bcd55ea  
[OK] All nodes agree about slots configuration.  
>>> Check for open slots...  
>>> Check slots coverage...  
[OK] All 16384 slots covered.**

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
