天天看点

mysql测试连接失败_MySQL docker 远程无法连接错误排查

现象

用 docker 起了一个 MySQL 数据库用作测试,环境起好了,远程连接时发现连接失败。

MySQL container正常运行,docker端口已暴露,两台服务器之间互相ping得通

错误排查

Step 1. Telnet

使用 telnet 测试远程ip及端口能否正常通信:telnet 10.23.*.*  3306

得到结果:Trying 10.23.*.*  ...

telnet: connect to address 10.23.*.*: Operation timed out

telnet: Unable to connect to remote host

结论: 远程ip及端口通信失败

Step 2. 检查服务器本地防火墙systemctl  status firewalld

得到结果,防火墙已关闭。

若为防火墙原因,可关闭防火墙后尝试: systemctl  stop firewalld

Step 3. 检查本地端口监听

使用netstat检查本地端口监听情况netstat -nlt  | grep 3306

得到结果:

mysql测试连接失败_MySQL docker 远程无法连接错误排查

端口已监听,使用IPv6

Step 4. 检查本地Ipv6设置

检查本地IPv6设置:sysctl net.ipv6.conf.all.forwarding

得到结果:net.ipv6.conf.all.forwarding = 0

修改 IPv6 设置:sysctl net.ipv6.conf.all.forwarding=1

重启docker服务systemctl restart docker

Step 5. 重新测试连接

连接成功