`
eimhee
  • 浏览: 2112305 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

解决linux下too many file问题

阅读更多

网址同时访问量比较大,此时jetty就会报错,报错信息中包含“Too many open files”,例如:

java.io.FileNotFoundException:  (Too many open files)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
        at weblogic.descriptor.DescriptorCache.writeToCache(DescriptorCache.java:236)
        at weblogic.descriptor.DescriptorCache.parseXML(DescriptorCache.java:388)
        Truncated. see log file for complete stacktrace

 

linux默认的打开文件数量是1024,我们可以用ulimit -a 来查看系统资源,例如:

[root@redhat ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                   (-n) 1024 --打开最大文件数量限制
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

 

解决该问题的宗旨是:增大打开文件最大句柄限制数,该数是1024的整数倍

1.临时增大open files的限制值

  可以用ulimit -n 来临时增大该限制值,但是一旦重启服务器后,该值又会恢复到1024。只能暂时性的解决问题。命令如下:

 

 

sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

 

 

写道

 

ulimit is a shell builtin like cd, not a separate program. sudo looks for a binary to run, but there is no ulimit binary, which is why you get the error message. You need to run it in a shell.

However, while you do need to be root to raise the limit to 65535, you probably don’t want to run your program as root. So after you raise the limit you should switch back to the current user.

To do this, run:

sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

and you will get a new shell, without root privileges, but with the raised limit. The exec causes the new shell to replace the process with sudo privileges, so after you exit that shell, you won’t accidentally end up as root again

 

下面这个命令可以追踪程序打开了什么文件

 

lsof -p <pid of jvm>

 

永久修改打开文件的最大数可以修改 /etc/security/limits.conf

加入下面2句

* soft nofile 2048 # Set the limit according to your needs
* hard nofile 2048

 然后重启putty, 可以看到生效了

1
4
分享到:
评论
2 楼 eimhee 2015-02-09  
finallygo 写道
你这属于"头痛医头脚痛医脚"的解决方式,你有查查为什么会出现这个错误么?

默认linux只能打开1024个文件, lsof -p <pid of jvm>  这个命令可以找到原因,
程序上的原因我还没仔细考虑过, 可能有些文件没及时关闭。
1 楼 finallygo 2015-02-08  
你这属于"头痛医头脚痛医脚"的解决方式,你有查查为什么会出现这个错误么?

相关推荐

    Hadoop问题处理

    java.io.IOException: Too many open file、java.lang.OutOfMemoryError报错处理方法

    Linux下应用程序大打开文件数的理解和修改

    运行在Linux系统上的Java程序运行了一段时间后出现Too many open files的异常情况。  这种情况常见于高并发访问文件系统,多线程网络连接等场景。程序经常访问的文件、socket在Linux中都是文件file,系统需要记录...

    CompTIA Linux+ Exam LX0-103 and Exam LX0-104, 3rd Edition

    Linux is viewed by many companies and organizations as an excellent, low-cost, secure alternative to expensive operating systems such as Microsoft Windows. The CompTIA Linux+ Powered by LPI exams test...

    文件libssl.so.1.0.0、文件libcrypto.so.1.0.0

    ucsc软件问题!!!在Linux系统中,如果安装ucsc的系列软件,如: conda install -c bioconda ucsc-bedgraphtobigwig conda install -c bioconda ucsc-bigwigtobedgraph ..... 等等一系列ucsctools的系列工具,在...

    Hadoop集群(第12期副刊)_Hbase性能优化

    Linux系统最大可打开文件数一般默认的参数值是1024,如果你不进行修改并发量上来的时候会出现“Too Many Open Files”的错误,导致整个HBase不可运行,你可以用ulimit -n 命令进行修改,或者修改/etc/security/...

    Linux操作系统错误代码解释_中英文对照

    OS error code 23: Too many open files in system 操作系统错误代码23:打开太多的文件系统 OS error code 24: Too many open files 操作系统错误代码24:打开的文件太多 OS error code 25: Inappropriate ioctl ...

    Linux文件句柄限制总结

    文件句柄 文章目录文件句柄查看用户级别(nofile)单个进程级别(nr_open )系统级别(file-max)修改用户级别(nofile)单个进程级别(nr_open )系统...超过最大句柄限制,报错:java.io.IOException: Too many open

    Tengine(Nginx)配置参考

    设置后你的操作系统和Nginx可以处理比“ulimit -a”更多的文件,所以把这个值设高,这样nginx就不会有“too many open files”问题了。 worker_rlimit_nofile 100000; #全局错误日志及PID文件 #error_log logs/...

    Linux.Server.Hacks

    (Linux.Server.Hacks.2003).Rob.Flickenger 英文版本 The Jargon File containsa bunch of definitionsof the term “hacker,” most having to do with technical adeptness and a delight in solving problems ...

    Oracle WebLogic Server 10gR3: Troubleshooting Methodologies

    非常好weblogic诊断教程 Oracle WebLogic Server 10g R3: Troubleshooting Methodologies Duration: 3 Days ...Symptoms, Causes, and Troubleshooting of Too Many Open Files Problem Copyright

    Sublime Text Build 3124 x64 Setup.exe

    minihtml: Fixed a stack overflow on Windows with too many unclosed tags API: Added Phantom and PhantomSet API: Added ViewEventListener API: Added View.is_primary() API: Added EventListener.on_hover...

    Free Pascal Mips机上的Pascal编译器源程序和执行文件

    The original FPC 2.00 sources include many examples, a lot of them can be used to test this compiler too. This alpha 0.90 version can be used as a base for further development. In order to compile ...

    NFS Illustrated by Brent Callaghan (z-lib.org).pdf

    has been almost too successful at making remote files indistinguishable from local files. For instance, a program that backs up files on a local disk to tape needs to avoid stumbling into NFS file...

    日程管理安排服务器软件

    With the htpasswd access, many encryption methods are available, and crypt is the default one in Radicale. Unfortunately, the crypt module is not unavailable on Windows, you have to pick another ...

    convmv-1.15.tar.gz

    if the file to which shall be renamed already exists, it will be overwritten if the other file content is equal. --unescape this option will remove this ugly % hex sequences from filenames and turn ...

    数据库基础

    §10.1.11 使用 product_user_file来限制用户使用产品 220 §10.2 常用技巧 221 §10.2.1 long 类型的查询 222 §10.2.2 如何确定执行时间 222 §10.2.3 如何终止用户会话 222 §10.2.4 用TRANSLATE对数据加密和解密...

    Unlocker 2.1.1 vmware装最新OSX解锁程序

    ESXi is no longer supported as there are too many errors on newer versions due to VMware hardening the ESXi image. 8. Thanks --------- Thanks to Zenith432 for originally building the C++ unlocker ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    More complex inline functions may also be put in a .h file for the convenience of the implementer and callers, though if this makes the .h file too unwieldy you can instead put that code in a ...

    unlocker211

    ESXi is no longer supported as there are too many errors on newer versions due to VMware hardening the ESXi image. 8. Thanks --------- Thanks to Zenith432 for originally building the C++ unlocker ...

    clucene源码

    'Too many open files' Some platforms don't provide enough file handles to run CLucene properly. To solve this, increase the open file limit: On Solaris: ulimit -n 1024 set rlim_fd_cur=1024 ...

Global site tag (gtag.js) - Google Analytics