CentOS 最新系统安装 Redis 7.0.11 详细指南

CentOS 最新系统安装 Redis 7.0.11 详细指南

本文将指导您在最新的 CentOS 系统上安装 Redis 7.0.11。我们将涵盖从安装依赖项到配置和启动 Redis 服务器的所有步骤。

1. 准备工作

  • 确保您的系统是最新的:
sudo yum update -y
  • 安装必要的依赖项:
sudo yum install -y gcc make tcl

2. 下载并编译 Redis

  • 下载 Redis 7.0.11 源码包:
wget https://download.redis.io/releases/redis-7.0.11.tar.gz
  • 解压源码包:
tar xzf redis-7.0.11.tar.gz
  • 进入解压后的目录:
cd redis-7.0.11
  • 编译 Redis:
make
  • 可选:运行测试以确保编译成功:
make test
  • 安装 Redis:
sudo make install

3. 配置 Redis

  • 创建 Redis 配置文件目录:
sudo mkdir /etc/redis
  • 复制默认配置文件到新目录:
sudo cp redis.conf /etc/redis/6379.conf
  • 编辑配置文件:
sudo vi /etc/redis/6379.conf
  • 根据需要进行配置更改,例如:

    • 绑定 IP 地址:bind 127.0.0.1 更改为 bind 0.0.0.0 以允许远程连接。
    • 设置密码: 取消注释 requirepass 并设置强密码。
    • 启用持久化: 根据需要配置 save 选项或启用 AOF。

4. 创建 Redis 服务

  • 创建 Redis 服务文件:
sudo vi /etc/systemd/system/redis.service
  • 将以下内容粘贴到文件中:
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target
  • 创建 Redis 用户和组:
sudo adduser --system --group --no-create-home redis
  • 设置 Redis 目录的权限:
sudo chown -R redis:redis /etc/redis
sudo chmod -R 770 /etc/redis

5. 启动并启用 Redis 服务

  • 重新加载 systemd 配置:
sudo systemctl daemon-reload
  • 启动 Redis 服务:
sudo systemctl start redis
  • 设置 Redis 服务开机自启:
sudo systemctl enable redis

6. 验证安装

  • 检查 Redis 服务状态:
sudo systemctl status redis
  • 使用 redis-cli 连接到 Redis 服务器:
redis-cli
  • 测试 Redis 是否正常工作:
127.0.0.1:6379> ping
PONG

7. 防火墙配置 (可选)

如果启用了防火墙,需要允许 Redis 端口 (默认 6379) 的访问:

sudo firewall-cmd --permanent --add-port=6379/tcp
sudo firewall-cmd --reload

8. 安全建议

  • 使用强密码保护 Redis 实例。
  • 考虑将 Redis 绑定到特定的 IP 地址,而不是 0.0.0.0。
  • 定期备份 Redis 数据。
  • 监控 Redis 的性能和资源使用情况。

结论

恭喜!您已经在 CentOS 系统上成功安装并配置了 Redis 7.0.11。您现在可以使用 Redis 来存储和管理您的数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rockmelodies

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值