Redis 保护模式

Redis 默认开启保护模式,即 redis.conf 配置文件中的 protected-mode yes。在这种情况下,当 default 用户没有设置密码时,仅能在本地访问,远程主机无法访问 Redis;当 default 用户设置了密码时,远程主机即可访问 Redis。

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and the default user has no password, the server
# only accepts local connections from the IPv4 address (127.0.0.1), IPv6 address
# (::1) or Unix domain sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured.
protected-mode yes

设置这个参数主要是从安全性角度考虑。从安全的角度出发,仍然需要为 default 用户设置密码,或者禁用 default 用户,转而通过 ACL 新增用户并配置其权限。

实际部署时,如果发现主从复制中,从节点无法从主节点同步数据,可以检查 Redis 的 default 用户是否没有配置密码:如果未配置密码,则需要为 default 用户配置密码,或将 protected-mode 参数设置为 no。但不建议通过关闭保护模式来解决此问题。