49

I can use ulimit but I think that only affects my shell session. I want the limit increased for all processes. This is on Red Hat.

1
  • Which version of Red Hat, by the way? RHEL5?
    – mattdm
    Mar 9, 2011 at 18:07

5 Answers 5

36

Justin's answer tells you how to raise the number of open files available total to the whole system. But I think you're asking how to raise the per-user limit, globally. The answer to that is to add the following lines to /etc/security/limits.conf:

*               soft    nofile            2048
*               hard    nofile            2048

(Where the * means all users.)

There's some summary documentation in that file itself and in man limits.conf. This is implemented via the pam_limits.so module which is called for various services configured in /etc/pam.d/.

And, I have to admit, I have no idea where that 1024 default comes from. And believe me, I looked. I even tried without the pam_limits module configured, and it's still there. It must be hard-coded in somewhere, but I'm not exactly sure where.

5
  • 5
    Hmm... I set this properly. Exit SSH and come back in and my soft limit is still set to 1024. Is there something I'm missing to make this "active"? Thanks. Aug 6, 2015 at 0:29
  • @mattdm - It is worth mention that on some Linux distributions the mentioned file will be under: /etc/limits.conf Dec 11, 2017 at 20:20
  • yeah, I've been looking to know where 1024 is set as the default. is it compiled into the kernel?
    – asgs
    Aug 19, 2020 at 14:54
  • 1
    additionally we need add fs.file-max = 65536 in file /etc/sysctl.conf as suggested by RHEL access.redhat.com/solutions/2469 and @minhas23 Feb 11, 2021 at 8:08
  • Potential negative side effects?
    – MadHatter
    Feb 3 at 6:05
26

Increase max number of ulimit open file in Linux

1.Step : open the sysctl.conf and add this line fs.file-max = 65536

$ vi /etc/sysctl.conf

add new line and

fs.file-max = 65536

save and exit.

2.Step:

$ vi /etc/security/limits.conf

and add below the mentioned

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

save and exit check max open file ulimit

# ulimit -a

....
open files                      (-n) 65535
2
  • 1
    sysctl -p or logout->login is required to make changes effective. Aug 13, 2020 at 5:24
  • This suggestion to have the per-user limit (i.e., "limits.conf") be the same as the system-wide (kernel, "sysctl") one is a recipe for a single user to lock up the system by using up all available files and leaving nothing to anything else. Mar 18, 2021 at 14:59
15

According to the article Linux Increase The Maximum Number Of Open Files / File Descriptors (FD), you can increase the open files limit by adding an entry to /etc/sysctl.conf.

Append a config directive as follows:

fs.file-max = 100000

Then save and close the file. Users need to log out and log back in again to changes take effect or they can just type the following command:

# sysctl -p

You can also verify your settings with the command:

# cat /proc/sys/fs/file-max
2
  • 1
    I'm skeptical about needing to log out and in again for this particular setting, which is system-wide. (That goes for pretty much everything in sysctl...)
    – mattdm
    Mar 9, 2011 at 18:10
  • True. You only need a new login session for ulimit-style settings (i.e., pam_limits). sysctl is instant and at the kernel level. Mar 18, 2021 at 14:56
15

But if you're trying to increase the max number of open files of a service like MariaDB or something else (using systemd) you have to do directly in file .service

/lib/systemd/system/<servicename>.service

Will be something like this:

[Unit]
Description=Some Daemon
After=syslog.target network.target

[Service]
Type=notify
LimitNOFILE=49152
ExecStart=/usr/sbin/somedaemon

[Install]
WantedBy=multi-user.target

The completely answer is here: Increasing nproc for processes launched by systemd on CentOS 7

1
  • This needs to be upvoted, as the ubiquity of systemd along with its ongoing changes are increasing across the Linux ecosystem. Although, I would suggest to edit the answer to cp -r /lib/systemd/system/mariadb.service /etc/systemd/system/ and make the changes to that file, rather than the system-wide service file that's provided by the package.
    – ILMostro_7
    Feb 18, 2018 at 3:41
3

SUPLEMENT:

You may find config in different place: /etc/security/limits.d/*.conf

I had to modify it. It didn't work without it. Format is the same as for limits.conf

1
  • I also had to update this file for the setting to fully take on our CentOS servers. Jan 24, 2017 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy