Windows 10 下 Redis 的安装(基于 WSL2 安装)
1、Redis 官方没有 Windows 下的原生安装包。如图1
2、参考:该项目不再积极维护。如果您正在寻找 Windows 版本的 Redis,您可能需要查看 Memurai。请注意,Microsoft 不以任何方式正式认可该产品。决定使用 Memurai。如图2
3、安装 Memurai-Developer-v4.1.2.msi 完毕后,重启电脑,以使环境变量生效。
4、最后发现没有效果,C:\Program Files\Memurai 不存在。执行:C:\>msiexec /quiet /i Memurai.msi 后,仍然没有效果。最终决定放弃。
PS C:\> msiexec /quiet /i Memurai.msi PS C:\>
5、查看端口 6379 又是被占用了的。
PS C:\> netstat -ano | findstr :6379 TCP 192.168.89.29:63792 3.231.104.211:443 ESTABLISHED 4920
6、参考:安装或启用 WSL2 。如图3
PS C:\> wsl --install 正在安装: 虚拟机平台 已安装 虚拟机平台。 正在安装: 适用于 Linux 的 Windows 子系统 已安装 适用于 Linux 的 Windows 子系统。 正在安装: 适用于 Linux 的 Windows 子系统 已安装 适用于 Linux 的 Windows 子系统。 正在安装: Ubuntu 已安装 Ubuntu。 请求的操作成功。直到重新启动系统前更改将不会生效。 PS C:\>
7、安装 Redis,进入 Ubuntu,从官方 APT 存储库安装 Redis 的最新稳定版本packages.redis.io。将存储库添加到apt索引,更新它,然后安装。如图4
root@DESKTOP-H4MGQIU:~# curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg root@DESKTOP-H4MGQIU:~# echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb jammy main root@DESKTOP-H4MGQIU:~# sudo apt-get update Get:1 https://packages.redis.io/deb jammy InRelease [3821 B] Get:2 https://packages.redis.io/deb jammy/main all Packages [4502 B] Get:3 https://packages.redis.io/deb jammy/main amd64 Packages [21.2 kB] Hit:4 http://archive.ubuntu.com/ubuntu jammy InRelease Get:5 http://security.ubuntu.com/ubuntu jammy-security InRelease [129 kB] Get:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB] Get:7 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [1673 kB] Get:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [127 kB] Get:9 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [14.1 MB] Get:10 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [279 kB] Get:11 http://security.ubuntu.com/ubuntu jammy-security/main amd64 c-n-f Metadata [13.0 kB] Get:12 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [2171 kB] Get:13 http://security.ubuntu.com/ubuntu jammy-security/restricted Translation-en [372 kB] Get:14 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 c-n-f Metadata [572 B] Get:15 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [886 kB] Get:16 http://security.ubuntu.com/ubuntu jammy-security/universe Translation-en [173 kB] Get:17 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 c-n-f Metadata [18.9 kB] Get:18 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [37.2 kB] Get:19 http://security.ubuntu.com/ubuntu jammy-security/multiverse Translation-en [7588 B] Get:20 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 c-n-f Metadata [228 B] Get:21 http://archive.ubuntu.com/ubuntu jammy/universe Translation-en [5652 kB] Get:22 http://archive.ubuntu.com/ubuntu jammy/universe amd64 c-n-f Metadata [286 kB] Get:23 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [217 kB] Get:24 http://archive.ubuntu.com/ubuntu jammy/multiverse Translation-en [112 kB] Get:25 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 c-n-f Metadata [8372 B] Get:26 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1888 kB] Get:27 http://archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [337 kB] Get:28 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 c-n-f Metadata [17.7 kB] Get:29 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [2238 kB] Get:30 http://archive.ubuntu.com/ubuntu jammy-updates/restricted Translation-en [384 kB] Get:31 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 c-n-f Metadata [604 B] Get:32 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1108 kB] Get:33 http://archive.ubuntu.com/ubuntu jammy-updates/universe Translation-en [258 kB] Get:34 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 c-n-f Metadata [25.4 kB] Get:35 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [43.3 kB] Get:36 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse Translation-en [10.8 kB] Get:37 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 c-n-f Metadata [444 B] Get:38 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [67.1 kB] Get:39 http://archive.ubuntu.com/ubuntu jammy-backports/main Translation-en [11.0 kB] Get:40 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 c-n-f Metadata [388 B] Get:41 http://archive.ubuntu.com/ubuntu jammy-backports/restricted amd64 c-n-f Metadata [116 B] Get:42 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [28.8 kB] Get:43 http://archive.ubuntu.com/ubuntu jammy-backports/universe Translation-en [16.5 kB] Get:44 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 c-n-f Metadata [672 B] Get:45 http://archive.ubuntu.com/ubuntu jammy-backports/multiverse amd64 c-n-f Metadata [116 B] Fetched 32.8 MB in 19s (1686 kB/s) Reading package lists... Done root@DESKTOP-H4MGQIU:~# sudo apt-get install redis Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: redis-server redis-tools Suggested packages: ruby-redis The following NEW packages will be installed: redis redis-server redis-tools 0 upgraded, 3 newly installed, 0 to remove and 112 not upgraded. Need to get 1726 kB of archives. After this operation, 9790 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 https://packages.redis.io/deb jammy/main amd64 redis-tools amd64 6:7.2.5-1rl1~jammy1 [1610 kB] Get:2 https://packages.redis.io/deb jammy/main amd64 redis-server amd64 6:7.2.5-1rl1~jammy1 [82.3 kB] Get:3 https://packages.redis.io/deb jammy/main amd64 redis all 6:7.2.5-1rl1~jammy1 [33.9 kB] Fetched 1726 kB in 4s (493 kB/s) Selecting previously unselected package redis-tools. (Reading database ... 24208 files and directories currently installed.) Preparing to unpack .../redis-tools_6%3a7.2.5-1rl1~jammy1_amd64.deb ... Unpacking redis-tools (6:7.2.5-1rl1~jammy1) ... Selecting previously unselected package redis-server. Preparing to unpack .../redis-server_6%3a7.2.5-1rl1~jammy1_amd64.deb ... Unpacking redis-server (6:7.2.5-1rl1~jammy1) ... Selecting previously unselected package redis. Preparing to unpack .../redis_6%3a7.2.5-1rl1~jammy1_all.deb ... Unpacking redis (6:7.2.5-1rl1~jammy1) ... Setting up redis-tools (6:7.2.5-1rl1~jammy1) ... Setting up redis-server (6:7.2.5-1rl1~jammy1) ... Setting up redis (6:7.2.5-1rl1~jammy1) ... Processing triggers for man-db (2.10.2-1) ... root@DESKTOP-H4MGQIU:~#
8、编辑 Redis的配置文件 /etc/redis/redis.conf。到绑定选项(bind),通常默认是绑定到127.0.0.1,修改为绑定到所有接口 0.0.0.0。如图5
9、保存并关闭文件。然后重新启动Redis服务以使更改生效:
sudo service redis-server restart
10、在WSL终端中运行 ip addr来查找WSL的IP地址
root@DESKTOP-H4MGQIU:~# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:15:5d:7b:2d:f2 brd ff:ff:ff:ff:ff:ff inet 172.24.155.141/20 brd 172.24.159.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::215:5dff:fe7b:2df2/64 scope link valid_lft forever preferred_lft forever root@DESKTOP-H4MGQIU:~#
11、为默认用户设置身份验证密码,不然可能无法从外部 Windows 主机访问 Redis。然后重启服务。如图6
root@DESKTOP-H4MGQIU:~# vi /etc/redis/redis.conf root@DESKTOP-H4MGQIU:~# sudo service redis-server restart root@DESKTOP-H4MGQIU:~#
12、在Windows上连接到WSL中的Redis,连接成功。如图7
近期评论