01 在 Ubuntu 中安装 Redis

在 Ubuntu 中安装 Redis

在安装之前需要切换至 root 账户!

1. 查找可用版本

1
2
3
4
5
apt search redis

# 往下翻(可能较长),大概会存在下面的字样:
redis/jammy 5:6.0.16-1ubuntu1 all
Persistent key-value database with network interface (metapackage)

2. 安装

1
2
3
4
5
apt install redis

# 看到:
Do you want to continue? [Y/n]
# 选择 y

3. 验证版本

1
redis-server --version

4. 修改配置文件

1
2
3
cd /etc/redis
ll
vim redis.conf

做以下修改:

  • bind 127.0.0.1 ::1 改成 bind 0.0.0.0 ::1
  • protected-mode yes 改成 protected-mode no

重新启动服务器生效并检查:

1
2
3
4
service redis-server restart

service redis-server status
# 看到绿色的 active (running) 即代表成功

5. 连接和退出

1
2
3
redis-cli
127.0.0.1:6379> ping
# 返回 PONG 表示成功

退出:按 Ctrl+D 或输入 exit