Ricky 这里有三台 Redis(操作系统均为 CentOS Linux 5.8 ),最近可能是因为内存溢出挂掉了其中一台,挂掉的这台恢复后,在使用命令 redis-trib.rb 重建集群时报以下错误:
[root@host ~]# /usr/local/redis/src/redis-trib.rb create --replicas 1 192.168.1.1:7000 192.168.1.1:7001 192.168.1.2:7000 192.168.1.2:7001 192.168.1.3:7000 192.168.1.3:7001 >>> Creating cluster [ERR] Node 192.168.1.1:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0. [root@host ~]#
解决方法:
1 、先 kill 掉这 6 个 Redis 进程:
以其中一台为例: [root@host ~]# ps -ef | grep redis root 10364 5677 0 10:49 pts/0 00:00:00 /usr/local/redis/src/redis-server 192.168.1.1:7001 [cluster] root 10367 5677 0 10:49 pts/0 00:00:00 /usr/local/redis/src/redis-server 192.168.1.1:7000 [cluster] root 11660 5677 0 10:59 pts/0 00:00:00 grep redis [root@host ~]# [root@host ~]# kill 10364 [root@host ~]# kill 10367
2 、删除这三台服务器上共 6 个 Redis 的 aof 和 rdb 持久化文件:
注意:
- 删除持久化文件会丢数据,谨慎操作;
- 持久化文件不一定存放在以下文件夹里,请查看您 redis.conf 配置文件里是怎么配置的。
以其中一台为例: [root@host ~]# cd /usr/local/redis/redis_cluster/7000 [root@host 7000]# rm -f appendonly.aof dump.rdb [root@host 7000]# cd /usr/local/redis/redis_cluster/7001 [root@host 7001]# rm -f appendonly.aof dump.rdb
3 、删除这三台服务器上共 6 个 Redis 的 cluster-config-file 文件(同样地,这个 cluster-config-file 文件不一定存放在以下文件夹里,请查看您 redis.conf 配置文件里是怎么配置的):
以其中一台为例: [root@host 7001]# cd /usr/local/redis/redis_cluster/7000 [root@host 7000]# rm -f nodes-7000.conf nodes-7001.conf
4 、启动这三台服务器上的 6 个 Redis ,然后使用命令 redis-trib.rb 创建集群看看,现在应该是没有问题了。
5 、如果还有问题,那么此时可以尝试使用以下命令登录这 6 个 Redis 并清除 Redis 的数据库,然后再使用命令 redis-trib.rb 创建集群:
以其中一台为例: [root@host 7000]# /usr/local/redis/src/redis-cli -h 192.168.1.1 -p 7000 192.168.1.1:7000> flushdb 192.168.1.1:7000> exit [root@host 7000]# [root@host 7000]# /usr/local/redis/src/redis-cli -h 192.168.1.1 -p 7001 192.168.1.1:7001> flushdb 192.168.1.1:7001> exit [root@host 7000]#
至此,问题解决。
参考自:
- https://blog.csdn.net/vtopqx/article/details/50235737
发表评论?