Modify the maximum number of file handles in linux.
We all know that during high concurrency Optimization on linux servers, you often need to optimize linux parameters in advance. Modifying the maximum number of file handles in linux is one of the most frequently modified parameters.
Run ulimit-a in linux to query linux-related parameters, as shown below:
[Root @ mongodb11 ~] # Ulimit-
Core file size (blocks,-c) 0
Data seg size (kbytes,-d) unlimited
Scheduling priority (-e) 0
File size (blocks,-f) unlimited
Pending signals (-I) 256324
Max locked memory (kbytes,-l) 64
Max memory size (kbytes,-m) unlimited
Open File (-n) 1024
Pipe size (512 bytes,-p) 8
POSIX message queues (bytes,-q) 819200
Real-time priority (-r) 0
Stack size (kbytes,-s) 10240
Cpu time (seconds,-t) unlimited
Max user processes (-u) 256324
Virtual memory (kbytes,-v) unlimited
File locks (-x) unlimited
By default, linux has a maximum of 1024 file handles. When the maximum concurrency of your server is reached, "too program open files" will be reported ".
So how can I modify the maximum number of file handles in linux? It is actually very simple:
1. ulimit-n 2048
This command can be used to modify the maximum number of file handles in linux. After modification, use ulimit-a to view the modified status, for example:
[Root @ mongodb11 ~] # Ulimit-n 2048
[Root @ mongodb11 ~] # Ulimit-
Core file size (blocks,-c) 0
Data seg size (kbytes,-d) unlimited
Scheduling priority (-e) 0
File size (blocks,-f) unlimited
Pending signals (-I) 256324
Max locked memory (kbytes,-l) 64
Max memory size (kbytes,-m) unlimited
Open File (-n) 2048
Pipe size (512 bytes,-p) 8
POSIX message queues (bytes,-q) 819200
Real-time priority (-r) 0
Stack size (kbytes,-s) 10240
Cpu time (seconds,-t) unlimited
Max user processes (-u) 256324
Virtual memory (kbytes,-v) unlimited
File locks (-x) unlimited
However, this method is only valid for the current process. Re-open a shell or start a process, you will find that the parameter is still the number before the ulimit-n xx modification. Is there a permanent way?
Of course! That is, modify system parameters.
2. Modify linux system parameters. Add vi/etc/security/limits. conf
* Soft nofile 65536
* Hard nofile 65536
Save the modification, log off the current user, log on again, run ulimit-a, OK, and the parameter takes effect:
[Root @ localhost ~] # Ulimit-
Core file size (blocks,-c) 0
Data seg size (kbytes,-d) unlimited
Scheduling priority (-e) 0
File size (blocks,-f) unlimited
Pending signals (-I) 256600
Max locked memory (kbytes,-l) 64
Max memory size (kbytes,-m) unlimited
Open File (-n) 65536
Pipe size (512 bytes,-p) 8
POSIX message queues (bytes,-q) 819200
Real-time priority (-r) 0
Stack size (kbytes,-s) 10240
Cpu time (seconds,-t) unlimited
Max user processes (-u) 256600
Virtual memory (kbytes,-v) unlimited
File locks (-x) unlimited
Article reprinted please indicate the source: http://www.cnblogs.com/likehua/p/3831331.html
What is the number of file handles? How can I overwrite the number of file handles in Linux (without changing the file) or simulate the consumption of some tools? The File handle is windows. In linux, it is called a File Descriptor. You can use ulimit-n to check the maximum number of opened files. as long as fopen is called multiple times and fclose is called, the consumption is exhausted. too many restrictions on a single program.
After changing the number of linux file handles, do I need to restart the process? Restart
Open files (-n)
It takes effect automatically when you want to restart
Modify/etc/security/limits. conf