問(wèn)題描述
tomcat日志中報(bào)too many open files導(dǎo)致程序無(wú)法讀取文件錯(cuò)誤。
報(bào)錯(cuò)原因
出現(xiàn)這句提示的原因是程序打開(kāi)的文件/socket連接數(shù)量超過(guò)系統(tǒng)設(shè)定值。
解決方法
- 查看每個(gè)用戶最大允許打開(kāi)文件數(shù)量
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) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
其中 open files (-n) 1024 表示每個(gè)用戶最大允許打開(kāi)的文件數(shù)量是1024
- 查看當(dāng)前系統(tǒng)打開(kāi)的文件數(shù)量
lsof | wc -l
watch "lsof | wc -l"
- 查看某一進(jìn)程的打開(kāi)文件數(shù)量
lsof -p pid | wc -l
lsof -p 1234 | wc -l
- 設(shè)置open files數(shù)值方法
ulimit -n 102400
但這種設(shè)置方法在重啟后會(huì)還原為默認(rèn)值。
- 永久設(shè)置方法
vim /etc/security/limits.conf
在最后加入
* soft nofile 4096
* hard nofile 4096
最前的 * 表示所有用戶,可根據(jù)需要設(shè)置某一用戶,例如
fdipzone soft nofile 8192
fdipzone hard nofile 8192
改完后注銷(xiāo)一下就能生效。