Ubuntu20 WSL 安装Redis 报错Connection refused
Posted ponponon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu20 WSL 安装Redis 报错Connection refused相关的知识,希望对你有一定的参考价值。
本来想在windows
上安装一个Redis
,但是发现官方都没有提供预编译好的二进制发行版本,这就很让人头疼了。
那就想着在WSL
上安装吧,美滋滋。
在Ubuntu20.04 WSL
上安装redis
有两种方式:
- 使用
apt
包管理器 - 自行编译源代码
先说第一种办法,通过apt
包管理器安装Redis
是最方便的
只需如下两行命令即可
sudo apt update
sudo apt install redis-server
但是实际上不行,你会发现一些错误:
csy@Yoga14S-yjc:~$ systemctl status redis-server
System has not been booted with systemd as init system (PID 1). Can\'t operate.
Failed to connect to bus: Host is down
以及
csy@Yoga14S-yjc:~$ redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
not connected>
not connected>
not connected>
not connected>
not connected> dsa
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
这就很麻烦,为了解决Connection refused
错误
可以执行一下命令
sudo service redis-server start
这是便可以正常使用redis-cli
了
csy@Yoga14S-yjc:~$ redis-cli
127.0.0.1:6379> exit
但是输入systemctl status redis-server
查看redis-server的运行状态还是不行
但是通过service
命令是可以的。
csy@Yoga14S-yjc:~$ sudo service redis-server status
* redis-server is running
关于service
和systemctl
的区别可以参考这篇文章Linux 服务管理两种方式service和systemctl
关于为什么service
可以而systemctl
不可以,参考这篇文章修复 "System has not been booted with systemd as init system "的错误。你就会知道答案。
以上是关于Ubuntu20 WSL 安装Redis 报错Connection refused的主要内容,如果未能解决你的问题,请参考以下文章
Windows10/Windows11 子系统(WSL2)安装Ubuntu20.04
Windows11 WSL 打开Ubuntu 报错 WslRegisterDistribution failed with error: 0x800701bc
windows11系统WSL2安装ubuntu20.04桌面