1. 程式人生 > 實用技巧 >linux配置使用者最大開啟檔案數

linux配置使用者最大開啟檔案數

環境:centos7

1、通過命令ulimit -a檢視當前程序可以開啟的最大檔案數

[root@tool-19 conf]# 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) 127947
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) 127947 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

2、還可以通過命令ulimit -n 直接檢視當前程序可以開啟檔案的最大數量

[root@tool-19 conf]# ulimit -n
1024

3、上面兩個命令是檢視當前程序最大檔案數,而系統也有最大檔案數,它指的是所有程序可以開啟的檔案數量,如下圖所示的命令可以檢視當前系統的最大檔案數

[root@tool-19 conf]# cat /proc/sys/fs/file-max 
3247213

4、通過命令ulimit -a 65535可以進行更改,只對當前會話生效

[root@tool-19 conf]# ulimit -n 65535
[root@tool-19 conf]# ulimit -n
65535

5、要永久生效,可以通過輸入下圖所示的兩條命令來達到更改最大檔案數永久生效的目的

[root@tool-19 conf]# echo '* soft nofile 65535' >> /etc/security/limits.conf 
[root@tool-19 conf]# echo '* hard nofile 65535' >> /etc/security/limits.conf
#退出重新進入,檢視生效
[root@tool-19 ~]# ulimit -n
65535