无法在 127.0.0.1:6379 连接到 Redis:连接被拒绝

Could not connect to Redis at 127.0.0.1:6379: Connection refused

在ubuntu 16.4 in digitalocean中安装了一个redis。

我已经通过编辑vim /etc/redis/redis.conf

将默认的redis服务器127.0.0.1:6379更改为我在digitalocean178.xxx.xxx.xxx:6379中自己的ip

之后我试了 redis-cliredis-cli shutdown 都回复了这个: 无法在 127.0.0.1:6379 连接到 Redis:连接被拒绝

但是如果ps aux|grep redis

我得到:

redis    11734  0.0  0.1  41852  3892 ?        Ssl  15:45   0:11 /usr/local/bin/redis-server 178.xxx.xxx.xxx:6379
root     12735  0.0  0.0  12944   948 pts/0    S+   19:11   0:00 grep --color=auto redis

这正常吗?或者我该怎么办?

您应该做什么取决于您希望它如何工作...


如果您希望能够通过任何网络接口连接到 Redis,请在配置文件中注释掉所有 bind 指令,方法是在行首 # =12=].


如果您只想通过指定 178.xxx.xxx.xxx 进行连接,请将以下内容放入您的配置文件中:

bind 178.xxx.xxx.xxx

如果要使用 127.0.0.1 或 178.xxx.xxx.xxx,则输入:

bind 178.xxx.xxx.xxx 127.0.0.1

我猜你想要这个选项,但请参阅下面的安全说明。


一般来说,从安全的角度来看,将您的 Redis 服务器暴露给整个 Internet 是不可取的 - 上面的所有选项都可以做到这一点。您可能想绑定到 127.0.0.1 并设置从您的 178.xxx.xxx.xxx public 地址到 127.0.0.1.

ssh 隧道

无论你在那里输入什么,重启 Redis 以使更改生效。