Redis主从配置异常解决:Error condition on socket for SYNC: Connection refused

来源:互联网 发布:阿里云ssl证书购买 编辑:程序博客网 时间:2024/06/06 03:29

在linux配置redis集群的时候出现了slave服务器共享不到master数据,并且slave服务器日志显示以下异常信息:

4873:S 17 Jul 04:29:20.746 # Error condition on socket for SYNC: Connection refused
4873:S 17 Jul 04:29:21.762 * Connecting to MASTER localhost:6379
4873:S 17 Jul 04:29:21.763 * MASTER <-> SLAVE sync started
4873:S 17 Jul 04:29:21.763 # Error condition on socket for SYNC: Connection refused
4873:S 17 Jul 04:29:22.778 * Connecting to MASTER localhost:6379
4873:S 17 Jul 04:29:22.779 * MASTER <-> SLAVE sync started
4873:S 17 Jul 04:29:22.779 # Error condition on socket for SYNC: Connection refused
4873:S 17 Jul 04:29:23.793 * Connecting to MASTER localhost:6379
4873:S 17 Jul 04:29:23.794 * MASTER <-> SLAVE sync started
4873:S 17 Jul 04:29:23.794 # Error condition on socket for SYNC: Connection refused
4873:S 17 Jul 04:29:24.809 * Connecting to MASTER localhost:6379
4873:S 17 Jul 04:29:24.810 * MASTER <-> SLAVE sync started
4873:S 17 Jul 04:29:24.810 # Error condition on socket for SYNC: Connection refused
4873:S 17 Jul 04:29:25.825 * Connecting to MASTER localhost:6379
4873:S 17 Jul 04:29:25.825 * MASTER <-> SLAVE sync started
4873:S 17 Jul 04:29:25.825 # Error condition on socket for SYNC: Connection refused


解决:
redis主服务器上的redis.conf中bind选项,将


bind 127.0.0.1

修改为

bind 0.0.0.0

又或者直接注释掉bind字段

# bind 127.0.0.1

原因: 
如果redis主服务器绑定了127.0.0.1,那么跨服务器IP的访问就会失败,从服务器用IP和端口访问主的时候,主服务器发现本机6379端口绑在了127.0.0.1上,也就是只能本机才能访问,外部请求会被过滤,这是Linux的网络安全策略管理的。如果bind的IP地址是172.168.10.70,那么本机通过localhost和127.0.0.1、或者直接输入命令redis-cli登录本机redis也就会失败了。只能加上本机ip才能访问到。 
所以,在研发、测试环境可以考虑bind 0.0.0.0,线上生产环境建议绑定IP地址。


阅读全文
0 0
原创粉丝点击