首先出现这个提示的原因:应用程序打开的文件数量超过了系统设定值。

如何查看当前系统每个用户最大允许打开文件数量:

[root@registry ~]# 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) 3820
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) 3820
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

或者

[root@registry ~]# ulimit -n
1024  

其中 open files (-n) 1024 表示每个用户最大允许打开的文件数量是1024

#查看一下当前已有的连接数,以此来判断open files 为1024 是否足够

[root@registry ~]# lsof -n  |awk '{print$2}'|sort |uniq -c |sort -nr |more
590 5458
445 1065
306 638
267 770
190 5682
189 5457
158 704
130 1194
117 681
81 1263
68 5419
66 640
62 1
60 5677
57 678
55 1067
51 9036
51 1196
48 5698
44 677
44 470
38 494
32 637
29 4430
20 4614
17 9250
14 4566
12 9256
12 9251
11 9254
11 9252
10 9255
10 693
9 9253
3 92
3 9037
3 9033
3 9
3 8964
3 8
3 726

其中第一列是打开的文件句柄数量,第二列是进程id号

通过句柄数量最多的进程,查看是哪个应用程序打开了最多的文件句柄,通过命令:

[root@registry ~]# ps -aef |grep PID

设置open files 数值的方法

1.临时设置方法

[root@registry ~]# ulimit -n 4096
[root@registry ~]# 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) 3820
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 4096
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) 3820
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

这样就可以把当前用户的最大允许打开文件数量设置为4096,但这种设置方法在重启后会还原为默认值。

2.永久设置方法

[root@registry ~]# vim /etc/security/limits.conf
# End of file
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

在文件末尾添加上述四行,其中后面两行的 * 表示所有的用户,也可以根据需要设置某一个用户,比如www

# End of file
root soft nofile 65535
root hard nofile 65535
www soft nofile 65535
www hard nofile 65535

注销账户,重新登录即可生效。 

如果想查看某个进程最大允许打开的文件数量,可通过如下命令查看:

[root@registry ~]# top
top - 15:39:21 up 101 days, 6:26, 1 user, load average: 0.33, 0.57, 0.52
Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombie
%Cpu(s): 6.7 us, 0.0 sy, 0.0 ni, 93.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3881824 total, 111956 free, 3505012 used, 264856 buff/cache
KiB Swap: 2047996 total, 1001156 free, 1046840 used. 123968 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12872 www 20 0 2738092 743948 2292 S 6.7 19.2 652:05.43 java
1 root 20 0 43380 2244 1352 S 0.0 0.1 4:11.26 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.31 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 28:18.97 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 33:52.08 rcu_sched
10 root rt 0 0 0 0 S 0.0 0.0 0:39.61 watchdog/0
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
14 root 20 0 0 0 0 S 0.0 0.0 0:07.72 khungtaskd
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.18 writeback
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md
25 root 20 0 0 0 0 S 0.0 0.0 12:21.57 kswapd0
26 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
27 root 39 19 0 0 0 S 0.0 0.0 0:17.32 khugepaged
28 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
36 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kthrotld
38 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kmpath_rdacd
39 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kpsmoused
40 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ipv6_addrconf
59 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 deferwq
101 root 20 0 0 0 0 S 0.0 0.0 0:03.48 kauditd
225 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ata_sff
233 root 20 0 0 0 0 S 0.0 0.0 0:00.00 scsi_eh_0
234 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 scsi_tmf_0
235 root 20 0 0 0 0 S 0.0 0.0 0:00.00 scsi_eh_1
236 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 scsi_tmf_1
240 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ttm_swap
252 root 0 -20 0 0 0 S 0.0 0.0 1:07.64 kworker/0:1H
257 root 20 0 0 0 0 S 0.0 0.0 3:12.26 jbd2/vda1-8
258 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ext4-rsv-conver
325 root 20 0 119080 5460 5316 S 0.0 0.1 5:27.58 systemd-journal
354 root 20 0 44032 8 4 S 0.0 0.0 0:00.08 systemd-udevd
[root@registry ~]# cat /proc/12872/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 65535 65535 processes
Max open files 65535 65535 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 15089 15089 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us

Linux 进程打开最大文件连接数Too many open files的更多相关文章

  1. Linux 利用进程打开的文件描述符(/proc)恢复被误删文件

    Linux 利用进程打开的文件描述符(/proc)恢复被误删文件 在 windows 上删除文件时,如果文件还在使用中,会提示一个错误:但是在 linux 上删除文件时,无论文件是否在使用中,甚至是还 ...

  2. 利用lsof去查看Unix/Linux进程打开了哪些文件

    利用lsof去查看Unix/Linux进程打开了哪些文件 今天用了一下lsof,发现这个linux的小工具,功能非常强大而且好用. 我们可以方便的用它查看应用程序进程打开了哪些文件或者对于特定的一个文 ...

  3. 显示Linux进程打开了哪些文件? 用lsof命令

    1.lsof abc.txt --> 显示开启文件 abc.txt的进程. 2.lsof -c abc  ---> 显示abc进程现在打开的文件. 3.lsof -c -p 1234 -- ...

  4. Linux 系统管理命令 - lsof - 查看进程打开的文件

    命令详解 重要星级: ★★★★★ 功能说明: 全名为 list open files,也就是列举系统中已经被打开的文件,通过 lsof 命令,就可以根据文件找到对应的进程信息,也可以根据进程信息找到进 ...

  5. linux下打开chm文件的方法

    windows中,通常情况下,chm文件可以使用系统自带的程序打开,但是linux就没有那么幸运了,那么,如何在linux下打开chm 文件呢?有小编来为您介绍介绍,本篇,小编以ubuntu环境为例 ...

  6. s11.1 lsof:查看进程打开的文件

    功能说明 lsof 全名为list open files,也就是列举系统中已经被打开的文件,通过lsof命令,就可以根据文件找到对应的进程信息,也可以根据进程信息找到进程打开的文件. [语法格式] l ...

  7. Linux Ubuntu 打开.exe文件

    这两天在编译Android源码,进行到要在Linux里安装烧录软件那一步,要先装驱动,故了解了如何在linux下打开.exe文件. .exe 文件在linux下不能直接打开,可有两种方式打开:. 1. ...

  8. lsof恢复进程打开的文件

    工作原理:进程每打开文件都会生成一个文件句柄FD来标识一个文件,进程打开的文件如果没有被释放,可以通过文件句柄FD来恢复删除的文件 注意:适合恢复进程一直在打开一个文件,例如日志文件,如果配置文件进程 ...

  9. Linux下打开超大文件的方法

    Linux下打开超大文件方法 在Linux下用VIM打开大小几个G.甚至几十个G的文件时,是非常慢的. 这时,我们可以利用下面的方法分割文件,然后再打开. 1 查看文件的前多少行 head -1000 ...

随机推荐

  1. opencv笔记--ORB

    ORB detector 使用 FAST detector 和 BRIEF descriptor 基本思路.在介绍 ORB 之前,首先对 FAST 与 BRIEF 进行说明. 1 FAST FAST( ...

  2. 用python的turtle作图(一)静态图

    最近,花了点时间,用python画图. 主要包括三部分,简单的静态图形,复杂的组合图形,图形动画. (一)画静态图形 长方形, 圆, 三角形, 平行四边形, 五角星 (二)图形的组合 笑脸, 国旗, ...

  3. Vue 源码解读(1)—— 前言

    当学习成为了习惯,知识也就变成了常识. 感谢各位的 点赞.收藏和评论. 新视频和文章会第一时间在微信公众号发送,欢迎关注:李永宁lyn 文章已收录到 github 仓库 liyongning/blog ...

  4. Java基于ClassLoder/ InputStream 配合读取配置文件

    阅读java开源框架源码或者自己开发系统时配置文件是一个不能忽略的,在阅读开源代码的过程中尝尝困惑配置文件是如何被读取到内存中的.配置文件本身只是为系统运行提供参数的支持,个人阅读源码时重点不大可能放 ...

  5. 树莓派GPIO开发(三):蜂鸣器-PWM调节

    配置环境 系统:Raspbian11(官方64位) 设备:树莓派CM4 一.写在前面 关于PWM的基本介绍在上一篇博客已经说过了:树莓派GPIO开发(二)RGB模块-PWM调节 在RGB模块中,我们主 ...

  6. Python中读写文件三部曲

    写入文件:要把第二个参数 'r' 改成 'w' ,表示write,即以写入的模式打开文件;  往文件中写入内容,使用write()函数. 例子如下:注意 'w' 写入模式会暴力清空掉原有文件,然后再写 ...

  7. 还不会使用linux?快来通过VMware安装centos系统吧~

    1.前言 Linux,全称GNU/Linux,是一种免费使用和自由传播的类UNIX操作系统,其内核由林纳斯·本纳第克特·托瓦兹于1991年10月5日首次发布,它主要受到Minix和Unix思想的启发, ...

  8. Java并发杂谈(一):volatile的底层原理,从字节码到CPU

    volatile的特性 volatile是Java中用于修饰变量的关键字,其主要是保证了该变量的可见性以及顺序性,但是没有保证原子性:其是Java中最为轻量级的同步关键字: 接下来我将会一步步来分析v ...

  9. Oracle数据库的下载、安装与卸载

    Oracle数据库下载: 这里以Oracle 11g为例,推荐去Oracle官网下载 Oracle官网下载地址:https://www.oracle.com/database/technologies ...

  10. 『无为则无心』Python日志 — 65、日志模块logging的使用

    目录 1.logger类用法 2.handler类用法 3.formatter类用法 4.filter类用法 1.logger类用法 logger类:logger用于提供日志接口,常用于配置和发送日志 ...