下面给你在 CentOS 上修改 Redis 配置的完整常见做法,按使用场景从“最常见”到“进阶”说明。
CentOS 下常见路径:
/etc/redis.conf
或(如果是源码安装):
/usr/local/redis/redis.conf
确认 Redis 正在使用的配置文件:
ps -ef | grep redis
vim /etc/redis.conf
常见需要修改的配置项:
bind 0.0.0.0
⚠️ 生产环境建议只绑定指定 IP,不要直接 0.0.0.0
requirepass your_password
port 6379
daemonize yes
dir /var/lib/redis
:wq
systemctl restart redis
systemctl status redis
service redis restart
进入 Redis CLI:
redis-cli
临时修改(重启失效):
CONFIG SET requirepass "123456"
CONFIG SET maxmemory 512mb
CONFIG GET maxmemory
查看当前配置:
CONFIG GET *
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload
redis-server /etc/redis.conf --port 6380
✅ 检查:
redis-server /etc/redis.conf
是否真的在用这个配置文件
✅ 检查:
bind 0.0.0.0protected-mode nobindmaxmemory如果你愿意,可以告诉我:
我可以给你精确到命令级别的修改方案。