大家好,我是老坛。
1. 问题描述
相信大家在搭建redis集群的时候都遇到过这样的问题,在执行了命令:
redis-cli --cluster create 47.94.201.245:7001 47.94.201.245:7002 47.94.201.245:7003 47.94.201.245:7004 47.94.201.245:7005 47.94.201.245:7006 --cluster-replicas 1
之后一直卡在 Waiting for the cluster to join这,一直阻塞:
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 47.94.201.245:7005 to 47.94.201.245:7001
Adding replica 47.94.201.245:7006 to 47.94.201.245:7002
Adding replica 47.94.201.245:7004 to 47.94.201.245:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 11f15cbaa8be30190f348ca49e4fa222fd1f854b 47.94.201.245:7001
slots:[0-5460] (5461 slots) master
M: f89f54d67ca64731dbee977aa37a87f8fe833281 47.94.201.245:7002
slots:[5461-10922] (5462 slots) master
M: 0cc34305106e109579c93f9e9d595d82022b602e 47.94.201.245:7003
slots:[10923-16383] (5461 slots) master
S: e9149384dfae51350c510ebb827b503cfb7be74c 47.94.201.245:7004
replicates 11f15cbaa8be30190f348ca49e4fa222fd1f854b
S: b95462fed727d78263a04d6ee26b4f70f5081021 47.94.201.245:7005
replicates f89f54d67ca64731dbee977aa37a87f8fe833281
S: f36793915fb1afbc0177ee568b2d9a97967b402d 47.94.201.245:7006
replicates 0cc34305106e109579c93f9e9d595d82022b602e
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
.....................................................................................................................................................................................................................................................................................................................................................................................................................
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
2. 问题解决
对于这个问题通常是因为端口没有开放的原因。大家可能会说,我的客户端访问端口明明开放了还有这个问题。这是因为除了客户端访问端口之外,还有一个集群间通信用到的总线端口。
总线端口的port是在原客户端访问端口的基础上加10000。比如你的客户端访问端口是7001,那你的总线端口就是17001。在总线端口没有开放的情况下,我们的集群也是无法正常搭建起来的,所以大家还需要把各节点的总线端口都开放一下才可以。
更多优质文章和代码资源请关注同名公众号:老坛聊开发
关于端口的开放,除了要看防火墙之外,如果大家是用的阿里云服务器也要看一下有没有加上相关的配置。
3. 总结
好有关搭建redis集群时遇到的无限Waiting for the cluster to join就给大家介绍到这里,希望大家点赞点关注!