WSL 安装 Debian 12 后,Linux 如何安装 redis ?

在 WSL 的 Debian 12 上安装 Redis 的步骤如下:


1. 更新系统包列表

sudo apt update && sudo apt upgrade -y

2. 安装 Redis

sudo apt install redis-server -y

3. 启动 Redis 服务

sudo systemctl start redis

4. 设置开机自启

sudo systemctl enable redis

5. 验证 Redis 运行状态

sudo systemctl status redis

正常运行时应显示 active (running)


6. 测试 Redis 连接

redis-cli ping

若返回 PONG 表示成功。


7. 配置 Redis(可选)

编辑配置文件:

sudo nano /etc/redis/redis.conf
  • 安全建议:取消绑定本地 IP(注释 bind 127.0.0.1 ::1)或设置密码 requirepass yourpassword
  • 保存后重启服务:
    sudo systemctl restart redis
    

WSL 注意事项

  • systemd 支持:旧版 WSL 默认不启用 systemd,若上述命令报错,需手动启动 Redis:
    sudo service redis start
    
    或参考 WSL 启用 systemd 教程。

验证安装

redis-cli
127.0.0.1:6379> set test "hello"
OK
127.0.0.1:6379> get test
"hello"

卸载 Redis(备用)

sudo apt purge redis-server -y
sudo apt autoremove -y

完成以上步骤后,Redis 即可在 Debian 12 上正常运行。根据需求调整配置文件以优化性能或安全性。

你可能感兴趣的:(Linux,debian,linux,redis)