環境: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 配置最大文件打開數 [root@tool-19 conf]# vim /etc/sysctl.conf #文件末尾加入配置內容: fs.file-max = 4000000 [root@tool-19 conf]# sysctl -p #然后執行命令,使修改配置立即生效:
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