遭遇”java.io.IOException: Too many open files”

今天下午,线上的Jetty服务宕机了,日志里大量的”java.io.IOException: Too many open files”错误。搜索到Freddy Chu的博客里正好有关于此的解决办法。

$ sysctl fs.file-max
$ lsof -u jetty -nn | wc -l
$ ulimit -a
$ sudo vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535

同时发现了系统里也有Freddy Chu提到的”Too many CLOSE_WAIT”问题,谢谢Freddy Chu。

$ sudo vi /etc/sysctl.conf
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_intvl = 2
net.ipv4.tcp_keepalive_probes = 2
net.ipv4.tcp_keepalive_time = 1800

$ sudo sysctl -p

Update(2010-01-21): root用户要特殊设置

$ sudo vi /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535

Leave a Reply

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

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.
For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>