For Linux file descriptors in question and solve

problem

Every web server or almost all Linux servers need to be adjusted to file descriptors, I used ulimit -nto see the current up to open the file in the user's default setting is 1024, but the system up and running and open a few simple service use lsof | wc -lview the system is already on tens of thousands of files, to the question, why limit the file descriptor is not in force?

solve

I see that all open file system, and the use of ulimit -nview is to limit the current user's file descriptors

File descriptor limit system using cat /proc/sys/fs/file-maxthe command View

Understand the Linux system file descriptor limit

linux systems usually have a data file that can be opened each process has a limit, when the process has been open file descriptors exceed this limit, open () system call such as to obtain a file descriptor will return failure.

  • Linux limit the maximum file descriptor has two aspects, a user-level limit, the other is system level limitations.
  1. User level limits: ulimit command to see is the largest user-level file descriptor limit, which means that the total number of procedures performed each user login occupied file descriptors can not exceed this limit, so much like our web server, if it is use down the right user-initiated, they should adjust to the user's file descriptor

  2. System level limitations: sysctl proc file system commands and view the same value, which is a system-level limit, which limit is the sum of all the user opens a file descriptor

Modify quantitative restrictions

  • User-level
[root@localhost ~]# ulimit -n 10000
#临时修改,只对当前shell有效
-a:显示目前资源限制的设定;
-c <core文件上限>:设定core文件的最大值,单位为区块;
-d <数据节区大小>:程序数据节区的最大值,单位为KB;
-f <文件大小>:shell所能建立的最大文件,单位为区块;
-H:设定资源的硬性限制,也就是管理员所设下的限制;
-m <内存大小>:指定可使用内存的上限,单位为KB;
-n <文件数目>:指定同一时间最多可开启的文件数;
-p <缓冲区大小>:指定管道缓冲区的大小,单位512字节;
-s <堆叠大小>:指定堆叠的上限,单位为KB;
-S:设定资源的弹性限制;
-t <CPU时间>:指定CPU使用时间的上限,单位为秒;
-u <程序数目>:用户最多可开启的程序数目;
-v <虚拟内存大小>:指定可使用的虚拟内存上限,单位为KB。
vi /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
#永久修改
  • Modify system-wide limit
    modify /etc/sysctl.conf files via sysctl command: sysctl -w fs.file-max=2048executed after completion sysctl -pto

Reference Documents

Error record

[root@localhost ~]# dd if=/dev/zero of=./cc.txt bs=100M count=21
文件大小超出限制(吐核)

Beginning very ignorant, and later learned under the access to information

The reason : human error, I use the ulimit 10000command, the result will be the default -foption, meaning that a single file after I set up this command and then create the maximum size can not exceed 10000 blocks is 40000K = 40M.

-F after adjusting the number Solution:

Guess you like

Origin www.cnblogs.com/joinbestgo/p/11184252.html