java.net.SocketException: Too many open files

Work 2008-12-01

<ListenThread.Default> <<WLS Kernel>> <> <BEA-000204> <Failed to listen on port 8001, failure count: 22, failing for 4,452 seconds, java.net.SocketException: Too many open files>
<ListenThread.Default> <<WLS Kernel>> <> <BEA-000206> <Attempting to close and reopen the server socket on port 8001.>
<ListenThread.Default> <<WLS Kernel>> <> <BEA-000203> <Reopening listen socket on port 8001.>



####<2008-11-26 下午11时05分27秒 CST> <Error> <EmbeddedLDAP> <caizheng> <unionserver> <ExecuteThread: '3' for queue: 'weblogic.kernel.System'> <<WLS Kernel>> <> <000000> <!Error_occurred_during_backups!>
####<2008-11-26 下午11时05分27秒 CST> <Critical> <EmbeddedLDAP> <caizheng> <unionserver> <ExecuteThread: '3' for queue: 'weblogic.kernel.System'> <<WLS Kernel>> <> <000000> <java.io.FileNotFoundException: ./unionserver/ldap/backup/EmbeddedLDAPBackup.zip (Too many open files)
    at java.io.FileOutputStream.open(Ljava.lang.String;)V(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
    at com.octetstring.vde.backend.standard.BackupTask.runTask(BackupTask.java:55)
    at com.octetstring.vde.util.TimedActivityThread.runOnDemand(TimedActivityThread.java:76)
    at weblogic.ldap.EmbeddedLDAP$EmbeddedLDAPTimedActivity.trigger(EmbeddedLDAP.java:1659)
    at weblogic.time.common.internal.ScheduledTrigger.run(ScheduledTrigger.java:243)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.time.common.internal.ScheduledTrigger.executeLocally(ScheduledTrigger.java:229)
    at weblogic.time.common.internal.ScheduledTrigger.execute(ScheduledTrigger.java:223)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
>

------------------------------------------------------------------------------------------

解决方法
1。ulimit -a 查看系统目前资源限制的设定。
[root@test security]# ulimit -a
core file size        (blocks, -c) 0
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) unlimited
max memory size       (kbytes, -m) unlimited
open files                    (-n) 1024
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) 8192
cpu time             (seconds, -t) unlimited
max user processes            (-u) 7168
virtual memory        (kbytes, -v) unlimited
[root@test security]#
通过以上命令,我们可以看到open files 的最大数为1024
那么我们可以通过一下命令修改该参数的最大值
2. ulimit -n 4096
[root@test security]# ulimit -n 4096
[root@test security]# ulimit -a
core file size        (blocks, -c) 0
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) unlimited
max memory size       (kbytes, -m) unlimited
open files                    (-n) 4096
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) 8192
cpu time             (seconds, -t) unlimited
max user processes            (-u) 7168
virtual memory        (kbytes, -v) unlimited

这样我们就修改了系统在同一时间打开文件资源的最大数,基本解决以上问题。

另外我们可以通过lsof  -p [进程的 pid]来查看系统当前打开的文件资源,可以了解不同时期系统的文件资源的使用情况,可根据情况进行系统资源的配置。
===================================================================
从这里学到的linux的命令
查看进程所占的文件描述符  lsof -p 390 | wc -l
查看系统的各种资源限制或者更改这个限制    ulimit -a