最近发现两台MySQL server在中午的时候忽然(很突然的那种)发飙,不断的挂掉。重启mysql也尽是失败,看mysql的errorlog,只能看到类似如下的信息:
Forcing close of thread 12232 user: 'root'
用mysqladmin 简单的监控了下mysql的情况:
mysqladmin -uroot -p******** status -i 1
发现Queries per second avg只有200左右,可以说很低,但是Threads 确非常不稳定,居然会瞬间升级200以上,一般情况下这个线程这个值都是不会高于5的个位数!
然后继续看
mysqladmin -uroot -p******** processlist
居然有大量的unauthenticated user?? 如下情况
+------+-----------+---------+----+---------+------+-------+------------------+
[root@app028 ~]# mysqladmin -uroot -p************ processlist
+------+-----------+---------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+-----------+---------+----+---------+------+-------+------------------+
| 2007 | unauthenticated user | 192.168.4.29:58519 | | Connect | | login | |
| 2008 | unauthenticated user | 192.168.4.29:58553 | | Connect | | login | |
| 2009 | unauthenticated user | 192.168.4.29:58571 | | Connect | | login | |
| 2010 | unauthenticated user | 192.168.4.29:58577 | | Connect | | login | |
| 2011 | unauthenticated user | 192.168.4.29:58579 | | Connect | | login | |
| 2012 | unauthenticated user | 192.168.4.29:58589 | | Connect | | login | |
google了一下,
发现这算属MySQL的一个bug,不管连接是通过hosts还是ip的方式,MySQL都会对DNS做反查,IP到DNS,由于反查的接续速度过慢(不管是不是isp提供的dns服务器的问题或者其他原因),大量的查询就难以应付,线程不够用就使劲增加线程,但是却得不到释放,所以MySQL会“假死”。
解决的方案很简单,结束这个反查的过程,禁止任何解析。
打开mysql的配置文件(my.cnf),在[mysqld]下面增加一行:
skip-name-resolve
重新载入配置文件或者重启MySQL服务即可。
附 /etc/my.cnf配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port=3306
default-character-set=utf8
max_allowed_packet = 6M
skip-name-resolve
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid