CentOS too many open files question-Modify the Linux max file handle number

Source: Internet
Author: User
Tags posix

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
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 Files (-N) 1024x768
Pipe Size (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, 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, Ulimit-n 2048

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 2048
[Email protected] ~]# 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) 256324
Max locked Memory (Kbytes, L) 64
Max memory Size (Kbytes,-m) unlimited
open Files (-N) 2048
Pipe Size (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. Reopen a shell or open a process, and you'll see that the parameter is still a number before the Ulimit-n xx changes. So is there a way to do it once and for all?

Of course! That is to modify the system parameters.

2, modify the Linux system parameters.vi/etc/security/limits.confAdd to

* Soft Nofile 65536

* Hard Nofile 65536

Modify save later, log off the current user, login again, execute ulimit-a, OK, the parameters are in effect:

[Email protected] ~]# 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) 256600
Max locked Memory (Kbytes, L) 64
Max memory Size (Kbytes,-m) unlimited
Open files (-N) 65536
Pipe Size (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

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

CentOS too many open files question-Modify the Linux max file handle number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.