redis主从连接不成功错误问题及解决

2024-03-01 0 383
目录

redis主从连接不成功错误

安装完redis后,设置主从,在从服务器上运行

127.0.0.1:6379> slaveof 192.168.159.131 6379

slaveof <主服务器的IP> <主服务器redis的端口>

然后回到主服务器上,运行info replication

显示如下:

127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

问题出现了

从没有连接上来。

查看主redis的日志文件

[1922] 22 Mar 22:04:24.971 * RDB: 0 MB of memory used by copy-on-write[1544] 22 Mar 22:04:25.008 * Background saving terminated with success[1544] 22 Mar 22:27:23.567 * Background saving started by pid 2079[2079] 22 Mar 22:27:23.574 * DB saved on disk[2079] 22 Mar 22:27:23.575 * RDB: 0 MB of memory used by copy-on-write[1544] 22 Mar 22:27:23.604 * Background saving terminated with success

查看从服务器日志

有如下错误:

Error condition on socket for SYNC: No route to host

然后telnet 主的端口竟然不通,发现主服务器的iptables开着,关掉后就可以和主服务器的端口通了(生产环境添加iptables规则)。

但是发现还是从不能连上主,再看从的日志时

变成如下内容:

[4399] 22 Mar 14:41:56.311 # MASTER aborted replication with an error: NOAUTH Authentication required.[4399] 22 Mar 14:41:57.313 * Connecting to MASTER 192.168.159.131:6379[4399] 22 Mar 14:41:57.313 * MASTER <-> SLAVE sync started[4399] 22 Mar 14:41:57.313 * Non blocking connect for SYNC fired the event.[4399] 22 Mar 14:41:57.314 * Master replied to PING, replication can continue…[4399] 22 Mar 14:41:57.315 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.[4399] 22 Mar 14:41:57.315 * Partial resynchronization not possible (no cached master)[4399] 22 Mar 14:41:57.316 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.[4399] 22 Mar 14:41:57.317 * Retrying with SYNC…[4399] 22 Mar 14:41:57.319 # MASTER aborted replication with an error: NOAUTH Authentication required.

网上查找有说是版本不一致造成的,但是我的版本都是一样的。

最后找到了解决方法

原来是主从都开启了密码requirepass,导致不能验证成功

在redis从服务器的配置文件里面添加如下内容:

masterauth 123456

(123456是我的主redis的密码,此参数是当与主连接时的密码验证)

总结

这样就解决了主从连接不成功问题~

以上为个人经验,希望能给大家一个参考,也希望大家多多支持悠久资源。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 Redis redis主从连接不成功错误问题及解决 https://www.u-9.cn/database/redis/176674.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务