iis服务器助手广告
返回顶部
首页 > 资讯 > 数据库 >redis主从连接不成功错误问题及解决
  • 353
分享到

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

redis主从redis主从连接redis主从连接不成功 2024-01-29 21:01:48 353人浏览 八月长安
摘要

目录Redis主从连接不成功错误问题出现了最后找到了解决方法总结redis主从连接不成功错误 安装完redis后,设置主从,在从服务器上运行 127.0.0.1:6379> slaveof 192.168.159.

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的密码,此参数是当与主连接时的密码验证)

总结

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网(www.lsjlt.com)。

您可能感兴趣的文档:

--结束END--

本文标题: redis主从连接不成功错误问题及解决

本文链接: https://www.lsjlt.com/news/559245.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作