在 CentOS 上“重置 Redis 配置”通常有两种理解,下面分别说明,你可以按需选择。
Redis 安装后通常会带一个默认配置模板。
cp /etc/redis.conf /etc/redis.conf.bak
rpm -ql redis | grep redis.conf
通常会有:
/etc/redis.conf
/usr/share/doc/redis-*/redis.conf
复制默认配置:
cp /usr/share/doc/redis-*/redis.conf /etc/redis.conf
systemctl restart redis
如果你想“从头再来”:
systemctl stop redis
rm -f /etc/redis.conf
systemctl start redis
⚠️ Redis 启动没有配置文件时,会使用内置默认值,但 CentOS 的 systemd 通常要求配置文件存在。
如果你只是想清空运行时配置(不影响文件):
redis-cli CONFIG RESETSTAT
或恢复部分默认:
redis-cli CONFIG REWRITE
CONFIG REWRITE会根据当前运行配置重写 redis.conf
如果你说的“重置”是清空数据:
redis-cli flushall
或只清当前库:
redis-cli flushdb
systemctl stop redis
yum remove redis -y
rm -rf /var/lib/redis
rm -f /etc/redis.conf
yum install redis -y
systemctl start redis
| 需求 | 命令 |
|---|---|
| 恢复默认配置 | 覆盖 /etc/redis.conf |
| 清空运行配置 | CONFIG RESETSTAT |
| 清空数据 | flushall |
| 完全重置 | 卸载重装 |
如果你能说明是 配置文件坏了 / 忘记密码 / 性能异常 / 数据异常,我可以给你更精准的步骤。