启动redis集群服务报错:[ERR] Node 10.0.0.1:6001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
这是由于上次redis集群没有配置成功,生成了每个节点的配置文件和db的备份文件,所以才会产生这个错误,查资料要将每个节点中的appendonly.aof、dump.rdb、node_xxx.conf文件删除,因为不是手动部署的redis,所以我停止redis服务后,先查找到这些文件所在的位置,再依次进行删除。
1、停止每个节点的redis服务(采用的简单粗暴的强制杀进程方法)
(1)查看所有redis服务的进程id: ps -aux | grep redis-server
[root@test2 ~]# ps -aux | grep redis-server ca+ 3976 0.3 0.0 146068 2552 ? Ssl Dec10 3:06 /software/redis/src/redis-server *:6001 [cluster] ca+ 3984 0.3 0.0 146164 2636 ? Ssl Dec10 3:04 /software/redis/src/redis-server *:6002 [cluster] ca+ 3992 0.3 0.0 146064 2352 ? Ssl Dec10 3:04 /software/redis/src/redis-server *:6003 [cluster] ca+ 4000 0.3 0.0 146056 2388 ? Ssl Dec10 3:05 /software/redis/src/redis-server *:6004 [cluster] ca+ 4008 0.3 0.0 146056 2288 ? Ssl Dec10 3:04 /software/redis/src/redis-server *:6005 [cluster] ca+ 4015 0.3 0.0 146196 2472 ? Ssl Dec10 3:04 /software/redis/src/redis-server *:6006 [cluster] root 29387 0.0 0.0 112816 972 pts/0 S+ 08:54 0:00 grep --color=auto redis-server
(2)强制停止上述6个进程,使用kill -9 pid命令
2、查找到appendonly.aof、dump.rdb、node_xxx.conf文件的位置,并删除
(1)查找位置:find / -name appendonly.aof (根据文件名称查找/目录下的appendonly.aof文件)
[root@test2 ~]# find / -name appendonly.aof /run/redis_6003/appendonly.aof /run/redis_6006/appendonly.aof /run/redis_6001/appendonly.aof /run/redis_6002/appendonly.aof /run/redis_6004/appendonly.aof /run/redis_6005/appendonly.aof
(2)删除appendonly.aof、dump.rdb、node_xxx.conf文件。(删除每个redis节点的备份文件,数据库文件和集群配置文件)
依次切换到文件路径下:cd /run/redis_6001
依次删除文件:rm appendonly.aof
3、启动所有节点的redis服务
如:
/software/redis/src/redis-server /etc/redis_6001.conf
4、启动redis集群服务
/software/redis/src/redis-cli --cluster create 10.0.0.1:6001 10.0.0.1:6002 10.0.0.1:6003 10.0.0.1:6004 10.0.0.1:6005 10.0.0.1:6006 10.0.0.2:6001 10.0.0.2:6002 10.0.0.2:6003 10.0.0.2:6004 10.0.0.2:6005 10.0.0.2:6006 --cluster-replicas 1