在 CentOS 上设置(安装并配置)Redis,一般分为 安装 → 配置 → 启动 → 开机自启 → 验证 这几步。下面给你一套 最常用、可直接照做 的流程(适用于 CentOS 7 / 8 / Stream)。
yum install -y epel-release
yum install -y redis
dnf install -y redis
安装完成后查看版本:
redis-server --version
Redis 默认配置文件在:
/etc/redis.conf
编辑配置文件:
vim /etc/redis.conf
bind 0.0.0.0
⚠️ 生产环境建议只绑定内网 IP,不要直接
0.0.0.0
requirepass your_password
daemonize yes
maxmemory 512mb
maxmemory-policy allkeys-lru
systemctl start redis
systemctl status redis
systemctl enable redis
redis-cli
如果设置了密码:
auth your_password
测试:
ping
# 返回 PONG
Redis 默认端口:6379
firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --reload
查看日志:
journalctl -u redis
检查:
bind 配置yum remove redis
rm -rf /var/lib/redis
rm -rf /etc/redis.conf
# 安装
yum install -y redis
# 配置
vim /etc/redis.conf
# 启动
systemctl start redis
systemctl enable redis
# 测试
redis-cli
如果你需要:
告诉我你的 CentOS 版本和使用场景,我可以给你更精确的方案。