Modify the maximum number of Linux file handles--ulimit-a

Source: Internet
Author: User
Tags posix

Recent server concurrency is very high, last night several services at the same time hanging, find logs found error: "Too many open files", in the Internet also found some information, finally by modifying the number of handles, solve the problem.

It is known that when Linux servers are tuned in 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) 1024
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.conf add

* Soft Nofile 65535

* Hard Nofile 65535

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) 65535
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

Modify the maximum number of Linux file handles--ulimit-a

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.