Got timeout reading communication packets解决方法

﹏ヽ暗。殇╰゛Y 2024-03-16 21:12 137阅读 0赞
  1. Got timeout reading communication packets解决方法
  2. http://www.th7.cn/db/mysql/201702/225243.shtml
  3. [Note] Aborted connection xxxx to db:
  4. 问题现象:在tail -f/data/logs/mysql/error.log日志中出现大量的如下信息(web用的是Zabbix,设置连接超时时间为100秒):
  5. ' host: 'localhost' (Got timeout reading communication packets)
  6. 2017-02-05T15:30:19.272811+08:00 28546 [Note] Aborted connection 28546 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
  7. 2017-02-05T15:30:22.388624+08:00 28547 [Note] Aborted connection 28547 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
  8. 2017-02-05T15:30:27.119216+08:00 28554 [Note] Aborted connection 28554 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
  9. 解决办法:
  10. 修改[root@lovebuy114 ~]# grep timeout /etc/my.cnf
  11. interactive_timeout = 120
  12. wait_timeout = 120
  13. log_warnings=1 //注意,我这里原来是2。修改成1后,问题现象果然但是已经不存在了。
  14. 在命令行中可以这样修改:
  15. mysql>set global log_warning=1;
  16. mysql>set global interactive_timeout = 120;
  17. mysql>set global wait_timeout = 120;
  18. 参数简要说明:
  19. 1)interactive_timeout:
  20. 参数含义:服务器关闭交互式连接前等待活动的秒数。交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。
  21. 参数默认值:28800秒(8小时)
  22. 解决无Notice的办法:
  23. grep timeout /etc/my.cnf innodb_lock_wait_timeout = 60
  24. interactive_timeout = 28800
  25. wait_timeout = 22
  26. grep log_warnings /etc/my.cnflog_warnings=2
  27. From:http://blog.csdn.net/jamesyao008/article/details/45098073
  28. 修改后,无效,原因是现在是变成了Notice,不是警告:
  29. tail -f/data/logs/mysql/error.log
  30. 2017-02-05T15:38:19.678134+08:00 128 [Note] Aborted connection 128 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
  31. 2017-02-05T15:38:22.452504+08:00 131 [Note] Aborted connection 131 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
  32. 连接、网络类超时
  33. http://www.cnblogs.com/xiaoboluo768/p/6222862.html
  34. 共有如下几个:
  35. connect_timeout:默认为10S
  36. wait_timeout:默认是8小时,即28800秒
  37. interactive_timeout:默认是8小时,即28800秒
  38. net_read_timeout:默认是30S
  39. net_write_timeout:默认是60S
  40. handshake流程
  41. 在TCP三次握手的基础之上,简历MySQL通讯协议的连接,这个连接建立过程受connect_timeout参数控制
  42. --------------------TCP established--------------------
  43. MySQL Server(10.10.20.96)------->Client(10.10.20.51)
  44. Client(10.10.20.51)------->MySQL Server(10.10.20.96)
  45. MySQL Server(10.10.20.96)------->Client(10.10.20.51)
  46. --------------------established--------------------
  47. 在MySQL通讯协议建立连接之后,此时客户端连接的超时受wait_timeout和interactive_timeout参数控制
  48. 建立连接后无交互:MySQL server ---wait_timeout--- Client
  49. 建立连接交互后:MySQL server ---interactive_timeout--- Client
  50. 在如果客户端有数据包传输,那么这个数据包的传输超时由net_read_timeout和net_write_timeout参数控制
  51. -------------------client与server端有数据传输时-------------------
  52. client ----->MySQL Server(net_read_timeout)
  53. client <-----MySQL Server(net_write_timeout)
  54. 从上面的结果中可以看到,第一个会话中修改global wait_timeout=5之后,新的连接上来,超过5秒没有发送新的数据包,连接就被断开。
  55. net_write_timeout
  56. mysql服务端向客户端写(发送)数据时,服务端等待客户端响应的超时时间,当服务端正在写数据到客户端时,net_write_timeout控制何时超时
  57. net_read_timeout
  58. mysql服务端从客户端读取(接收)数据时,服务端等待客户端响应的超时时间,当服务端正在从客户端读取数据时,net_read_timeout控制何时超时
  59. MySQL · 答疑解惑 · MySQL 的那些网络超时错误
  60. http://mysql.taobao.org/monthly/2017/05/04/
  61. 阿里云内核月报
  62. 前言
  63. 我们在使用/运维 MySQL 过程中,经常会遇到一些网络相关的错误,比如:
  64. Aborted connection 134328328 to db: 'test' user: 'root' host: '127.0.0.1' (Got timeout reading communication packets)
  65. MySQL 的网络超时相关参数有好几个,这个超时到底是对应哪个参数呢?
  66. 在之前的月报中,我们介绍过 MySQL 的 网络通信模块 ,包括各模块间的关系,数据网络包是如何发送接受的,以及结果集的数据格式,大家可以先回顾下。
  67. 这里我们对 mysqld 处理网络包时,遇到的超时异常情况进行分析,希望大家在遇到网络相关的报错时,能更好理解和排查问题。
  68. 问题分析
  69. MySQL 是平等网络协议,就是说 client 和 server 之间的网络交互是一来一回的,client 发送完请求后,必须等待 server 响应包回来,才能发下一个请求。
  70. 对 mysqld 来说,就是接收网络请求,然后内部处理,将结果集返回给客户端,然后等待下一个请求:
  71. 先看下 mysqld server 和网络超时相关的参数有哪些:
  72. interactive_timeout
  73. wait_timeout
  74. net_read_timeout
  75. net_write_timeout
  76. connect_timeout
  77. 在底层实现上,不管是读还是写操作,超时都是通过 poll(&pfd, 1, timeout) 做的,参数之间的区别是针对连接的不同状态。
  78. 读超时
  79. wait_timeout 是给读请求用的,在 do_command 开始就做设置:
  80. my_net_set_read_timeout(net, thd->variables.net_wait_timeout);
  81. 这个时候,连接是空闲的,等待用户的请求。
  82. 等读完用户的请求包后,连接就变成 active 的,在调用 dispatch_command 执行 SQL 前,通过
  83. my_net_set_read_timeout(net, thd->variables.net_read_timeout);
  84. 把超时设置回 net_read_timeout,之后在执行 SQL 请求过程中,server 和 client 基本不会有网络交互,所以这个超时基本用不上。
  85. 有一个特殊的情况是 LOAD DATA LOCAL FILE 命令,server 在执行过程中,需要和 client 再做网络交互。
  86. interactive_timeout 是给交互模式的客户端使用的,比如我们常用的 mysql client 工具,这个是在认证过程中设置的,逻辑如下:
  87. static void
  88. server_mpvio_update_thd(THD *thd, MPVIO_EXT *mpvio)
  89. {
  90. thd->client_capabilities= mpvio->client_capabilities;
  91. thd->max_client_packet_length= mpvio->max_client_packet_length;
  92. if (mpvio->client_capabilities & CLIENT_INTERACTIVE)
  93. thd->variables.net_wait_timeout= thd->variables.net_interactive_timeout;
  94. thd->security_ctx->user= mpvio->auth_info.user_name;
  95. if (thd->client_capabilities & CLIENT_IGNORE_SPACE)
  96. thd->variables.sql_mode|= MODE_IGNORE_SPACE;
  97. }
  98. 如果客户端的能力位上设置了 CLIENT_INTERACTIVE,会用 interactive_timeout 的值覆盖 wait_timeout 的值。
  99. 而一般情况下,我们应用在建立连接时,是不会设置这个能力位的。
  100. 写超时
  101. net_write_timeout 对应写超时,在连接认证完成后,server 和 client 交互过程中写超时一真是不变的。
  102. 认证超时
  103. connect_timeout 是给连接认证过程用的,读和写都用这个值,认证完成后,读和写分别设置为 net_read_timeout 和 net_write_timeout。
  104. 总结
  105. 可以看到和读相关的超时参数是最多的,也比较容易搞混乱。
  106. 如果是认证过程中超时,不管是读还是,都是 connect_timeout;
  107. 对于读网络超时,一般是 wait_timeout/interactive_timeout,基本不会是 net_read_timeout(特例是业务用到 LOAD DATA LOCAL FILE);
  108. 对于写网络超时,都是 net_write_timeout。
  109. 在遇到超时情况下,可以根据这些原则判断对那个参数做调整。
  110. 比如下面这种情况:
  111. 2017-05-15 19:32:41 47930 [Warning] Aborted connection 6 to db: 'unconnected' user: 'root' host: 'localhost' (Got timeout reading communication packets)
  112. 很可能需要调整的 wait_timeout/interactive_timeout。
  113. 2017-05-15 20:06:27 5063 [Warning] Aborted connection 12 to db: 'test' user: 'root' host: 'localhost' (Got timeout writing communication packets)
  114. 需要调整 net_write_timeout
  115. 需要注意的是,MySQL 的关于网络的错误,除了超时以外都认为是 error,没有做进一步的细分,比如可能会看到下面这种日志,有可能是客户端异常退出了,也有可能是网络链路异常。
  116. 2017-05-15 19:34:57 47930 [Warning] Aborted connection 8 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets)
  117. 2017-05-15 20:07:39 5063 [Warning] Aborted connection 13 to db: 'test' user: 'root' host: 'localhost' (Got an error writing communication packets)

发表评论

表情:
评论列表 (有 0 条评论,137人围观)

还没有评论,来说两句吧...

相关阅读