How to increase number of open files limit in CentOS 5,6, and 7

When load testing an application and seeing “Resource temporarily unavailable” issues, increase the “nofile” and system-wide limitations for the number of open files.

The kernel allows a certain amount of continuously open file descriptors. This number will automatically vary depending on the amount of RAM in the system by default.

In the file /etc/sysctl.conf, edit/add the following kernel parameter.

# vi /etc/sysctl.conf
fs.file-max = XXXXX

For applying the above changes execute.

# sysctl -p

The current value of the max-open-files limit can be found by.

# cat /proc/sys/fs/file-max
or
# sysctl -a | grep fs.file-max

Ulimit gives the user control over the resources available to the shell and the processes it starts. Per-process file descriptor limits apply to each user. 1024 is the default value. This can only be changed by root.

# ulimit -n
1024
# su - root
# ulimit -n 16384 
# ulimit -n
16384

To make the change permanent, edit the following file.

  • For Single User:
# vi /etc/security/limits.conf
<username> soft nofile 4096
<username> hard nofile 10240

Then save changes with :wq

Verify the changes as follows.

# su - username
# ulimit -Sn
4096
# ulimit -Hn
10240
  • For all users use wild card ‘*’ instead of username
# vi /etc/security/limits.conf
* soft nofile 4096
* hard nofile 10240

Then save changes with :wq

Leave a Reply