redis-cluster 集群搭建详细指南及常见问题集合

只当个搬运工吧

搭建篇:https://www.cnblogs.com/mafly/p/redis_cluster.html   测试能用

常见问题:

1 redis操作key时出现以下错误 (error) MOVED 5798 127.0.0.1:7001

 https://www.fashici.com/tech/356.html

2.ERR] Not all 16384 slots are covered by nodes.

   https://blog.csdn.net/vtopqx/article/details/50235891

3.in `call': ERR Slot 8579 is already busy (Redis::CommandError)

   错误提示是

   slot插槽被占用了(这是 搭建集群前时,以前redis的旧数据和配置信息没有清理干净。)

   解决方案是

   用redis-cli 登录到每个节点执行  flushall  和 cluster reset  就可以了。然后重新执行群集脚本命令:

./redis-trib.rb create --replicas 0 192.168.3.15:6379 192.168.3.15:6380 192.168.3.15:6381 

4.[ERR] Not all 16384 slots are covered by nodes.


  redis群集搭建成功后,6379节点莫名其的宕机,重启了几次,一会儿就又宕机了。在 /my_soft/Redis安装包及jar包/redis-3.0.4/src 目录 下执行check脚本:

 

./redis-trib.rb check 192.168.3.15:6379
./redis-trib.rb check 192.168.3.15:6380
./redis-trib.rb check 192.168.3.15:6381

  

  1. 其中,6379节点出现了:[ERR] Not all 16384 slots are covered by nodes. 如下图所示:

 


slot插槽出问题了,修复slot 执行下面的命令:

 

./redis-trib.rb fix 192.168.3.15:6379

 

 

当然了,我们也可以把6380、6381节点都修复一下:

 

  1.  
    ./redis-trib.rb fix 192.168.3.15:6380
  2.  
    ./redis-trib.rb fix 192.168.3.15:6381

 

修改完毕后,重启6379节点,

/usr/local/bin/redis-server  /my_soft/my_config/redis3/6379/redis.conf

 5.集群操作

移动槽

redis-trib.rb reshard 127.0.0.1:6360
执行集群reshard操作,通过集群中127.0.0.1:6360这一台机器
 
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 2731
输入需要移动的槽数量
 
What is the receiving node ID? 21c93aa709e10f7a9064faa04539b3ecd
输入接收的节点的ID
 
How many slots do you want to move (from 1 to 16384)? 2731
What is the receiving node ID? 0abf4ca21c93aa709e10f7a9064faa04539b3ecd
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:0ddb4e430dda8778ac873dd169951c7d71b8235e
Source node #2:done
输入所有被移动的节点ID,确认后输入done
 
    Moving slot 5460 from 0ddb4e430dda8778ac873dd169951c7d71b8235e
    Moving slot 13653 from 0ddb4e430dda8778ac873dd169951c7d71b8235e
Do you want to proceed with the proposed reshard plan (yes/no)?
检查后输入yes进行移动分槽
至此,分槽移动完毕。
 
 

删除节点

 
redis-trib.rb del-node 127.0.0.1:6360 'f24c0c1ecf629b5413cbca632d389efcad7c8346'
最后跟着的是这个节点的ID,可在redis-cli终端中使用CLUSTER NODES查看
必要条件,此节点所有分槽均已移除。
 
 

添加master节点

redis-trib.rb add-node 127.0.0.1:6360 127.0.0.1:6350
新节点必须是空的,不能包含任何数据。请把之前aof和dump文件删掉,并且若有nodes.conf也需要删除。
add-node  将一个节点添加到集群里面, 第一个是新节点ip:port, 第二个是任意一个已存在节点ip:port
node:新节点没有包含任何数据, 因为它没有包含任何slot。新加入的加点是一个主节点, 当集群需要将某个从节点升级为新的主节点时, 这个新节点不会被选中,同时新的主节点因为没有包含任何slot,不参加选举和failover。
 
 

添加一个从节点

前三步操作同添加master一样
第四步:redis-cli连接上新节点shell,输入命令:cluster replicate 对应master的node-id

 

posted @ 2018-07-01 17:05  子木子木  阅读(640)  评论(0编辑  收藏  举报