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 上正常运行。根据需求调整配置文件以优化性能或安全性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值