问题现象
用户使用 DTS 将 ECS 自建 Redis 迁移至火山引擎版 Redis,在任务配置阶段进行连接测试,显示 "连接认证失败,请检查网络是否正常"
排查步骤
通常我们会进行如下排查:
检查任务相关配置
配置源库信息,具体如下表所示,
参数 | 说明 |
---|---|
实例类型 | 选择 Redis。 |
接入方式 | 选择火山引擎 ECS 自建 Redis 或者自建 Redis |
主机地址 | 输入源自建实例的主机地址。 |
端口 | 输入源自建实例的端口号。 |
VPC | 从下拉列表中选择源实例所属的 VPC 网络。 |
数据库账号 | 输入源实例的数据库账号。 |
数据库密码 | 输入源实例数据库账号对应的密码。 |
需要注意如下配置:
- 如果选择 ECS 自建 Redis,需要确保使用的主机地址为**私网地址,且 VPC 必须选择 ECS 所在 VPC **
- 确保安全组放行了 DTS 的网段,保证网络连通性
请勿建议用户添加 0.0.0.0/0,暴露在公网上可能有被攻击的风险
检查是否开启了保护模式
在自建 Redis 上检查是否开启了保护模式
127.0.0.1:6379> config get protected-mode
开启保护模式后,会出现如下报错:
failed: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified
检查 bind 参数
在确认没有开启保护模式后,我们还需要检查 bind 参数,检查输出参数是否为 127.0.0.1。
127.0.0.1:6379> config get bind
1) "bind"
2) "127.0.0.1"
解决方案
确保网络连通性正常
当源库、目标库部署在火山引擎的 ECS 中通过私网连接,且开启了访问限制时,您需要在 ECS 的安全组规则中添加 DTS 服务器的 IP 地址。
确保关闭保护模式
可以使用如下命令来关闭保护模式,当开启保护模式后,实例只允许来自本地的连接。
127.0.0.1:6379> config set protected-mode no
参数说明如下:
The server only accepts connections from clients connecting from the IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from 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, nor a specific set of interfaces are explicitly listed using the "bind" directive.
修改 bind 参数
如果 Redis 实例的 bind 参数设置为 127.0.0.1,意味着只允许来自本地的连接,其他远程连接访问 Redis 会被拒绝,在 Redis 配置文件中修改 bind 参数如下所示
bind 127.0.0.1
因此在修改配置文件之前,需要仔细了解每个配置参数的含义和作用,并谨慎地进行修改
参考文档
[1] https://redis.io/docs/management/security/#protected-mode [2] https://redis.io/docs/management/security/ [3] https://redis.io/docs/management/config-file/