1. 程式人生 > >配置redis主從伺服器,slave伺服器日誌顯示Error condition on socket for SYNC: Connection refused

配置redis主從伺服器,slave伺服器日誌顯示Error condition on socket for SYNC: Connection refused

Error condition on socket for SYNC: Connection refused,表示redis主伺服器拒絕redis從伺服器的連線。這樣從官方預設的配置文件redis.conf中說起。

redis.conf 中 【bind】配置的用法:(一句話:bind配置了什麼ip,別人就得訪問bind裡面配置的ip才訪問到redis服務。

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

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,這配置表明接收所有網絡卡的請求。

若bind 內/外網ip,預設的 127.0.0.1會失效。用redis客戶端訪問本臺主機時 要加ip地址。( redis-cli -h xxx.xxx.xxx.xxx)。不知是否跟版本有關,本人用的redis版本是4.0.11.

參考文章