How to fix “Too many open files” issue

  1. Check the current global limitatoins
    ulimit -a

2. Find the pid of target process

ps -ef|grep yourprocessname

3.0 View the amount of files of process:

ls /proc/926/fd | wc -l

3. View the open files of target proces

3. Change open files value

ulimit -n 20480

4. restart process

5. The above method only works for current sytem, it will missing when restart the server, so we have to change system files

vim /etc/security/limits.conf

add the following content in the end:

* soft nofile 20480

* hard nofile 20480

  1. Change /etc/supervisor/supervisord.conf, add “minfds=XXX” under [supervisord]
  • Restart supervisor

全局配置

临时突破全局文件句柄数(所有进程所能够创建的文件句柄数)

  •   查看全局文件句柄数:cat /proc/sys/fs/file-max
  •   配置:echo 1000000 > /proc/sys/fs/file-max
  •   配置后立即生效

永久突破全局文件句柄数

  • 配置文件/etc/sysctl.conf,在文件末尾加上:fs.file-max=1000000
  • 使配置文件生效:sysctl -p

特别注意:

  • 局部文件句柄数一定不要超过全局文件句柄数!!!我就遇到过,因为一时疏忽,把局部文件句柄数设置超过了全局文件句柄数,导致无法开机后无法登陆的现象!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.