当前位置: 移动技术网 > IT编程>数据库>Mysql > 通过案例分析MySQL中令人头疼的Aborted告警

通过案例分析MySQL中令人头疼的Aborted告警

2017年12月07日  | 移动技术网IT编程  | 我要评论

双人体艺术,水泥试验仪器,8xoy改成什么了

本文主要给大家介绍的是关于mysql中aborted告警的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍:

实战

part1:写在最前

在mysql的error log中,我们会经常性看到一些各类的aborted connection错误,本文中会针对这类错误进行一个初步分析,并了解一个问题产生后的基本排查思路和方法。掌握这种方法是至关重要的,而不是出现问题了,去猜,去试。数据库出现问题的时候需要dba在短时间内快速解决问题,因此一个好与坏的dba,区别也在于此。

part2:种类

[warning] aborted connection 305628 to db: 'db' user: 'dbuser' host: 'hostname' (got an error reading communication packets)
[warning] aborted connection 81 to db:'unconnected' user: 'root' host: '127.0.0.1' (got timeout reading communication
packets)
[warning] aborted connection 109 to db:'helei1' user: 'sys_admin' host: '192.168.1.1' (got an error writing communication packets)
[warning] access denied for user 'root'@'127.0.0.1' (using password: yes)
[warning] got an error writing communication packets

part3:重点参数分析

wait_timeout

command-line format --wait-timeout=#
system variable name wait_timeout
variable scope global, session
dynamic variable yes
permitted values (windows) type integer
default 28800
min value 1
max value 2147483
permitted values (other) type integer
default 28800
min value 1
max value 31536000

这个参数指的是数据库系统在关闭它之前,服务器等待非交互式连接上的活动的秒数。

interactive_timeout

command-line format --interactive-timeout=#
system variable name interactive_timeout
variable scope global, session
dynamic variable yes
permitted values type integer
default 28800
min value 1

这个参数指的是在关闭交互式连接之前,服务器等待活动的秒数

warning:警告这两个参数建议一起调节,能够避免一些坑。

本文的两个参数值采用的是默认值

mysql> show global variables like '%timeout%';
+----------------------------+----------+
| variable_name    | value |
+----------------------------+----------+
| connect_timeout   | 10  |
| delayed_insert_timeout  | 300  |
| innodb_lock_wait_timeout | 50  |
| innodb_rollback_on_timeout | off  |
|interactive_timeout  | 28800 |
| lock_wait_timeout   | 31536000 |
| net_read_timeout   | 30  |
| net_write_timeout   | 60  |
| slave_net_timeout   | 3600  |
|wait_timeout    | 28800 |
+----------------------------+----------+
10 rows in set (0.01 sec)

另外在数据库中,我们重点关注下这两个参数,看看什么情况下aborted_clients会提升,什么情况下aborted_connects 会提升

mysql>show global status like 'aborted%';
+------------------+-------+
|variable_name | value |
+------------------+-------+
|aborted_clients | 19 |
|aborted_connects | 0  |
+------------------+-------+
2 rows inset (0.00 sec)

part4:案例1

这里我故意输入错误的密码5次,来看下数据库的error log和aborted的哪个参数记载了这一问题

[root@he3~]# mysql -uroot -pwrongpass -h127.0.0.1
error 1045 (28000): access denied for user 'root'@'127.0.0.1' (using password: yes)
[root@he3~]# mysql -uroot -pwrongpass -h127.0.0.1
error 1045 (28000): access denied for user 'root'@'127.0.0.1' (using password: yes)
[root@he3~]# mysql -uroot -pwrongpass -h127.0.0.1
error 1045 (28000): access denied for user 'root'@'127.0.0.1' (using password: yes)
[root@he3~]# mysql -uroot -pwrongpass -h127.0.0.1
error 1045 (28000): access denied for user 'root'@'127.0.0.1' (using password: yes)
[root@he3~]# mysql -uroot -pwrongpass -h127.0.0.1
error 1045 (28000): access denied for user 'root'@'127.0.0.1' (using password: yes)

可以看出,这里的aborted_connects 记录了密码错误的这一问题

mysql>show global status like 'aborted%';
+------------------+-------+
|variable_name | value |
+------------------+-------+
|aborted_clients | 19 |
|aborted_connects | 5  |
+------------------+-------+
2 rows inset (0.00 sec)

error log中,也记载了这类密码输错的信息

[warning] access denied for user'root'@'127.0.0.1' (using password: yes)
[warning] access denied for user 'root'@'127.0.0.1' (using password:yes)
[warning] access denied for user 'root'@'127.0.0.1' (using password:yes)
[warning] access denied for user 'root'@'127.0.0.1' (using password:yes)
[warning] access denied for user 'root'@'127.0.0.1' (using password:yes)

part5:案例2

接下来我们看下文章第三节提到的两个重点参数对数据库连接的行为影响

这里我们将这两个参数均配置为10秒

mysql>set global wait_timeout=10;
query ok,0 rows affected (0.00 sec)
 
mysql>set global interactive_timeout=10;
query ok,0 rows affected (0.00 sec)
mysql>show processlist;
error 2006 (hy000): mysql server has gone away
no connection. trying to reconnect... connection id: 79 current database: *** none ***
 
+----+------+-----------------+------+---------+------+-------+------------------+
| id |user | host   | db | command | time | state | info    |
+----+------+-----------------+------+---------+------+-------+------------------+
| 79 |root | 127.0.0.1:42016 | null | query | 0 | null | show processlist |
+----+------+-----------------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)

这里三次操作,可以看到clients数上升,这是由于timeout参数控制的,已经连接上数据的连接被杀掉。

mysql>show global status like 'aborted%';
error 2006 (hy000): mysql server has gone away
no connection. trying to reconnect... connection id: 81 current database: *** none ***
 
+------------------+-------+
|variable_name | value |
+------------------+-------+
|aborted_clients | 22 |
|aborted_connects | 5  |
+------------------+-------+
2 rows in set (0.01 sec)

error log中记载的是

[warning] aborted connection 81 to db: 'unconnected' user: 'root' host: '127.0.0.1' (got timeout reading communication packets)
[warning] aborted connection 78 to db: 'unconnected' user: 'root' host: '127.0.0.1' (got timeout reading communication packets) 
[warning] aborted connection 79 to db: 'unconnected' user: 'root' host: '127.0.0.1' (got timeout reading communication packets)

part6:案例3

在这个案例中我们看下最大连接数对数据库连接的行为影响

mysql>show global variables like 'max_conn%';
+--------------------+-------+
|variable_name  | value |
+--------------------+-------+
|max_connect_errors | 1000 |
|max_connections | 1024 |
+--------------------+-------+
2 rows in set (0.00 sec)
 
 
mysql>set global max_connections=2;
query ok,0 rows affected (0.00 sec)

这里看到爆出了连接数过多的问题

[root@he3~]# mysql -uroot -pmanager -h127.0.0.1
error 1040 (hy000): too many connections

而错误日志没有任何记录

part7:案例4

第三方工具navicat select结果没有出来的时候选择停止则出现

clients上涨

mysql>show global status like 'aborted%';
+------------------+-------+
|variable_name | value |
+------------------+-------+
|aborted_clients | 28 |
|aborted_connects | 10 |
+------------------+-------+
2 rows in set (0.00 sec)

error log日志记录

170626 16:26:56 [warning] aborted connection 109 to db: 'helei1' user: 'sys_admin' host: '192.168.1.1' (got an error writing communication packets)

part8:原因总结

  1. 在mysql中sleep状态数百秒的而且经常重复连接是应用程序在工作后没有关闭连接的症状之一,而是依靠数据库wait_timeout来关闭它们。强烈建议在操作结束时更改应用程序逻辑以正确关闭连接;
  2. 检查以确保max_allowed_packet的值足够高,并且客户端没有收到“数据包太大”消息。 这种情况他会中止连接,而不正确关闭它;
  3. 另一种可能性是time_wait。建议您确认连接被妥善管理并且是在应用端正常关闭;
  4. 确保事务正确提交(开始和提交),以便一旦应用程序“完成”连接,它将处于“clean”的状态;
  5. 您应该确保客户端应用程序不中止连接。 例如,如果php的选项max_execution_time设置为5秒,增加connect_timeout是没用的,因为php会杀死脚本。 其他编程语言和环境也有类似的选项;
  6. 连接延迟的另一个原因是dns问题。 检查是否启用了skip-name-resolve,检查主机根据其ip地址而不是其主机名进行身份验证;
  7. 尝试增加mysql的net_read_timeout和net_write_timeout值,看看是否减少了错误的数量。

总结

通过这4个案例,我们能够了解到,aborted_clients、和aborted_connects的区别,以及什么情况下会爆出什么样的错误日志,文章第二节中的几个aborted错误是常见的错误,这类错误出现的时候脑海里要有一个理论知识,知道什么情况下,会出现什么样的错误,以便快速定位问题。由于笔者的水平有限,编写时间也很仓促,文中难免会出现一些错误或者不准确的地方,不妥之处恳请读者批评指正。

好了,以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网