How to increase number of open files limit in Red Hat Enterprise Linux?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 5 or later

Issue

  • Facing "Resource temporarily unavailable" errors while load testing a application, need to increase "nofile" and system wide limits for number of open files.

Resolution

/proc/sys/fs/file-max :- This is the number of concurrently open file descriptors allowed by the kernel. By default this number will automatically vary according to the amount of RAM in the system.

  • Edit/Add below kernel parameter in file /etc/sysctl.conf.

    # vi /etc/sysctl.conf
      fs.file-max = XXXXX
    
  • For applying above changes run

    # sysctl -p
    
  • You can verify the current value of the max-open-files limit by

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

Ulimit: Provides control over the resources available to the shell and processes started by the user's shell.

  • Each user has per-process file descriptor limits. The default is 1024. Only root can change this.

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

To make the change permanent, edit the following file

  • For a single user

    # vi /etc/security/limits.conf    
    <username> soft nofile 4096
    <username> hard nofile 10240
    
  • Then save the changes:

    :wq
    
  • Verify the changes:

    # 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 the changes:

    :wq
    
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.