Ulimit-n corresponding/etc/security/limits.conf file settings
Problem: Can ' t open so many files for Linux OPS students, I believe they have encountered this problem.
Under Linux All resources are files, ordinary files are files, disk printers are files, sockets of course also files. The system is set to 1024 by default, but this number is not enough for servers, especially large concurrency, so we need to change the actual situation to a larger and more reasonable value.
Modify method
Temporary solution: Ulimit-shn 65535
Permanent solution, note, do not set too large, causing the server to fail to start, less than/proc/sys/fs/file-max
Vim/etc/security/limits.conf
# confirm that the following content is included:
* Soft Nofile 65536
* Hard Nofile 65536
Save, and then restart
Note: 65536 is my side of the set value, the reader can also set a suitable value, * on behalf of all users
Another,/PROC/SYS/FS/FILE-NR, can see the number of file handles currently used throughout the system
Ulimit-u
For example, when we simulate a large-scale HTTP concurrency test, the client will report an inability to fork the new proc exception because of the maximum process 1024 limit
Maximum number of processes to unlock a Linux system
Methods are as follows
Vim/etc/security/limits.d/90-nproc.conf
# Add the following line
* Soft Nproc 102400
Root Soft Nproc 102400
Ulimit the hard limit is the actual limit, and the soft limit, is the warnning limit, will only make warning, in fact, the Ulimit command itself is divided into soft and hard settings, plus-H is hard, plus-s is soft.
The default display is the soft limit, if the changes are not added, it is two to change together
The first one in the configuration file is domain, which is set to the asterisk to represent the global, and you can also make different restrictions for different users.
But Ulimit is actually a limitation on a single program, the process level
What about the total system limit?
It's actually here,/proc/sys/fs/file-max.
Find the explanation of File-max with Man 5 proc: file-max Specifies the limit on the number of file handles that can be opened by all processes in the system scope. Kernel-level.
The current value can be viewed by cat, and Echo immediately modifies
echo 10000 >/proc/sys/fs/file-max
There's another one,/proc/sys/fs/file-nr.
Read-only to see the number of file handles currently in use by the entire system
Ps:
[Email protected] ~]# CAT/PROC/SYS/FS/FILE-NR
1024 0 101269
Each of them represents
Number of allocated file handles/number of handles allocated but not used/maximum number of file handles
Specific explanations Reference http://www.dewen.io/q/14740
Http://stackoverflow.com/questions/3991223/how-does-linux-file-descriptor-limits-work
[Email protected] ~]# Cat/proc/sys/fs/file-max
101269
You can see that the last item of FILE-NR is consistent with File-max.
Reference link https://gitsea.com/2013/05/23/linux-ulimit%E8%AF%A6%E8%A7%A3/
Http://blog.sina.com.cn/s/blog_605f5b4f01013lad.html
The Association of the three linux/proc/sys/fs/file-nr/proc/sys/fs/file-max/etc/security/limits.conf