以下是根据前面的沟通记录整理的完整安装过程和依赖项,确保在 Ubuntu 22 上成功安装 Redis 5.0.8。
安装 Redis 5.0.8 的完整步骤
1. 安装依赖
在编译和运行 Redis 之前,需要安装一些必要的工具和库:
sudo apt update
sudo apt install build-essential tcl gcc make
build-essential
:包含编译工具链(如gcc
和make
)。tcl
:用于运行 Redis 的测试。gcc
和make
:用于编译 Redis。
2. 下载 Redis 5.0.8 源码
从 Redis 官方网站下载 Redis 5.0.8 的源码包:
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
3. 解压并进入目录
解压下载的文件,并进入解压后的目录:
tar -xzvf redis-5.0.8.tar.gz
cd redis-5.0.8
4. 编译 Redis
运行以下命令编译 Redis:
make
如果编译过程中没有报错,可以运行以下命令进行测试:
make test
5. 安装 Redis
将 Redis 安装到系统中:
sudo make install
6. 配置 Redis
复制默认配置文件到 /etc
目录,并根据需要进行修改:
cp redis.conf /etc/redis.conf
nano /etc/redis.conf
建议修改以下配置:
- 后台启动:将
daemonize no
修改为daemonize yes
。 - 允许远程连接:注释掉
bind 127.0.0.1
。 - 关闭保护模式:将
protected-mode yes
修改为protected-mode no
。
7. 启动 Redis 服务
使用以下命令启动 Redis 服务:
redis-server /etc/redis.conf
8. 测试 Redis
通过 redis-cli
测试 Redis 是否正常工作:
redis-cli ping
如果返回 PONG
,则表示 Redis 安装成功。
9. 设置开机自启(可选)
如果需要 Redis 在系统启动时自动运行,可以将其添加为 systemd 服务:
- 创建 Redis 服务文件:
sudo nano /etc/systemd/system/redis.service
- 添加以下内容:
[Unit] Description=Redis In-Memory Data Store After=network.target [Service] ExecStart=/usr/local/bin/redis-server /etc/redis.conf ExecStop=/usr/local/bin/redis-cli shutdown Restart=always [Install] WantedBy=multi-user.target
- 启用并启动 Redis 服务:
sudo systemctl enable redis sudo systemctl start redis
总结
通过以上步骤,你可以在 Ubuntu 22 上成功安装 Redis 5.0.8。以下是安装过程中需要的依赖项和工具:
- 依赖项:
build-essential
:包含编译工具链。tcl
:用于运行 Redis 的测试。gcc
:C 语言编译器。make
:用于构建和安装 Redis。