在WSL安装redis服务并在Windows中访问

2024-03-12 91点热度 0人点赞 0条评论

原文链接

在WSL安装redis服务并在Windows中访问

在windows11上安装Linux

如何使用 WSL 在 Windows 上安装 Linux

wsl --install

安装redis

Install Redis on Windows

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

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

sudo apt-get update
sudo apt-get install redis

配置在Windows上访问WSL的Redis服务

  1. 配置Redis支持局域网访问
    修改/etc/redis/redis.conf文件:
# 注释掉下面的配置
# bind 127.0.0.1 ::1
# 修改下面的配置为no
protected-mode no

然后重启redis服务。

  1. 在windows上配置端口转发和防火墙允许入站规则
    使用管理员权限运行PowerShell并执行命令:
# 查询 WSL 2 IP 地址
PS C:\Windows\system32> wsl -- hostname -I
 172.27.163.145

# 配置端口转发:外网访问 windows 8080 端口转发到 172.19.42.138:8080
PS C:\Windows\system32> netsh interface portproxy add v4tov4 listenport=6379 connectaddress=172.27.163.145 connectport=6379

PS C:\Windows\system32> New-NetFirewallRule -DisplayName "Allow Inbound TCP Port 6379" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 6379


Name                          : {72cc921d-21b8-4cf8-b107-f725e1f81a72}
DisplayName                   : Allow Inbound TCP Port 6379
Description                   :
DisplayGroup                  :
Group                         :
Enabled                       : True
Profile                       : Any
Platform                      : {}
Direction                     : Inbound
Action                        : Allow
EdgeTraversalPolicy           : Block
LooseSourceMapping            : False
LocalOnlyMapping              : False
Owner                         :
PrimaryStatus                 : OK
Status                        : 已从存储区成功分析规则。 (65536)
EnforcementStatus             : NotApplicable
PolicyStoreSource             : PersistentStore
PolicyStoreSourceType         : Local
RemoteDynamicKeywordAddresses : {}
PolicyAppId                   :

验证

下载AnotherRedisDesktopManager进行验证https://github.com/qishibo/AnotherRedisDesktopManager/releases

王显锋

激情工作,快乐生活!

文章评论