redis4.0.12主从连接报错Error condition on socket for SYNC: Connection refused和Connection reset by peer

7 篇文章 0 订阅

当我配置好redis的配置文件后、redis的主服务器正常启动并没有什么问题。但是当我启动redis的从服务器后,从服务器开始报错、出现下面这个问题。说从服务器连接主服务器被拒绝了。

出现这个问题是因为主服务器的bind绑定了本机ip导致。那样跨服务器ip的访问就会失效。从服务器访问主服务器的ip和端口时,主服务器发现6379端口绑定在了本机ip上,也就是说只有本机ip才能访问。外部请求会被过滤。

13469:S 31 Dec 18:10:30.472 * Connecting to MASTER hadoop01:6379
13469:S 31 Dec 18:10:30.473 * MASTER <-> SLAVE sync started
13469:S 31 Dec 18:10:30.475 # Error condition on socket for SYNC: Connection refused
13469:S 31 Dec 18:10:31.475 * Connecting to MASTER hadoop01:6379
13469:S 31 Dec 18:10:31.475 * MASTER <-> SLAVE sync started
13469:S 31 Dec 18:10:31.478 # Error condition on socket for SYNC: Connection refused
13469:S 31 Dec 18:10:32.477 * Connecting to MASTER hadoop01:6379
13469:S 31 Dec 18:10:32.477 * MASTER <-> SLAVE sync started
13469:S 31 Dec 18:10:32.481 # Error condition on socket for SYNC: Connection refused

解决方案:

修改主服务器的redis.conf配置文件中的bind配置。

#原配置
bind 127.0.0.1


#修改为
bind 0.0.0.0
#虽然说将其注释掉也可以解决上面的问题,但是不建议注释掉这个方法。因为会出现另一个问题。
#或者将其注释掉
#bind 127.0.0.1

将bind字段给注释掉也可以解决上面的问题,但是随之而来会遇到另一个问题。

出现下面这个问题有两种原因:

一个是我们没有绑定ip、另一个是我们没有配置redis密码。

1) The server is not binding explicitly to a set of addresses using the "bind" directive.

2) No password is configured.

13503:S 31 Dec 18:35:34.035 * Connecting to MASTER hadoop01:6379
13503:S 31 Dec 18:35:34.036 * MASTER <-> SLAVE sync started
13503:S 31 Dec 18:35:34.039 * Non blocking connect for SYNC fired the event.
13503:S 31 Dec 18:35:34.044 # Error condition on socket for SYNC: Connection reset by peer
13503:S 31 Dec 18:35:35.039 * Connecting to MASTER hadoop01:6379
13503:S 31 Dec 18:35:35.039 * MASTER <-> SLAVE sync started
13503:S 31 Dec 18:35:35.041 * Non blocking connect for SYNC fired the event.
13503:S 31 Dec 18:35:35.056 # Error condition on socket for SYNC: Connection reset by peer

解决方案:

第一个当然是将我们的主服务器注释掉的bind字段给放开。改成0.0.0.0。

#原配置
#bind 127.0.0.1

#修改为
bind 0.0.0.0

如果你不想将bind字段放开的话、那么你也可以将受保护模式给关闭。修改redis.conf的protected-mode为no。同样也可以解决这个问题。但是不建议方法!!!

#原配置
protected-mode yes

#修改为
protected-mode no

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值