在 CentOS 上,让 Redis 配置生效通常取决于你修改的是哪个配置文件以及Redis 是如何启动的。下面按常见情况说明:
常见位置:
/etc/redis.conf
/etc/redis/redis.conf
查看 Redis 实际使用的配置文件:
ps -ef | grep redis
例如:
redis-server /etc/redis.conf
vi /etc/redis.conf
常见修改示例:
bind 0.0.0.0
protected-mode no
requirepass yourpassword
maxmemory 512mb
systemctl restart redis
或
systemctl restart redis.service
确认状态:
systemctl status redis
systemctl stop redis
systemctl start redis
redis-cli
CONFIG GET bind
CONFIG GET requirepass
CONFIG GET maxmemory
适合 不能重启 的场景:
redis-cli
CONFIG SET maxmemory 512mb
CONFIG SET requirepass yourpassword
⚠️ 注意:
redis.conf如果 Redis 是通过 systemd 启动的:
✅ 必须保证:
systemctl enable redis
否则重启服务器后不会自动启动。
如果是 Docker:
docker restart redis
或修改 docker run 参数 / docker-compose.yml 后重启容器。
❌ 改了配置但没重启
❌ 改错配置文件(有多个 redis.conf)
❌ Redis 以 redis-server 直接启动,没用 systemd
❌ 配置写错导致 Redis 启动失败(看日志)
查看日志:
journalctl -u redis
或
tail -f /var/log/redis/redis.log
如果你愿意,可以告诉我:
我可以给你精确的操作步骤。