今天在雲服務器上搭建好了redis環境,想用RedisDesktopManager工具去連接一下,結果連接不上,顯示如下圖:
我確保了服務器防火牆關閉,又在redis配置文件中設置了requirepass 密碼,但還是失敗。在自己電腦上也能夠ping通服務端ip地址。
我就看了一下redis.conf文件。開頭就有寫原因:
################################## NETWORK #####################################
# 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 這里是告訴我們可以綁定多個ip來連接redis服務端
# 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 翻譯一下大概 注意:如果redis直接暴露在互聯網,綁定所有接口是非常危險的,因此我們沒有注釋下面的綁定指令
# instance to everybody on the internet. So by default we uncomment the bind 127.0.0.1 這個相當於只綁定在服務端本地,也就是說只能在服務端連接redis,進行操作
# 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 如果你想要開放所有ip接口,注釋下面這行
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
就直接注釋bind 127.0.0.1,重啟一下讓配置生效,再進行遠程連接就ok了: