1、如遇到应用程序too many open files 报错
ps -ef|grep xxxx
cd /proc/进程号/
cat limits
`Max open files 9999 9999 files `
2、查看当前 open flies
限制
root@ip-172-31-30-45:~# ulimit -n
1024
3、解决方法:
3.1
在当前窗口执行 ulimit -n 65536
命令,重启应用程序,但只对当前窗口启动的程序生效.
3.2
编辑/etc/security/limits.d/90-nproc.conf
文件,可长久生效。
[root@mysql]# cat /etc/security/limits.d/90-nproc.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
4、查询系统中各进程打开文件排行,第一列是打开文件描述符数量,第二列是PID
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more
5、lsof -p 进程号
查询正在打开文件描述符,或者进入/proc/PID/fd
目录中查看。
6、引申
有些应用程序内置参数是可以控制open files
限制的,比如MySQL数据库有open_files_limit
参数,会根据一些算法决定最终open files 限制。
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_open_files_limit