我设置了
kern.maxfiles=65536
kern.maxfilesperproc=65536
之后,我将以下命令放在.zshrc文件
中ulimit -n 30000
但是,如果我尝试从Eclipse运行基于Netty的应用程序,则只有10K插座打开,然后会发生Java IO异常"太多的打开文件"。固定是堆栈。
java.io.IOException: Too many open files
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
at io.netty.channel.socket.nio.NioServerSocketChannel.doReadMessages(NioServerSocketChannel.java:135)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:68)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:834)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:745)
我使用以下命令检查服务器使用的打开文件/插座的数量,并且在发生异常时,它总是显示出比10K稍大的值。
lsof -p <pid> | wc -l
增加文件描述符值以实现。您将值设置为" 65536",但仅通过添加shell
来调用30000请更改值,然后在当前会话中重新加载bash,或者打开新的终端/会话,然后重新启动您的应用程序。它必须工作
您可以在以下链接的帮助下设置Ulimit。
https://vasnlinux.wordpress.com/2015/05/01/linux-server-hardening/