Installation of Redis under Windows 10 (based on WSL2 installation)

在Windows上连接到WSL中的Redis,连接成功
1. Redis officially does not have native installation packages under Windows. as shown in Figure 1
Redis 官方没有 Windows 下的原生安装包
Figure 1
2. Reference:The project is no longer actively maintained. If you are looking for a Windows version of Redis, you may need to check Memurai. Please note that Microsoft does not officially recognize the product in any way. Decided to use memurai. as shown in Figure 2
参考:https://github.com/MSOpenTech/redis ,该项目不再积极维护。如果您正在寻找 Windows 版本的 Redis,您可能需要查看 Memurai。请注意,Microsoft 不以任何方式正式认可该产品。决定使用 Memurai。
Figure 2
3. After installing memurai-developer-v4.1.2.msi, restart the computer to make the environment variable take effect. 4. In the end, it was found that there was no effect, and c:program filesmemurai did not exist. Execute: C:>msiExec /quiet/i memurai.msi , still no effect. Finally decided to give up.


PS C:> msiexec /quiet /i Memurai.msi
PS C:>


5. Check port 6379 is occupied again.


PS C:> netstat -ano | findstr :6379
  TCP    192.168.89.29:63792    3.231.104.211:443      ESTABLISHED     4920


6. Reference:Install or enable WSL2 . as shown in Figure 3
安装或启用 WSL2
Figure 3


PS C:> wsl --install
正在安装: 虚拟机平台
已安装 虚拟机平台。
正在安装: 适用于 Linux 的 Windows 子系统
已安装 适用于 Linux 的 Windows 子系统。
正在安装: 适用于 Linux 的 Windows 子系统
已安装 适用于 Linux 的 Windows 子系统。
正在安装: Ubuntu
已安装 Ubuntu。
请求的操作成功。直到重新启动系统前更改将不会生效。
PS C:>


7. Install redis, enter ubuntu, and install the latest stable version of redis, packages.redis.io from the official apt repository. Add the repository to the apt index, update it, and install it. as shown in Figure 4
安装 Redis,进入 Ubuntu,从官方 APT 存储库安装 Redis 的最新稳定版本packages.redis.io。将存储库添加到apt索引,更新它,然后安装
Figure 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. Edit the configuration file of redis /etc/redis/redis.conf. To the Bind option (Bind), usually the default is binding to 127.0.0.1, and modify it to bind to all interfaces 0.0.0.0. as shown in Figure 5
编辑 Redis的配置文件 /etc/redis/redis.conf。到绑定选项(bind),通常默认是绑定到127.0.0.1,修改为绑定到所有接口 0.0.0.0
Figure 5
9. Save and close the file. Then restart the redis service for changes to take effect:


sudo service redis-server restart


10. Run ip addr in the wsl terminal to find the ip address of wsl


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. Set the authentication password for the default user, otherwise you may not be able to access Redis from the external Windows host. Then restart the service. as shown in Figure 6
为默认用户设置身份验证密码,不然可能无法从外部 Windows 主机访问 Redis。然后重启服务
Figure 6


root@DESKTOP-H4MGQIU:~# vi /etc/redis/redis.conf
root@DESKTOP-H4MGQIU:~# sudo service redis-server restart
root@DESKTOP-H4MGQIU:~#


12. Connect to Redis in WSL on Windows, the connection is successful. as shown in Figure 7
在Windows上连接到WSL中的Redis,连接成功
Figure 7

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.