標籤:code 串連數量 content pipe ulimit soc core files 登出
linux 開啟檔案數 too many open files 解決方案
too many open files
出現這句提示的原因是程式開啟的檔案/socket串連數量超過系統設定值。
查看每一個使用者最大同意開啟檔案數量
ulimit -a
[email protected]:~$ ulimit -acore file size (blocks, -c) 0data seg size (kbytes, -d) unlimitedscheduling priority (-e) 20file size (blocks, -f) unlimitedpending signals (-i) 16382max locked memory (kbytes, -l) 64max memory size (kbytes, -m) unlimitedopen files (-n) 1024pipe size (512 bytes, -p) 8POSIX message queues (bytes, -q) 819200real-time priority (-r) 0stack size (kbytes, -s) 8192cpu time (seconds, -t) unlimitedmax user processes (-u) unlimitedvirtual memory (kbytes, -v) unlimitedfile locks (-x) unlimited
當中 open files (-n) 1024 表示每一個使用者最大同意開啟的檔案數量是1024
查看當前系統開啟的檔案數量
lsof | wc -lwatch "lsof | wc -l"
查看某一進程的開啟檔案數量
lsof -p pid | wc -llsof -p 1234 | wc -l
設定open files數值方法
ulimit -n 2048
[email protected]:~$ ulimit -n 2048[email protected]:~$ ulimit -acore file size (blocks, -c) 0data seg size (kbytes, -d) unlimitedscheduling priority (-e) 20file size (blocks, -f) unlimitedpending signals (-i) 16382max locked memory (kbytes, -l) 64max memory size (kbytes, -m) unlimitedopen files (-n) 2048pipe size (512 bytes, -p) 8POSIX message queues (bytes, -q) 819200real-time priority (-r) 0stack size (kbytes, -s) 8192cpu time (seconds, -t) unlimitedmax user processes (-u) unlimitedvirtual memory (kbytes, -v) unlimitedfile locks (-x) unlimited
這樣就能夠把目前使用者的最大同意開啟檔案數量設定為2048了。但這樣的設定方法在重新啟動後會還原為預設值。
永久設定方法
vim /etc/security/limits.conf在最後增加* soft nofile 4096* hard nofile 4096
最前的 * 表示全部使用者。可依據須要設定某一使用者,比如
fdipzone soft nofile 8192fdipzone hard nofile 8192
改完後登出一下就能生效。
linux 開啟檔案數 too many open files 解決方案