Home > Linux, MySQL > Increasing File Descriptors and Open Files Limit CentOS 7

Increasing File Descriptors and Open Files Limit CentOS 7

PS: See Andy Dyrcz answer in the comments for a better way to do this

Some programs like Apache and MySQL require a higher number of file descriptors.
This is how you can increase that limit for all users in CentOS 7
Commands require root access

# Find the default limit – check the open files line – it will be 1024

sudo ulimit -a

To increase edit nano /etc/sysctl.conf add the below line, save and exit

fs.file-max = 100000

We also need to increase hard and soft limits
Edit /etc/security/limits.conf add the below lines before the #End, save and exit

* soft nproc 65535
 * hard nproc 65535
 * soft nofile 65535
 * hard nofile 65535

Next run the command

sudo sysctl -p

for MySQL, edit /usr/lib/systemd/system/mysqld.service  and add the below 2 lines at the end, save and exit

LimitNOFILE=65535
 LimitNPROC=65535

then increase the table_open_cache and open_files_limit in my.cnf

# reload systemctl
 sudo systemctl daemon-reload

# if you modified mysql config, restart mysql and check values for table_open_cache and open_files_limit

systemctl restart mysqld.service

run the below command to check the open files limit – change user based on requirement
output should say: open files (-n) 65535

# for mysql
 su - mysql -c 'ulimit -aHS' -s '/bin/bash'

# for apache
 su - apache -c 'ulimit -aHS' -s '/bin/bash'
Advertisements
  1. April 3, 2016 at 3:37 PM

    When adding

    LimitNOFILE=65535
    LimitNPROC=65535

    To the service file, it needs to be added to the [Service] section, not at the end.

  2. Andy Dyrcz
    March 27, 2017 at 6:57 PM

    You really don’t want to edit the service’s ulimits from within /usr/lib/systemd/system/ as this will most likely be overwritten during an update/upgrade. You want to create an “/etc/systemd/system/.service.d/” and create a limits.conf file in that directory.
    This way you don’t have to re-troubleshoot when you upgrade and you get “TOO MANY FILES” errors. 🙂

  3. Andy Dyrcz
    March 27, 2017 at 6:59 PM

    oops! I used %gt and $lt around service_name, so your comments chopped it out…. You want to create an “/etc/systemd/system/’service_name’.service.d/” is what i meant…

    • March 28, 2017 at 8:21 AM

      @Andy – thanks for the tip – i have included in the post

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: