在Ubuntu上使用Glassfish时出现“Openfiles太多”的错误

我在Ubuntu 10.04 LTS 64位(Amazon EC2)上调整Glassfish 2.1.1时遇到问题。 只要将HTTP服务线程数从默认值5更改为100,就会在server.log中发现以下错误。

java.net.SocketException: Too many open files

其他错误包括:

 [#|2011-05-19T15:41:38.034-0500|SEVERE|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=16;_ThreadName=Timer-20;_RequestID=1bd7cd3e-0011-4ebc-95e5-487b96c76b20;|"DPL8011: autodeployment failure while deploying the application : null"|#] [#|2011-05-19T15:41:39.555-0500|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=20;_ThreadName=Timer-1;_RequestID=0d9630b5-2752-4ffb-ac7c-1cf51920155a;| java.lang.NullPointerException at com.sun.jbi.management.system.AutoAdminTask.pollAutoDirectory(AutoAdminTask.java:1031) at com.sun.jbi.management.system.AutoAdminTask.performAutoInstall(AutoAdminTask.java:329) at com.sun.jbi.management.system.AutoAdminTask.performAutoFunctions(AutoAdminTask.java:288) at com.sun.jbi.management.system.AdminService.heartBeat(AdminService.java:967) at com.sun.jbi.management.system.AdminService.handleNotification(AdminService.java:198) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor$ListenerWrapper.handleNotification(DefaultMBeanServerInterceptor.java:1732) at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:257) at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:322) at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:307) at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:229) at javax.management.timer.Timer.sendNotification(Timer.java:1237) at javax.management.timer.Timer.notifyAlarmClock(Timer.java:1206) at javax.management.timer.TimerAlarmClock.run(Timer.java:1289) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) |#] 

 [#|2011-05-19T16:30:40.228-0500|SEVERE|sun-appserver2.1|org.apache.jasper.servlet.JspServlet|_ThreadID=16;_ThreadName=httpWorkerThread-4949-48;_RequestID=63d6908e-cc09-4fa8-aac0-241e7582c42f;|PWC6117: File "/opt/glassfish-v2.1.1-b31g/lib/install/applications/admingui/adminGUI_war/header.jsp" not found|#] 

 [#|2011-05-19T16:30:40.229-0500|SEVERE|sun-appserver2.1|org.apache.jasper.servlet.JspServlet|_ThreadID=17;_ThreadName=httpWorkerThread-4949-46;_RequestID=869579eb-887d-4dc4-b0fc-edc4e41755a7;|PWC6117: File "/opt/glassfish-v2.1.1-b31g/lib/install/applications/admingui/adminGUI_war/homePage.jsp" not found|#] 

谷歌search,我发现了以下资源:

http://felipeferreira.net/?p=873 http://www.netadmintools.com/art295.html

我的/etc/security/limits.confg具有以下configuration。 我已经改变了http://mariosgaee.blogspot.com/2011/04/glassfish-211-on-linux-performance.html中提到的tcp设置

 * soft nofile 65535 * hard nofile 65535 * soft stack unlimited * hard stack unlimited 

/ proc / sys / fs / file-max的值是762655(我没有改变这个),但是我把/etc/sysctl.conf加到了'fs.file-max = 762655'

ulimit输出

 $ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 20 file size (blocks, -f) unlimited pending signals (-i) 16382 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) unlimited cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited file locks (-x) unlimited 

任何想法可能会导致这个问题? 提前致谢!

要查看运行过程的实际限制,您可以使用/ proc,只需获取您的glassfish / java进程的pid,然后查看cat / proc / $ PID_OF_PROCESS / limits它应该是“Max open files”。 你也可以使用“lsof -p”监视打开文件的数量。

继续以前的答案:1.您是否在更改limits.conf后重新启动了glassfish服务器? 2. glassfish运行的是什么? 是否与limit.conf中设置的限制相匹配? 有时候启动脚本会为你调用ulimit,重写你在limits.conf中设置的内容3.你提到你的运行Ubuntu 10.04。 检查你的pam安装是否加载pam_limits.so,否则你的limits.conf将被忽略

尝试在/etc/pam.d/common-session中添加该行:

 session required pam_limits.so 

并可能需要重新启动。