When Linux servers are tuned for large concurrency, it is often necessary to pre-tune the Linux parameters, where modifying the maximum number of Linux file handles is one of the most frequently modified parameters.
You can query Linux-related parameters by executing ulimit-a in Linux, as follows:
[Email protected] ~]# ulimit-a
Open files (-N) 1024
By default, the maximum number of file handles for Linux is 1024. When your server reaches its limit in large concurrency, it will report "Too many open files".
So how do I change the number of Linux max file handles? It's actually very simple:
1. Temporary effective method
This command modifies the maximum number of Linux file handles and modifies the state of the changes using ulimit-a later, such as:
[Email protected] ~]# ulimit-n 65536
[Email protected] ~]# ulimit-a
Open files (-N) 65536
[Email protected] ~]# ulimit-n
65536
However, this method is only valid for the current process. Reopen a shell or open a process, and you'll see that the parameter is still a number before the Ulimit-n xx changes.
2, modify the Linux system parameters. vi/etc/security/limits.conf add
* Soft Nofile 65536
* Hard Nofile 65536
Note: "*" means that it is valid for all users, and if only one user needs to be active, only the "*" should be changed to a user name.
Modify save later, log off the current user, login again, execute ulimit-a, OK, the parameters are in effect:
[Email protected] ~]# ulimit-a
Open files (-N) 65536
Note:
The hard limit indicates the maximum value that can be set in the soft limit. The soft limit refers to the setting value that the current system is in effect. Hard limit values can be reduced by ordinary users. But cannot be increased. The soft limit cannot be set higher than the hard limit. Only the root user can increase the hard limit value.
Maximum can be set to:
655350
This article from "Travel Life" blog, declined reprint!
Linux Too many open files problem-Modify the maximum number of Linux file handles