问题现象
服务器日志信息如包含"Too many open files",如下:
<Sep 28, 2009 9:55:16 AM CST> <Critical> <Server> <BEA-002616> <Failed to listen on channel "Default" on ***...:***, failure count: 1, failing for 0 seconds, java.net.SocketException: Too many open files> <Sep 28, 2009 9:55:16 AM CST> <Error> <HTTP> <BEA-101019> <[weblogic.servlet.internal.WebAppServletContext@6c086c08 - appName: 'consoleapp', name: 'console', context-path: '/console', spec-version: '2.5'] Servlet failed with IOException java.io.FileNotFoundException: /**/wlserver_10.3/server/lib/consoleapp/webapp/images/sort_up.gif (Too many open files) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:112) at weblogic.utils.classloaders.FileSource.getInputStream(FileSource.java:31) at weblogic.servlet.internal.WarSource.getInputStream(WarSource.java:65) at weblogic.servlet.FileServlet.sendFile(FileServlet.java:400) Truncated. see log file for complete stacktrace >
部署了smartbi的websphere,报如下错误:
03-02 11:15:23 WARN updateIndexObjects(smartbi.index.IndexService:240) - /websphere/IBM/WebSphere/AppServer/profiles/AppSrv02/Index-smartbi/read/_42o8_1.del (Too many open files) 03-02 11:15:23 ERROR activate(smartbi.framework.Framework:70) - 读取文件错误 读取文件错误 at smartbi.util.StringUtil.getLanguageResourceBundle(StringUtil.java:845) at ...(...) at smartbi.extension.Extension.getResourceAsStream(Extension.java:364) Caused by: java.io.FileNotFoundException: ./exts-smartbi/smartbiExtension3613428770114930406.tmp/META-INF/extension_lang_zh_CN.properties (Too many open files) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:212) at java.io.FileInputStream.<init>(FileInputStream.java:152) at smartbi.extension.Extension.getResourceAsStream(Extension.java:364) at smartbi.extension.ExtensionManager$4.getResourceAsStream(ExtensionManager.java:506) at smartbi.util.StringUtil.getLanguageResourceBundle(StringUtil.java:832) at smartbi.util.StringUtil.getLanguageValue(StringUtil.java:800) at smartbi.util.StringUtil.getLanguageValue(StringUtil.java:792) at smartbi.composite.CompositeModule.afterStartup(CompositeModule.java:215) at smartbi.framework.Framework.activate(Smartbi:66) at smartbi.extension.spring.SmartbiContextLoaderListener.contextInitialized(SmartbiContextLoaderListener.java:144) at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1734) at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:415) at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88) at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:171) at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:904) at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:789)
问题原因
出现类似上述的错误说明系统的用户同时打开的文件数过多, 需要调整参数改大配置。
解决方案
Linux/AIX操作系统中有参数设置允许用户同时打开的最大文件数量
可通过su -root切换到root用户后执行如下指令:
echo "
* soft nofile 65536
* hard nofile 65536
" >> /etc/security/limits.conf
上述指令将最大打开文件数调整为65536,此修改对所有linux用户生效。配置完毕后通过su 用户名切换到其他用户执行ulimit -n可以看到修改后的效果。
对于文件描述符增加的比例,资料推荐是以2的幂次为参考。如当前文件描述符数量是1024,可增加到2048,如果不够,可设置到4096,依此类推。
具体是哪些文件持续消耗了文件数,在Linux上可以通过lsof命令查看(更多lsof命令的了解可以参考网上的文档:https://www.cnblogs.com/sparkbj/p/7161669.html)。
Windows
在 Windows 操作系统上,文件描述符被称作文件句柄。在 Windows 2000 服务器上,打开文件的句柄极限设置为 16,384。此数量可以在任务管理器的性能摘要中监视。
注:关于句柄数的修改可从网上搜索相关解决方案,如可参考网上文档:http://www.cnblogs.com/mydomain/p/3428620.html 和 http://www.cnblogs.com/likehua/p/3831331.html