【README】 redis集群添加节点报错
[ERR] Node 192.168.163.202:6380 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
【1】 原因
导致异常的主要原因是该节点中默认生成的配置或历史存储数据不一致导致的,清除对应节点的dump.rdb、nodes.conf文件,重启之后即可。
dump.rdb是由Redis服务器自动生成的 默认情况下 每隔一段时间redis服务器程序会自动对数据库做一次遍历,把内存快照写在一个叫做“dump.rdb”的文件里,这个持久化机制叫做SNAPSHOT。有了SNAPSHOT后,如果服务器宕机,重新启动redis服务器程序时redis会自动加载dump.rdb,将数据库状态恢复到上一次做SNAPSHOT时的状态。
【2】解决步骤:
1、停止服务,删除aof/rdb文件;
2、删除nodes.conf
3、必要的情况下执行flushdb。
原文链接: http://www.choupangxia.com/2019/11/07/redis-node-is-not-empty/
【3】报错现场和实际解决方法
1) 把 202:6380 添加到 机器201:6379所在集群,集群master节点的hash为 5571f088f9d8798dd0c2e973ced830c2cd8033a2
[root@centos201 ~]# /usr/local/redis-cluster/bin/redis-trib.rb add-node --slave --master-id 5571f088f9d8798dd0c2e973ced830c2cd8033a2 192.168.163.202:6380 192.168.163.201:6379
>>> Adding node 192.168.163.202:6380 to cluster 192.168.163.201:6379
Connecting to node 192.168.163.201:6379: OK
Connecting to node 192.168.163.203:6379: OK
Connecting to node 192.168.163.202:6379: OK
>>> Performing Cluster Check (using node 192.168.163.201:6379)
M: 5571f088f9d8798dd0c2e973ced830c2cd8033a2 192.168.163.201:6379
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: 5c0ea563b464e58dd8dc9722cdfcb97a85c44714 192.168.163.203:6379
slots:10923-16383 (5461 slots) master
0 additional replica(s)
M: 99a3516a03612dba4b73c32e7e1e03ff1145a660 192.168.163.202:6379
slots:5461-10922 (5462 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 192.168.163.202:6380: OK
[ERR] Node 192.168.163.202:6380 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
补充: 对以上命令的说明, 命令作用:为redis集群添加节点 , 把 202:6380 添加到 机器201:6379所在集群,集群master节点的hash为 5571f088f9d8798dd0c2e973ced830c2cd8033a2
2)停止202:6380 redis服务,并在202:6380机器上删除 redis aof文件, nodes.conf 文件; 最后重新启动 202:6380 redis服务
[root@centos202 ~]# ps -ef | grep redis
root 1665 1 0 21:17 ? 00:00:09 /usr/local/bin/redis-server 192.168.163.202:6379 [cluster]
root 1669 1 0 21:17 ? 00:00:07 /usr/local/bin/redis-server 192.168.163.202:6380 [cluster]
root 1673 1 0 21:17 ? 00:00:07 /usr/local/bin/redis-server 192.168.163.202:6381 [cluster]
root 1796 1694 0 23:04 pts/1 00:00:00 grep --color=auto redis
[root@centos202 ~]#
[root@centos202 ~]# kill -9 1669
[root@centos202 ~]#
[root@centos202 ~]# ps -ef | grep redis
root 1665 1 0 21:17 ? 00:00:09 /usr/local/bin/redis-server 192.168.163.202:6379 [cluster]
root 1673 1 0 21:17 ? 00:00:07 /usr/local/bin/redis-server 192.168.163.202:6381 [cluster]
root 1799 1694 0 23:06 pts/1 00:00:00 grep --color=auto redis
[root@centos202 ~]#
[root@centos202 6380]# cd data/
[root@centos202 data]# ll
total 4
-rw-r--r--. 1 root root 0 Feb 18 21:17 appendonly.aof
-rw-r--r--. 1 root root 229 Feb 18 22:49 nodes-6380.conf
[root@centos202 data]# rm appendonly.aof
rm: remove regular empty file 'appendonly.aof'? y
[root@centos202 data]# ll
total 4
-rw-r--r--. 1 root root 229 Feb 18 22:49 nodes-6380.conf
[root@centos202 data]# rm -rf nodes-6380.conf
[root@centos202 data]# ll
total 0
[root@centos202 data]#
[root@centos202 data]# /usr/local/bin/redis-server /usr/local/redis-cluster/6380/redis.conf
[root@centos202 data]#
[root@centos202 data]# ps -ef | grep redis
root 1665 1 0 21:17 ? 00:00:10 /usr/local/bin/redis-server 192.168.163.202:6379 [cluster]
root 1673 1 0 21:17 ? 00:00:07 /usr/local/bin/redis-server 192.168.163.202:6381 [cluster]
root 1808 1 43 23:07 ? 00:00:01 /usr/local/bin/redis-server 192.168.163.202:6380 [cluster]
root 1812 1694 0 23:07 pts/1 00:00:00 grep --color=auto redis
3) 再次把 202:6380 添加到 机器201:6379所在集群
[root@centos201 ~]# /usr/local/redis-cluster/bin/redis-trib.rb add-node --slave --master-id 5571f088f9d8798dd0c2e973ced830c2cd8033a2 192.168.163.202:6380 192.168.163.201:6379
>>> Adding node 192.168.163.202:6380 to cluster 192.168.163.201:6379
Connecting to node 192.168.163.201:6379: OK
Connecting to node 192.168.163.203:6379: OK
Connecting to node 192.168.163.202:6379: OK
>>> Performing Cluster Check (using node 192.168.163.201:6379)
M: 5571f088f9d8798dd0c2e973ced830c2cd8033a2 192.168.163.201:6379
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: 5c0ea563b464e58dd8dc9722cdfcb97a85c44714 192.168.163.203:6379
slots:10923-16383 (5461 slots) master
0 additional replica(s)
M: 99a3516a03612dba4b73c32e7e1e03ff1145a660 192.168.163.202:6379
slots:5461-10922 (5462 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 192.168.163.202:6380: OK
>>> Send CLUSTER MEET to node 192.168.163.202:6380 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.163.201:6379.
[OK] New node added correctly.
bingo 添加成功。