温馨提示×

centos怎么改redis配置文件

小樊
48
2026-10-26 09:41:54
栏目: 云计算

在 CentOS 上修改 Redis 配置文件,一般按下面步骤来即可:


一、找到 Redis 配置文件

Redis 默认配置文件通常是:

/etc/redis.conf

或者(如果是源码编译或某些版本):

/etc/redis/redis.conf

你可以先确认一下:

rpm -ql redis | grep redis.conf

或

find / -name redis.conf

二、备份配置文件(推荐)

修改前先备份,防止改错:

cp /etc/redis.conf /etc/redis.conf.bak

三、编辑配置文件

使用 vi 或 vim 编辑:

vi /etc/redis.conf

常见修改项示例:

1️⃣ 修改监听地址(允许远程访问)

bind 0.0.0.0

⚠️ 生产环境建议绑定具体 IP,并配合防火墙

2️⃣ 关闭保护模式

protected-mode no

3️⃣ 修改端口

port 6379

4️⃣ 设置密码

requirepass yourpassword

5️⃣ 允许后台运行

daemonize yes

四、保存退出

在 vi 中:

Esc
:wq

五、重启 Redis 使配置生效

CentOS 7 / 8(systemd)

systemctl restart redis

或

systemctl restart redis.service

查看状态:

systemctl status redis

六、验证配置是否生效

redis-cli

如果设了密码:

redis-cli -a yourpassword

查看配置:

CONFIG GET bind
CONFIG GET requirepass

七、常见问题

❌ 改了配置不生效?

  • 确认重启的是 正确的 redis 实例
  • 检查是否用了 redis-server 手动启动,而非 systemd
  • 查看日志:
journalctl -u redis

如果你能告诉我:

  • CentOS 版本(6 / 7 / 8 / Stream)
  • Redis 安装方式(yum / 编译)
  • 想改哪一项配置

我可以直接给你精确命令。

0 踩