【问题标题】:Could not connect to Redis at 127.0.0.1:6379: Network is unreachable无法在 127.0.0.1:6379 连接到 Redis:网络无法访问
【发布时间】:2020-12-04 12:19:31
【问题描述】:

在过去的几周里,我一直在使用 WSL 2/Ubuntu 20.04 在 Windows 10 上本地使用 redis 服务器,但现在我突然无法再连接到服务器了。这是我通常在使用 wsl 2 运行 ubuntu 时打开的 linux 终端中所做的:

$ sudo service redis-server start
$ sudo service redis-server status
* redis-server running

但现在如果我尝试运行 redis-cli 命令,我会收到以下错误:

Could not connect to Redis at 127.0.0.1:6379: Network is unreachable

我已经检查了 ip 和端口使用:

$ ps aux | grep redis

返回

redis      190  0.2  0.0  51704  9796 ?        Ssl  17:12   0:00 /usr/bin/redis-server 127.0.0.1:6379

据我所知,这告诉我服务器正在 127.0.0.1:6379 运行,但我无法连接到它。 我能找到的关于此类问题的每篇文章都将错误显示为

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

而不是“网络无法访问”,所以我不确定问题是什么。

【问题讨论】:

  • 听起来你没有环回接口。检查ifconfig。您可以尝试运行sudo ifconfig lo 127.0.0.1 && sudo route add -net 127.0.0.0 来修复它,但通常操作系统会自动设置它,所以您的系统中可能还有其他问题......
  • 我尝试使用 ifconfig 但必须使用 sudo apt install net-tools 才能使用 ifconfig。安装失败。我得到的错误:E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/n/net-tools/net-tools_1.60+git20180626.aebd88e-1ubuntu1_am --- 所以我不能使用 ifconfig

标签: ubuntu redis windows-subsystem-for-linux


【解决方案1】:

问题在于防火墙设置,其 Windows 防火墙或 WSL Ubuntu 防火墙拒绝通过端口连接。

开港:

窗口:https://www.windowscentral.com/how-open-port-windows-firewall

Ubuntu (WSL):sudo ufw allow <port number>

其他 linux distor 参考:https://www.journaldev.com/34113/opening-a-port-on-linux

这解决了我的问题。

【讨论】:

  • 使用 Ubuntu WSL 命令为我工作:sudo ufw allow 6379
猜你喜欢
  • 2019-02-04
  • 2015-11-06
  • 2016-11-20
  • 2022-01-16
  • 2023-03-18
  • 2017-05-16
  • 2017-07-06
  • 2017-08-09
  • 2020-08-27
相关资源
最近更新 更多