一、安装说明
redis并没有官方的windows安装包,但可以通过 Windows Subsystem for Linux(WSL) 来安装。wsl安装教程可参考666. 【windows】 win11 安装 WSL( Windows Subsystem for Linux)
二、安装
- 启动wsl;
- 执行安装命令:
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
- 启动redis
执行:
service redis-server start
三、验证安装
- 命令验证
执行:
redis-cli
四、给redis添加密码
- 将配置文件中的
protected-mode yes
改成protected-mode no
;将配置文件中的# requirepass foobared
改成requirepass yourpassword
sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis/redis.conf sed -i 's/# requirepass foobared/requirepass yourpassword/g' /etc/redis/redis.conf
- 将配置文件中的
bind 127.0.0.1 -::1
改成bind 0.0.0.0
sed -i 's/bind 127.0.0.1 -::1/bind 0.0.0.0/g' /etc/redis/redis.conf
- 重启 redis
service redis-server restart
- 再次连接数据库
redis-cli -a yourpassword
- 使用windows的客户端来连接
- 查看wsl的IP
root@FENG:/mnt# ip a 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:8c:0c:5b brd ff:ff:ff:ff:ff:ff inet 172.18.185.209/20 brd 172.18.191.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::215:5dff:fe8c:c5b/64 scope link valid_lft forever preferred_lft forever
使用windows上的AnotherRedisDesktopManager连接redis
可以看到redis版本信息了: