在 CentOS 上修改 Redis 配置,通常分为 修改配置文件 和 重启/重载 Redis 两部分。下面按常见场景说明。
一般位置(取决于安装方式):
# YUM 安装(常见)
/etc/redis.conf
# 编译安装
/usr/local/redis/redis.conf
查看 Redis 实际使用的配置:
redis-cli config get dir
ps -ef | grep redis
编辑配置文件:
vi /etc/redis.conf
bind 0.0.0.0
# 或注释掉 bind
# bind 127.0.0.1
⚠️ 生产环境建议配合防火墙和密码
requirepass yourpassword
修改后登录:
redis-cli -a yourpassword
port 6379
appendonly yes
maxmemory 2gb
maxmemory-policy allkeys-lru
daemonize yes
# systemd(CentOS 7+)
systemctl restart redis
# 或
systemctl restart redis.service
查看状态:
systemctl status redis
redis-cli
CONFIG SET requirepass "newpass"
CONFIG REWRITE
⚠️ CONFIG REWRITE 会写回配置文件(部分版本支持)
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
redis-cli
CONFIG GET *
如果你能说明:
我可以给你 更精确的命令。