转载请注明出处: http://blog.youkuaiyun.com/jason_asia/article/details/48621211
Zabbix agent导致的Error in accept: Too many open files in system无法访问msyql数据库
【环境描述】
Mysql 5.5.21
【情况描述】
现象数据库处于运行状态,但是无法创建新的连接,监控报警“Timeout while attempting connection”
[root@db11149 ~]# mysql
连接不上Mysql,一直处于等待状态。
Mysql的error日志报错:
[ERROR] /usr/sbin/mysqld: Can't find file:'./wukong_customs/wukong_task_info.frm' (errno: 23)
[ERROR] Error in accept: Too many openfiles in system
Mysqld进程打开的文件句柄数:
[root@db11149 ~]# lsof -p 24504 | wc-l
4805
没有超过Mysql设置的限值。
[root@db11149 ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 268288
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 268288
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@db11149 ~]# cat/etc/security/limits.conf | tail -3
# End of file
* soft nofile 65536
* hard nofile 65536
查看操作系统的日志:
localhost kernel: VFS: file-max limit 65536reached
localhost nrpe[6665]: Network server acceptfailure (23: Too many open files in system)
日志显示操作系统的连接数已经达到了最大值65535了,但是服务器上运行的业务应用只有数据库服务,而mysql打开的文件句柄数不到5000个。因此推断是有哪个正在运行的服务打开的句柄数过多导致的。
查看目前运行的所有进程打开的句柄数:
# for i in `ps -ef| egrep -v 'UID PID PPID' | awk '{print $2}'` ; do echo "pid=$i, open_files=`lsof -p $i| wc -l`" >> 1 ;done
计算所有进程打开的句柄总数:
# cat 1 | cut -d= -f 3 | awk'BEGIN{i=0}{i=i+$1}END{print i}'
62481
查看打开句柄数最多的进程:
确定是zabbix进程打开的
[root@db11149 ~]# ps -ef | grep zabbix
root 27644 1 0 Jul27 ? 00:00:00 zabbix_agentd -c/etc/zabbix/zabbix_agentd.conf
root 27646 27644 0 Jul27 ? 00:00:00 zabbix_agentd: collector [idle1 sec]
root 27647 27644 0 Jul27 ? 00:02:06 zabbix_agentd: listener #1[waiting for connection]
root 27648 27644 0 Jul27 ? 00:02:06 zabbix_agentd: listener #2[waiting for connection]
root 27649 27644 0 Jul27 ? 00:02:07 zabbix_agentd: listener #3[waiting for connection]
root 27650 27644 0 Jul27 ? 00:02:04 zabbix_agentd: listener #4[waiting for connection]
root 27651 27644 0 Jul27 ? 00:02:06 zabbix_agentd: listener #5[waiting for connection]
root 27652 27644 0 Jul27 ? 00:01:59 zabbix_agentd: listener #6[waiting for connection]
root 27653 27644 0 Jul27 ? 00:02:09 zabbix_agentd: listener #7[waiting for connection]
root 27654 27644 0 Jul27 ? 00:02:07 zabbix_agentd: listener #8 [waitingfor connection]
pid=27644, open_files=35
pid=27646, open_files=35
pid=27647, open_files=7614
pid=27648, open_files=7614
pid=27649, open_files=7666
pid=27650, open_files=7379
pid=27651, open_files=7479
pid=27652, open_files=7214
pid=27653, open_files=7916
pid=27654, open_files=7804
查看zabbix agent打开的文件:
zabbix_ag 27651 root 2w REG 253,2 1948 98307 /tmp/zabbix_agentd.log
zabbix_ag 27651 root 3w REG 253,2 5 98305 /tmp/zabbix_agentd.pid
zabbix_ag 27651 root 4u IPv6 894815352 0t0 TCP *:10050 (LISTEN)
zabbix_ag 27651 root 5u IPv4 894815353 0t0 TCP *:10050 (LISTEN)
zabbix_ag 27651 root 7u sock 0,5 0t0 898398069 can't identify protocol
………. 好多好多 cant’t identifyprotocol
zabbix_ag 27651 root 8u sock 0,5 0t0 898398084 can't identify protocol
【产生原因】
由此确定是由于zabbix agent的异常导致的。
【如何处理】
重启zabbix agent后,打开的文件被释放。
查找zabbix的资料后确定是zabbix agent的BUG,目前在zabbix agent 2.4.3和2.4.4版本中发现了这个BUG,在2.2和2.5版本中已经修复了。
然后更新zabbix agent的版本。
本文详细描述了一个系统中 Zabbix Agent 异常导致 MySQL 数据库连接失败的问题,通过检查操作系统日志、进程句柄数及 zabbix agent 的文件打开情况,最终定位到是 zabbix agent 导致系统文件句柄数过高。解决方案包括重启 zabbix agent,升级至已修复此 bug 的版本,避免系统资源过度占用。

810

被折叠的 条评论
为什么被折叠?



