linuxでのtoo many fileの問題の解決

2609 ワード

ウェブサイトの同時アクセスが大きい場合、jettyはエラーを報告します.エラー情報には「Too many open files」が含まれています.たとえば、次のようになります.
java.io.FileNotFoundException:  (Too many open files)        at java.io.FileOutputStream.open(Native Method)        at java.io.FileOutputStream.(FileOutputStream.java:179)        at java.io.FileOutputStream.(FileOutputStream.java:131)        at weblogic.descriptor.DescriptorCache.writeToCache(DescriptorCache.java:236)        at weblogic.descriptor.DescriptorCache.parseXML(DescriptorCache.java:388)        Truncated. see log file for complete stacktrace
 
linuxのデフォルトのオープンファイル数は1024で、ulimit-aを使用してシステムリソースを表示できます.たとえば、次のようにします.
[root@redhat ~]# ulimit -acore file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedfile size               (blocks, -f) unlimitedpending signals                 (-i) 1024max locked memory       (kbytes, -l) 32max memory size         (kbytes, -m)unlimitedopen files(-n)1024--最大ファイル数制限pipe size(512 bytes,-p)8 POSIX message queues(bytes,-q)819200 stack size(kbytes,-s)10240 cpu time(seconds,-t)を開く unlimitedmax user processes              (-u) 16384virtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited
 
この問題を解決する目的は、ファイルを開く最大ハンドル制限数を1024の整数倍にすることです.
1.Open filesの制限値を一時的に大きくする
この制限値はulimit-nが来たときに大きくすることができますが、サーバを再起動すると1024に戻ります.一時的に問題を解決するしかない.コマンドは次のとおりです.
 
 
sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

 
 
と書く
 
ulimit is a shell builtin like cd, not a separate program. sudo looks for a binary to run, but there is no ulimit binary, which is why you get the error message. You need to run it in a shell.
However, while you do need to be root to raise the limit to 65535, you probably don’t want to run your program as root. So after you raise the limit you should switch back to the current user.
To do this, run:
sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"
and you will get a new shell, without root privileges, but with the raised limit. The exec causes the new shell to replace the process with sudo privileges, so after you exit that shell, you won’t accidentally end up as root again
 
次のコマンドは、プログラムがどのファイルを開いたかを追跡します.
 
lsof -p <pid of jvm>

 
永久修正オープンファイルの最大数は/etc/security/limitsを変更できます.conf
次の2文を加える
* soft nofile 2048 # Set the limit according to your needs
* hard nofile 2048

そしてputtyを再起動すると、有効になります