Error condition on socket for SYNC: Connection refused

redis 主节点显示 slave数据为0

主节点:172.16.43.144:6379

# Replication
role:master
connected_slaves:0
master_replid:f70e3abf6107767212fc6991c79cdfe491ae1d34
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

查看从节点 172.16.43.143的日志文件显示如下
Error condition on socket for SYNC: Connection refused
表示redis主服务器拒绝redis从服务器的连接。这样从官方默认的配置文档redis.conf中说起。

94707:S 19 Mar 23:16:01.772 * MASTER <-> SLAVE sync started
94707:S 19 Mar 23:16:01.772 # Error condition on socket for SYNC: Connection refused
94707:S 19 Mar 23:16:02.785 * Connecting to MASTER 172.16.43.144:6379
94707:S 19 Mar 23:16:02.785 * MASTER <-> SLAVE sync started
94707:S 19 Mar 23:16:02.786 # Error condition on socket for SYNC: Connection refused
94707:S 19 Mar 23:16:03.810 * Connecting to MASTER 172.16.43.144:6379
94707:S 19 Mar 23:16:03.810 * MASTER <-> SLAVE sync started
94707:S 19 Mar 23:16:03.811 # Error condition on socket for SYNC: Connection refused
94707:S 19 Mar 23:16:04.829 * Connecting to MASTER 172.16.43.144:6379
94707:S 19 Mar 23:16:04.830 * MASTER <-> SLAVE sync started
94707:S 19 Mar 23:16:04.830 # Error condition on socket for SYNC: Connection refused
94707:S 19 Mar 23:16:05.842 * Connecting to MASTER 172.16.43.144:6379
94707:S 19 Mar 23:16:05.842 * MASTER <-> SLAVE sync started
94707:S 19 Mar 23:16:05.843 # Error condition on socket for SYNC: Connection refused
94707:S 19 Mar 23:16:06.862 * Connecting to MASTER 172.16.43.144:6379
94707:S 19 Mar 23:16:06.862 * MASTER <-> SLAVE sync started
94707:S 19 Mar 23:16:06.863 # Error condition on socket for SYNC: Connection refused

redis.conf 中 【bind】配置的用法:(一句话:bind配置了什么ip,别人就得访问bind里面配置的ip才访问到redis服务。)
redis.conf中的官方说明,bind是用于,在一台redis服务器中有多块网卡的场景下。如果不配置 “bind”,redis会监听来自宿主机器上所有网卡的请求,官方认为这是很危险的。

bind默认的是 127.0.0.1,说明只能用redis宿主机的redis-cli去访问redis,不允许网络上其他主机访问。

所以,要解决这个报错,要配置宿主机的内或外网ip(redis从服务器 能访问的到的ip)。bind xxx.xxx.xxx.xxx。这是比较推荐的做法。或者将bind 127.0.0.0 改为 bind 0.0.0.0,这配置表明接收所有网卡的请求。

你可能感兴趣的:(redis,主从配置,redis)