Linux Increase The Maximum Number Of Open Files / File Descriptors (FD)

by Vivek Gite on April 18, 2006 · 37 comments

How do I increase the maximum number of open files under CentOS Linux? How do I open more file descriptors under Linux?

The ulimit command provides control over the resources available to the shell and/or to processes started by it, on systems that allow such control. The maximum number of open file descriptors displayed with following command (login as the root user).

Command To List Number Of Open File Descriptors

Use the following command command to display maximum number of open file descriptors:
cat /proc/sys/fs/file-max
Output:

75000

75000 files normal user can have open in single login session. To see the hard and soft values, issue the command as follows:
# ulimit -Hn
# ulimit -Sn

To see the hard and soft values for httpd or oracle user, issue the command as follows:
# su - username
In this example, su to oracle user, enter:
# su - oracle
$ ulimit -Hn
$ ulimit -Sn

System-wide File Descriptors (FD) Limits

The number of concurrently open file descriptors throughout the system can be changed via /etc/sysctl.conf file under Linux operating systems.

The Number Of Maximum Files Was Reached, How Do I Fix This Problem?

Many application such as Oracle database or Apache web server needs this range quite higher. So you can increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):
# sysctl -w fs.file-max=100000
Above command forces the limit to 100000 files. You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is:
# vi /etc/sysctl.conf
Append a config directive as follows:
fs.file-max = 100000
Save and close the file. Users need to log out and log back in again to changes take effect or just type the following command:
# sysctl -p
Verify your settings with command:
# cat /proc/sys/fs/file-max
OR
# sysctl fs.file-max

User Level FD Limits

The above procedure sets system-wide file descriptors (FD) limits. However, you can limit httpd (or any other users) user to specific limits by editing /etc/security/limits.conf file, enter:
# vi /etc/security/limits.conf
Set httpd user soft and hard limits as follows:
httpd soft nofile 4096
httpd hard nofile 10240

Save and close the file. To see limits, enter:
# su - httpd
$ ulimit -Hn
$ ulimit -Sn

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 37 comments… read them below or add one }

1 Tachyon October 21, 2006

Icreasing the file handles is a good tip, but 5000 is very low these days. 200000 is more realistic for any modern system.
Also, there’s no need to logout, just edit the /etc/sysctl.conf and then type ‘sysctl -p’ as root.

Thanks,
Tachyon

Reply

2 Maroon Ibrahim June 23, 2007

Does this command work for Debian and does it affect SQUID file descriptor too?
Best Regards?

Reply

3 vivek August 15, 2007

Maroon,

Yes it works on Debian and all other Linux systems/distros.

Reply

4 Sathish A August 28, 2007

how to increase in a Redhat linux server? How to find the location of sysctl.conf file or how to find in which file the limit has been set?

thanks in advance

Reply

5 baka.tom September 11, 2007

i tried this on a CentOS (which by the way, i’ve decided the worst linux distribution ever), and it doesn’t seem to work. ulimit -n still says 1024, even after logout, even after reboot.

Reply

6 bourne September 13, 2007

/etc/sysctl.conf is good for the system-wide amount, but don’t forget that users also need different limits. See /etc/security/limits.conf (Debian, Redhat, SuSE all have it, probably most others as well) to assign specific limits on per-group, per-user, and default basises.

Reply

7 jason September 13, 2007

I am running “Red Hat Enterprise Linux ES release 4 (Nahant Update 5)” and followed the instructions above. Like “baka.tom”, I was unable to see the change reflected by typing “ulimit -n”. I don’t know if this is a problem, but it certainly reduces the credibility of this article (unless I screwed up, of course).

Reply

8 vivek September 14, 2007

baka.tom / jason,

The FAQ has been updated for latest kernel. It should work now. Let me know if you have any more problems.

bourne, thanks for pointing out user level or group level filelimit option.

I appreciate all feedback.

Reply

9 jackson December 1, 2007

Red Hat configuration requires the following line to be added for /etc/security/limits to work.

in /etc/pam.d/login
session required pam_limits.so

Reply

10 Arstan April 23, 2008

I’m trying to make 8192 on Ubuntu 7.10, adding

* soft nofile 8192
* hard nofile 8192

doesn’t work, but when i do change * to username(lets say root) it applies.

So how to change it system wide?

Reply

11 shankar June 19, 2009

you could use the following command to check if the given change reflected

#ulimit -n -H

that gives the hard value…

Reply

12 hywl51 October 28, 2009

“Use the following command command to display maximum number of open file descriptors:
cat /proc/sys/fs/file-max
Output:

75000

75000 files normal user can have open in single login session. ”

I think 75000 should mean the whole system can support 75000 open files at most , not for per user login.

Reply

13 Adam HP February 25, 2010

To clear up any confusion for increasing the limit on Red Hat 5.X systems:

# echo “fs.file-max=70000″ >> /etc/sysctl.conf
# sysctl -p
# echo “* hard nofile 65536″ >> /etc/security/limits.conf
# echo “session required pam_limits.so” >> /etc/pam.d/login
# ulimit -n -H
65536

In summary set your max file descriptors to a number higher than your hard security ‘nofile’ limit to leave room for the OS to run.

Reply

14 Ramesh March 22, 2010

Can anyone explain all the attributes in ulimit -a and how it impacts the performance of a system?

Reply

15 Thamizhananl P April 29, 2010

In Red hat enterprises linux(RHEL4 and RHEL5) after setting nofile limit we need to do below modification
In /etc/security/limits.conf file added
root soft nofile 5000
root hard nofile 6000

Edit the /etc/pam.d/system-auth, and add this entry:
session required /lib/security/$ISA/pam_limits.so

It perfectly worked me.
After this change open a new terminal and issue ulimit -a.
There you could see the updated file descriptor value for root user.

Reply

16 Jeoffrey July 9, 2010

This is very good. Thanks for the post =)

Reply

17 jfd3 August 17, 2010

What is the difference between a hard limit and a soft limit?
Thanks,

Reply

18 Francisco September 8, 2010

Is there any equivalent for MAC OS x (darwin) ??

Reply

19 Dirk September 11, 2010

Hi Francisco,

when I issue “ulimit -n -H” on Mac OS X 10.6, it says “unlimited”. So I guess you don’t have to worry about it.

Dirk

Reply

20 Joel December 14, 2010

I’m using Linux (Debian Lenny) on a server. I would like to keep my ulimit -n settings.
The values in /etc/security/limits.conf (soft and hard limits) and in /etc/sysctl.conf have been increased.
/etc/pam.d/login constains the “session required pam_limits.so”
I’ve also put the “ulimit -n 50000″ command in .bashrc
… and after logout/login and/or ssh, ulimit -n still returns 1024! What tricky settings also need to be changed? These incoherent and over-complicated version-dependent settings really make linux unusable. I’d rather write code than waste my time on linux configuration files.

Reply

21 Joel December 14, 2010

In the end, it suddenly worked, without changing anything more. How much time is needed before it’s taken into account? Strange and unreliable…

Reply

22 jee January 2, 2011

I have a problem about “too many open file “, i had changed all parameters,

but this problem is exist.

My system have a web application system, that have a dongle, I guess the problem

maybe caused by dongle .

Can you help me , thank you !

Reply

23 Terry Antonio January 25, 2011

Good Day Mate
I was going to leave you in my will for this but the mortgage payments might be to high.
Anyway long story short I run free radius and on a new server i built and it constantly reports “no db handles” if you check with the freeradius forum this is a common problem and is usually met with the kurt reply “figure out whats using all the descriptors”.
I had in my mind I had encountered this problem many years ago and it was a matter of increasing the system handles but just could not track it down.
From your article I found my mysql handles were set at 1024 I increased the soft limit to 5000 and the hl to 10000 and all is well in paradise again. Your bloods worth bottling
Cheers Terry

Reply

24 Marco Smith March 23, 2011

Hi, Can someone please tell me why the amount of open files increase so rapidly when changing from Single user mode to multi user mode?

Reply

25 Vivek Gite March 23, 2011

More users + More process + More background process == More open files

Reply

26 Marco Smith March 23, 2011

And what if you run, multi user mode from console, i.e without Windows X? Like for instance, what process/processes run that makes the number on increase SO high….like from 160 to 900 open files????

Reply

27 Thamizhannal March 23, 2011

Excluding operating system process(es), if any application runs on muti user mode and does not close the opened file, then it would create this issue. Please make sure that if any external application(may be your own’s or deployed one) runs on muti user mode and closed all the files it has opened if any.

Reply

28 cgrinds April 25, 2011

If you have cPanel, check /etc/profile.d/limits.sh. Although you shouldn’t change it here it’s possibly the root cause of your changes not sticking.

Reply

29 pep May 12, 2011

Could you please let me know , while we change the ulimit for root using “ulimit -n” , which is the configuration file in which it reflects.

Reply

30 Mukesh September 6, 2011

Thanks, it worked for me on Red Hat Linux 5.

Reply

31 khupcom September 21, 2011

Not working on my centos box.
# su – nginx
# ulimit -Hn
1024
# ulimit -Sn
1024

Reply

32 Soham December 8, 2011

Try in /etc/security/limits.conf file and at the end of the file add this.

* – nofile

Logout and login again and check ulimit -n

Reply

33 Leonardo September 27, 2011

Hi,

Worked in RH 5.

It´s very important to know if you have set the max-files for user xx, you must to start the application with the user xx…. if you are starting with another user, the changes does not effetct.

Reply

34 Nick October 26, 2011

You could also try

ulimit -n xxxxx now

where xxxxx is the number, e.g. 16384. Worked for me on CentOS 5.7.

Reply

35 Killjoy November 23, 2011

Nice one, worked fine for me too on Debian 6.

Reply

36 kamalakar November 1, 2011

I am trying to increase ulimit on Ubuntu
even after restarting changes are not reflected

Reply

37 mrcool December 26, 2011

u must edit config file ,if u increase the file descriptor value through the terminal means it shold be a temporary only ,if u want to permanently increase your ulimit mean u have to set the ulimit in config file. . . .

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 14 + 15 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: