在 CentOS 上配置 Redis 安全,可以从网络、认证、权限、系统层面几个维度来做。下面按生产环境推荐做法说明。
Redis 配置文件一般在:
/etc/redis.conf
# 或
/etc/redis/redis.conf
bind 127.0.0.1 192.168.1.100
❌ 不要:
bind 0.0.0.0
protected-mode yes
如果 Redis 只在本地或内网使用,保持 yes。
requirepass StrongPassword123!
连接时需:
redis-cli -a StrongPassword123!
port 6379 → port 16379
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG "CONFIG_随机字符串"
rename-command KEYS ""
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="6379" accept'
firewall-cmd --reload
0.0.0.0/0useradd -r -s /sbin/nologin redis
chown -R redis:redis /var/lib/redis
chown -R redis:redis /var/log/redis
systemd 示例:
User=redis
Group=redis
适合 跨机房 / 公网
tls-port 6380
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt
如不需要 Lua:
lua-time-limit 100
logfile /var/log/redis/redis.log
slowlog-log-slower-than 10000
监控建议:
redis-cli infobind 127.0.0.1 10.0.0.5
protected-mode yes
port 6379
requirepass StrongPass!
rename-command FLUSHALL ""
rename-command CONFIG "CONFIG_abc123"
protected-mode no + 无密码如果你愿意,我可以:
你是 CentOS 几?Redis 几版本?