2 回答

TA貢獻1831條經驗 獲得超10個贊
默認情況下,Redis 不允許遠程連接。您只能從 127.0.0.1 (localhost)(運行 Redis 的計算機)連接到 Redis 服務器。
替換/etc/redis/redis.conf 文件中bind 127.0.0.1
的。bind 0.0.0.0
然后運行sudo service redis-server restart
以重新啟動服務器。
使用以下命令驗證 redis 是否正在偵聽端口 6379 上的所有接口:
ss -an | grep 6379
您應該看到如下所示的內容。0.0.0.0 表示計算機上的所有 IPv4 地址。
tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* tcp LISTEN 0 128 [::]:6379 [::]:*
如果這不能解決問題,您可能需要檢查可能阻止訪問的防火墻。

TA貢獻1804條經驗 獲得超2個贊
我遇到了類似的問題,這與地址綁定有關。在 redis 配置文件 /etc/redis/redis.conf 中,找到具有 prefix 的行bind
。通常,該行包含bind 127.0.0.1
.?這意味著,僅接受來自與 redis 服務器(在您的情況下是 redis 服務器容器)相同的主機的客戶端連接。
如果您希望接受客戶端連接,則需要在此綁定定義行中添加客戶端容器的主機名或主機 IP。
bind?127.0.0.1?<client-ip?or?client-hostname>
實現此目的的另一種方法是綁定任何地址,
bind?0.0.0.0
無論哪種情況,都需要使用更改后的 .redis 文件重新啟動 redis 服務器redis.conf
。
更新
從redis.conf文件中,我們可以看到以下內容:
# 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 loopback 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
可以看到默認的綁定地址是127.0.0.1。因此,對于您的情況,您可以指定地址或注釋該行。
- 2 回答
- 0 關注
- 304 瀏覽
添加回答
舉報