8

Linux 出现 too many open files 的处理办法

 2 years ago
source link: https://www.bugcatt.com/archives/2682
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

阿航

2021年6月22日

2

Linux 出现 too many open files 的处理办法

今天在使用Hexo generate时出现了oo many open files这个问题, 在此记录下过程以及解决方案.

CentOS

使用此命令获取当前系统打开文件数量:

lsof | wc -l

使用此命令获取打开文件数量上限:

ulimit -a

会返回类似:

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) 7268
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 7268
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

其中, open files的值就为上限. 上方的例子为 1024.

方案一: 优化你的服务

最优方案其实是使你的服务妥善处理文件. 如果无法优化, 请参考方案二.

方案二: 提高 open files 数量上限

使用该命令临时修改, 立即生效, 重启后失效:

ulimit -n 2048

你可以按需调整数量, 比如 ulimit -n 65535


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK