Ubuntu 上 Glassfish 出现“打开文件过多”错误

Ubuntu 上 Glassfish 出现“打开文件过多”错误

我在 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|#]

通过谷歌搜索我发现了以下资源:

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

我的 /etc/security/limits.confg 具有以下配置。并且我已按照说明更改了 tcp 设置http://mariosgaee.blogspot.com/2011/04/glassfish-211-on-linux-performance.html

*       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

知道是什么原因导致了这个问题吗?提前谢谢!

答案1

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

答案2

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

答案3

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

session required pam_limits.so

并且可能需要重新启动。

相关内容