记一次遇到的Redis集群报错问题——[ERR] Nodes don't agree about configuration!的解决方案

最近在研究搭建redis集群。根据redis的官方文档,搭建redis集群至少需要6台机器:3台机器作为master节点,负责处理数据请求,以及参与集群选举投票,采用过半通过机制,所有需要2n+1(n >= 1)个节点;3台机器作为slave节点,作为master的备份节点。当master节点挂掉后,slave节点便提升为master节点。受限于硬件环境配置,我选择了使用3台机器来搭建redis的方案。在每台机器上分别启动master进程和slave进程,然后第二台机器的slave进程作为第一台机器的master进程的备份,依次类推。可以保证在这3台机器中的一台机器挂掉的情况下,redis集群还能正常工作。

安装redis的官方文档搭建完redis集群后,redis集群正常工作。但是在测试时发现一个问题,就是多启动几次master进程和slave进程,让redis自动切换角色后,redis集群不能正常工作,使用redis-trib.rb check 127.0.0.1:6379命令检测集群运行状况,redis报出了下面的错误信息:

[ERR] Nodes don't agree about configuration!
>>> Check for open slots...
[WARNING] Node 192.168.103.153:6379 has slots in importing state (107,415,1672,2204,3400).
[WARNING] The following slots are open: 107,415,1672,2204,3400
>>> Check slots coverage...
[OK] All 16384 slots covered.

这个问题在谷歌上查询了很久也没查到答案,后来通过检查redis的配置文件redis.conf文件才找到原因,原来是在master进程和slave进程分别使用的配置文件中,我将这appendfilename一项配置成了同一个值:

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information

appendonly yes

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof

这个配置项是redis持久化数据到本地磁盘的文件名称,当使用了同一个名称时,master进程和slave进程都向这个数据库写入数据,造成了数据错乱,集群不能正常工作,修改appendfilename为不同的值后,问题得以解决。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值