linux配置用户最大打开文件数(错误Too many open files)

环境: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

 

posted @ 2020-07-13 11:43  苍茫宇宙  阅读(648)  评论(0编辑  收藏  举报