Docker部署的SpringCloud服务:数据库连接异常

14 篇文章 0 订阅

1 数据库连接异常

o.s.b.a.j.DataSourceHealthIndicator - DataSource health check failed
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

ERROR c.alibaba.druid.pool.DruidDataSource - create connection SQLException, url: jdbc:mysql://172.17.1.165:3306/face_recognition?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8, errorCode 0, state 08S01
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

2 查询的原因

  • 查看连接时间
mysql> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 |
+---------------+-------+

数据库连接池耗尽。

  • 最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
  • 查看连接池数量
mysql> show full processlist;
+----+------+-----------+------+---------+------+----------+-----------------------+
| Id | User | Host      | db   | Command | Time | State    | Info                  |
+----+------+-----------+------+---------+------+----------+-----------------------+
|  4 | root | localhost | NULL | Query   |    0 | starting | show full processlist |
+----+------+-----------+------+---------+------+----------+-----------------------+
  • 查看线程数
mysql> show status like 'Threads';
Empty set (0.00 sec)

3 问题再现

  • 服务器IP变更,
  • 微服务注册中心等系列服务都进行了修改
  • 并通过docker将微服务一一重启,
  • 但是,就是连接不了数据库。
    排查了一天,最后,发现是Docker内无法连接网络,因为服务器IP变更,Docker仍使用之前服务器的IP配置,所以Docker内所有的服务均无法连接网络。
  • 方案
    重启Docker,重启Docker中的所有服务即可。

[1]https://blog.csdn.net/qq_27471405/article/details/80921846?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

[2]https://blog.csdn.net/qq_40651609/article/details/86756200?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
[3]https://blog.csdn.net/qq_40651609/article/details/86756200?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
[4]https://blog.csdn.net/java1949java/article/details/94580585?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase
[5]https://blog.csdn.net/ClearLoveQ/article/details/81479001?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allfirst_rank_v2~rank_v25-5-81479001.nonecase&utm_term=08s01%20state%20数据库链接
[6]https://www.zhihu.com/question/343352928/answer/806828168
[7]https://www.cnblogs.com/niunafei/p/12824859.html
[8]https://blog.csdn.net/whxwkb/article/details/84110703
[9]http://blog.chinaunix.net/uid-20382003-id-3022768.html
[10]https://www.jb51.net/article/111531.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天然玩家

坚持才能做到极致

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值