Linux系統裏打開文件描述符的最大值,一般缺省值是1024,對一臺繁忙的服務器來說,這個值偏小,所以有必要重新設置linux系統裏打開文件描述符的最大值。那麼應該在哪裏設置呢?
永久修改
編輯 /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
重新登錄,不需要重啓,ulimit -a
可以看到文件打開數已經是65534了
[root@VM-123-187-centos ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 3894
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535 #文件打開數已經是65534了
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) 3894
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
臨時修改
[root@VM-123-187-centos ~]# ulimit -n
1024
[root@VM-123-187-centos ~]# ulimit -n 65535
[root@VM-123-187-centos ~]# ulimit -n
65535
查看某進程可打開的文件數
- 獲取某進程ID(6464)
[root@iZj6cac0hudp6vxsqk771aZ proc]# ps aux|grep xxxxx
root 6464 1.4 33.9 3920460 1266508 ? Sl Jun03 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cat /proc/進程id/limits
->cat /proc/6464/limits
[root@iZj6cac0hudp6vxsqk771aZ proc]# cat /proc/6464/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 14503 14503 processes
Max open files 65535 65535 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 14503 14503 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us