linux - [Solved-4 Solutions] How to change the number of open files limit in Linux - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

How to change the number of open files limit in Linux ?

Linux - Solution 1:

You could always try doing a ulimit -n 2048. This will only reset the limit for your current shell and the number you specify must not exceed the hard limit

Each operating system has a different hard limit setup in a configuration file. For instance, the hard open file limit on Solaris can be set on boot from /etc/system.

set rlim_fd_max = 166384
set rlim_fd_cur = 8192
click below button to copy the code. By - Linux tutorial - team

On OS X, this same data must be set in /etc/sysctl.conf.

kern.maxfilesperproc=166384
kern.maxfiles=8192
click below button to copy the code. By - Linux tutorial - team

Under Linux, these settings are often in /etc/security/limits.conf.

There are two kinds of limits:

  • soft limits are simply the currently enforced limits
  • hard limits mark the maximum value which cannot be exceeded by setting a soft limit

Soft limits could be set by any user while hard limits are changeable only by root. Limits are a property of a process. They are inherited when a child process is created so system-wide limits should be set during the system initialization in init scripts and user limits should be set during user login for example by using pam_limits.

There are often defaults set when the machine boots. So, even though you may reset your ulimit in an individual shell, you may find that it resets back to the previous value on reboot. You may want to grep your boot scripts for the existence ulimit commands if you want to change the default.

Linux - Solution 2:

If you are using Linux and you got the permission error, you will need to raise the allowed limit in the /etc/limits.conf or /etc/security/limits.conf file (where the file is located depends on your specific Linux distribution).

For example to allow anyone on the machine to raise their number of open files up to 10000 add the line to the limits.conf file.

* hard nofile 10000
click below button to copy the code. By - Linux tutorial - team

Then logout and relogin to your system and you should be able to do:

ulimit -n 10000
click below button to copy the code. By - Linux tutorial - team

without a permission error.

Linux - Solution 3:

1) Add the following line to /etc/security/limits.conf

webuser hard nofile 64000
click below button to copy the code. By - Linux tutorial - team

then login as webuser

su - webuser
click below button to copy the code. By - Linux tutorial - team

2) Edit following two files for webuser

append .bashrc and .bash_profile file by running

echo "ulimit -n 64000" >> .bashrc ; echo "ulimit -n 64000" >> .bash_profile
click below button to copy the code. By - Linux tutorial - team

3) Log out, then log back in and verify that the changes have been made correctly:

$ ulimit -a | grep open
open files                      (-n) 64000
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 4:

If some of your services are balking into ulimits, it's sometimes easier to put appropriate commands into service's init-script. For example, when Apache is reporting

"[alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread"

Try to put ulimit -s unlimited into /etc/init.d/httpd. This does not require a server reboot.


Related Searches to - linux - linux tutorial - How to change the number of open files limit in Linux