温馨提示×

centos redis配置怎样查配置项

小樊
34
2026-10-05 19:45:21
栏目: 云计算

在 CentOS 上查看 Redis 配置项 一般有几种常用方式,下面按使用场景给你总结一下。


一、通过 redis-cli 查看(推荐)

1️⃣ 查看所有配置项

redis-cli CONFIG GET *

2️⃣ 查看某个具体配置项

例如查看 maxmemory:

redis-cli CONFIG GET maxmemory

常见示例:

redis-cli CONFIG GET port
redis-cli CONFIG GET bind
redis-cli CONFIG GET requirepass
redis-cli CONFIG GET maxmemory-policy

⚠️ 如果 Redis 有密码:

redis-cli -a yourpassword CONFIG GET *

二、查看 Redis 配置文件(centos 常见路径)

1️⃣ 常见配置文件位置

/etc/redis.conf
# 或
/etc/redis/redis.conf

查看配置:

cat /etc/redis.conf

搜索某项配置:

grep maxmemory /etc/redis.conf
grep bind /etc/redis.conf

三、查看 Redis 启动时使用的配置文件

1️⃣ 查看 Redis 进程

ps -ef | grep redis

示例输出:

redis    1234  1  0 10:00 ?  00:00:01 /usr/bin/redis-server /etc/redis.conf

说明当前使用的是 /etc/redis.conf


四、运行时临时修改并查看(不写文件)

redis-cli CONFIG SET maxmemory 2gb
redis-cli CONFIG GET maxmemory

⚠️ 这种修改 重启后失效


五、确认 Redis 是否开机自启 & 服务名(CentOS 7+)

systemctl status redis
systemctl status redis-server

六、常见易查配置项速查

配置项 说明
port 端口
bind 绑定 IP
requirepass 密码
maxmemory 最大内存
maxmemory-policy 内存淘汰策略
appendonly 是否 AOF
save RDB 快照
daemonize 是否后台运行

如果你愿意,可以告诉我:

  • Redis 版本
  • 是否用 yum / 源码安装
  • 想查哪个具体配置

我可以直接给你对应命令。

0 踩