ActiveMQ:Communications link failure问题以及解决办法

 
ActiveMQ版本:5.5.1
MQ 所使用的 MySQL 是 InnoDB存储引擎
记录人:@郑昀

现象:

业务表面现象:无。系统现象:无。
日志信息:业务系统发送 MQ 消息时,下面这种错误日志断断续续地一直都有:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
 
The last packet successfully received from the server was 60,001 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
 
原因:

ActiveMQ 持久化方案我们选的是 MySQL 。
MySQL 的全局变量 wait_timeout 默认是28800,单位是秒,即8小时。
运维部早先在测试 ActiveMQ 5.5 主从方案时,发现当 Master 宕机后,锁(数据库里的一个排他锁)有可能没有释放,导致 Slave 无法成为 Master(这是 ActiveMQ 5.5 的 BUG,已在 5.6.0和5.7.0 修复)。
所以运维部将 wait_timeout 参数调短为了60秒,希望能加速锁释放。
当业务不繁忙时,也许会有60秒既不生产也不消费,因此 MySQL 主动断开了 Connection 。此时,如果作为 MySQL Client 身份的 Broker Service,它的数据库连接池对 连接断开检测和自动重连 做得不好的话,那么 Broker 首次访问 DB 时 jdbc 就会报错。
 
短期解决办法:

将 ActiveMQ 所使用的 MySQL 的全局变量 wait_timeout 恢复为默认值 28800 。(已完成)
 
中期解决方法:
将 ActiveMQ 升级到 5.6.0或5.7.0 稳定版本。

相关的BUG:

ActiveMQ 的缺陷单 AMQ-1958 报告:

JDBC master/slave deadlock when connection is lost

影响版本: 4.1.2, 5.0.0, 5.1.0, 5.2.0
Fix版本:5.6.0
状态:2012年4月17日已修复
描述:
在一个纯 JDBC Failover 场景下(1 Master+1 Slave):如果 Master 失去了数据库网络连接,数据库里的锁将不会释放。这样 Slave 不知道 Master 已不能执行任务,Slave 仍尝试不断获取锁;当 Master 重启后,它自己也无法获得锁,于是变身为 Slave;结果就是 0 Master+2 Slave 
环境:Oracle 10,MySQL 5
(这也就是运维部在 ActiveMQ 5.5.1 测试场景所遇到的)
 
AMQ-3654 也报告类似问题:

JDBC Master/Slave : Slave cannot acquire lock when the master loose database connection

影响版本:5.5.0
Fix版本:5.7.0
状态:2012年6月13日已修复
描述:与 AMQ-3654 描述一样。只不过报告的版本号不一样。
 
 

参考资源:
1)火丁老王,MySQL里的wait_timeout
『wait_timeout 过大有弊端,其体现就是 MySQL 里大量的 SLEEP 进程无法及时释放,拖累系统性能,不过也不能把这个指设置的过小,否则你可能会遭遇到“MySQL has gone away”之类的问题。』
『在MySQL命令行里通过SET来设置即可,避免服务重启:
mysql> set global wait_timeout=60;』
『查有无生效,用 show global variables 查全局变量:
mysql> show global variables like 'wait_timeout';
单纯使用 show variables 的话就等同于使用的是 show session variables,查询的是会话变量,你会误以为设置没有生效。
4)以前有人提议在数据库连接字符串中增加autoReconnect=true&failOverReadOnly=false,但这只对 MySQL 4.0 以前的版本有效,对 MySQL 5.0 以后无效。

Master failure

If the master looses connection to the database or looses the exclusive lock then it immediately shuts down. If a master shuts down or fails, one of the other slaves will grab the lock and so the topology switches to the following diagram

6)wait_timeout 参数说明
『参数含义:服务器关闭非交互连接之前等待活动的秒数。

在线程启动时,根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值,取决于客户端类型(由mysql_real_connect()的连接选项CLIENT_INTERACTIVE定义)。

参数默认值:28800秒(8小时)』
 
本文引自:http://www.cnblogs.com/zhengyun_ustc/archive/2012/11/10/activemq_wait_timeout.html

MQ:Communications link failure的更多相关文章

  1. 解决Java程序连接mysql数据库出现CommunicationsException: Communications link failure错误的问题

    一.背景 最近在家里捣鼓一个公司自己搭建的demo的时候,发现程序一启动就会出现CommunicationsException: Communications link failure错误,经过一番排 ...

  2. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法

    09:00:30.307 [http-8080-6] ERROR org.hibernate.transaction.JDBCTransaction -JDBC begin failed com.my ...

  3. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 数据库报错

    -- 查询mysql 数据库链接空闲时间持有最大空闲时间,单位为秒 SHOW VARIABLES WHERE VAriable_name = 'interactive_timeout'; -- 会出现 ...

  4. mysql Communications link failure,C3p0的参数详解

    MySQL默认一个连接空闲8小时候就会自动断开,而这时程序以为连接还能使用,然后在使用的时候就会出现Communications link failure异常. 这时需要进行两步设置,有时候只设置My ...

  5. Communications link failure的解决办法

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications link failure,The last packet successfully r ...

  6. Communications link failure报错的处理

    一.报错的问题: 测试环境在做压力测试的时候爆出错误 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications l ...

  7. 解决MySQL连接超时Communications link failure due to underlying exception

    最近在用一个MySQL的Java连接池的过程中,连接一晚上不释放,第二天就会造成超时的错误,查了一下原因,原来是因为MySQL默认的空闲等待时间是8个小时,一旦空闲超过8个小时,就会抛出异常.异常文本 ...

  8. jdbc 连接mysql Communications link failure的解决办法

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications link failure,The last packet successfully r ...

  9. 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago

    # #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...

  10. Oozie时出现Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure?

    不多说,直接上干货! 问题详情 [hadoop@bigdatamaster oozie--cdh5.5.4]$ bin/ooziedb.sh create -sqlfile oozie.sql -ru ...

随机推荐

  1. File、Files、Path、Paths

    一.Path.Paths 和 File.Files // Paths 工具类,用于获取 Path 实例 Path path = Paths.get("files/Data.txt" ...

  2. 启动Apache出现错误Port 80 in use by "Unable to open process" with PID 4!

    22:15:30  [Apache] Problem detected! 22:15:30  [Apache] Port 80 in use by "Unable to open proce ...

  3. 基于Jenkins实现可腹部回滚的cicd平台

    Jenkins :是一个开源的实现持续集成的工具,可以实施监控持续集成过程中所存在的问题,提供详细的日志文件和提醒功能,还能用图表的形式直观的展示出项目构建的趋势和稳定性 maven:只有在Java项 ...

  4. js检测邮箱格式,正则检测邮箱格式

    网上搜了关于邮箱格式的检测,发现很多不太适用,我自己写了一个,可以检测有开头和没开头的,又可以检测@,@qq. 后的格式 var myReg=/^(\w|(\.\w+))+@([a-zA-Z0-9_- ...

  5. docker登录mysql

    一.查看mysql是否已启动 二.登录mysql 三.假如需要重启mysql 查看docker中运行的容器docker ps,再重新启动mysql,docker restart 9299415df7f ...

  6. MyBatis Plus 设置ID的自增 /非自增时遇到的问题

    非自增时 自己设置ID 其他可参考------>主键策略的几种类型 https://blog.csdn.net/hxyascx/article/details/105401767

  7. elementUI table 第一列值相等合并

    效果如下: 首先:在table上加:span-method="spanMethod" 其次: methods中加两个方法 dataPretreatment() { //表格数据列合 ...

  8. DAST精简代码

    先训练G:先不计算D的梯度: 判别器输入类型为(源域,0)或者(目标域,1),输出图片为真实图片(源域)的概率值for param in model_D.parameters(): # model_D ...

  9. 【redis-cli】常用命令

    -- 查看数据库下key存储数 redis-cli INFO | grep ^db -- 选择数据库 select [0-15] -- 列出所有key keys * -- 列出key模糊匹配 keys ...

  10. vue组件传参,父子组件以及兄弟组件(非常详细)

    一,父子组件传参. 1.首先在项目目录中新建template文件夹,里边包含父组件:List.vue以及子组件:firstComponent.vue,secondComponent.vue. 2.父组 ...