CentOS7.9 Yum 安装 Redis6.x(RPM 包,无需编译,推荐 remi 源)

CentOS7 自带 yum 源只有 redis3.2,所以必须装 remi 源才能直接 yum 装 redis6。

1. 安装 epel + remi 软件源(root 执行)

复制代码
# 安装epel依赖源
yum install -y epel-release
# 安装remi源rpm包
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# 安装yum工具
yum install -y yum-utils
# 启用remi仓库
yum-config-manager --enable remi

2. 查看可用 redis 版本(可选)

bash 复制代码
yum --showduplicates list redis

会看到 redis-6.2.14 这类 6.x 版本。

3. 直接安装 redis6.2.14

bash 复制代码
yum install -y redis-6.2.14

安装完成后:

  • 配置文件:/etc/redis.conf
  • 数据目录:/var/lib/redis
  • 日志:/var/log/redis/redis.log
  • 服务名:redis

4. 修改配置 /etc/redis.conf

bash 复制代码
# 1. 远程访问:注释bind 127.0.0.1,或者改成 bind 0.0.0.0
#bind 127.0.0.1

# 2. 设置密码(去掉#,自定义密码)
requirepass Redis@2026

# 3. 外网访问时:关闭保护模式(生产建议配合防火墙+强密码)
protected-mode no

# daemonize yes 默认yum包已经配置好后台运行

备份配置文件(好习惯)

复制代码
cp /etc/redis.conf /etc/redis.conf.bak

5. 启动 + 开机自启

bash 复制代码
systemctl start redis
systemctl enable redis
systemctl status redis

6. 防火墙放行 6379 端口(外部访问才需要)

复制代码
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload

7. 验证

bash 复制代码
redis-server --version
redis-cli
AUTH Redis@2026
PING
# 返回PONG代表成功

常用操作命令

bash 复制代码
# 重启redis
systemctl restart redis
# 停止
systemctl stop redis
# 查看日志
tail -f /var/log/redis/redis.log

卸载命令(如果装错版本)

复制代码
systemctl stop redis
yum remove -y redis
rm -rf /var/lib/redis /var/log/redis

注意事项

  1. remi 源是国外源,如果下载慢,可以替换 remi 国内镜像
  2. 生产环境不要直接 bind 0.0.0.0,最好指定业务服务器 IP,密码复杂度提高
  3. 如果后续升级 redis,直接 yum update redis 即可



相关推荐
进击的明明6 小时前
当AI开始“边想边干”:深入聊聊ReAct,以及如何用Python手搓一个简单Agent
python·面试·agent
全栈弄潮儿6 小时前
Python实战第8期:函数
后端·python·编程语言
GeW7 小时前
新质生产力路线图Linux、数据库、国产化替代一次讲透
linux
卷无止境8 小时前
暗流与破局:AI时代的代码安全审查工具全景指南
后端·python
aningx9 小时前
cachyos 从 GRUB 切换到 rEFInd
linux
第404号工位10 小时前
40块钱二手瘦客户端,如何跑满家庭物联网中枢?(拒绝Docker爆盘实录)
linux·架构·node.js
卷无止境11 小时前
一人公司的全栈选型指南:让 AI Agent 写得快,也让生意跑得稳
后端·python
骑着蜗牛撵大象32712 小时前
Linux 进程间通信之管道:从 pipe() 的内核语义到 FIFO 落地排错
android·java·linux·系统编程·fifo·管道·进程间通信
..Dauntless..12 小时前
【Linux】一切皆文件和缓冲区
linux·运维·服务器
QMCY_jason12 小时前
x86 ubuntu2204 无gui 安装 openeuler 2203 aarch64版本
linux·运维·服务器