How to Change the Number of Open Files Limit in Linux

How do I change the number of open files limit in Linux?

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

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

kern.maxfilesperproc=166384
kern.maxfiles=8192

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.

Cannot change the maximum open files per process with sysctl

For Ubuntu 17.04. See this solution.

Prior to Ubuntu 17.04:

I don't know why the above settings don't work but it seems you can get the same result by using the /etc/security/limits.conf file.

Set the limit in /etc/security/limits.conf

sudo bash -c "echo '* - nofile 10240' >> /etc/security/limits.conf"
  • * means all users. You can replace it by a specific username.
  • - means both soft and hard for the type of limit to be enforced. Hard can only be modified by the superuser. Soft can be modified by a non-root user and cannot be superior to hard.
  • nofile is the Maximum number of open files parameter.
  • 10240 is the new limit.

Reload

Logout and log back in. sudo sysctl -p doesn't seem to be enough to reload.

You can check the new limit with:

ulimit -n

Tested on Ubuntu 16.04 and CentOS 6. Inspired by this answer.

How to increase the open files user limit in boxfuse?

Boxfuse Client 1.26.7.1312 and up now automatically adjust the user limits to match the kernel limits. See https://cloudcaptain.sh/docs/releasenotes#1.26.7.1312 and https://cloudcaptain.sh/docs/payloads/springboot#sysctl

Simply upgrade with boxfuse -u and you should be good to go.

How to change open files (ulimit -n) permanently for normal user in Debian Stretch?

It's not a problem in Debian.
It's a problem in systemd + gnome.
systemd chosen not read or use limits.conf, gdm chosen let systemd set it's limit.
ssh sudo su tty will use /etc/seecurity/limits.conf as normal.
See this bug systmd --user does not load limits from /etc/security/limits.d/ in Fedora. In the discussion this solution work for me.

Create file /etc/systemd/system/user@1000.service.d/limit.conf, replace 1000 as your userId, set limit in this file as in systemd service:

[Service]
LimitNOFILE=655360

How do I increase the open files limit for a non-root user?

The ulimit command by default changes the HARD limits, which you (a user) can lower, but cannot raise.

Use the -S option to change the SOFT limit, which can range from 0-{HARD}.

I have actually aliased ulimit to ulimit -S, so it defaults to the soft limits all the time.

alias ulimit='ulimit -S'

As for your issue, you're missing a column in your entries in /etc/security/limits.conf.

There should be FOUR columns, but the first is missing in your example.

* soft nofile 4096
* hard nofile 4096

The first column describes WHO the limit is to apply for. '*' is a wildcard, meaning all users. To raise the limits for root, you have to explicitly enter 'root' instead of '*'.

You also need to edit /etc/pam.d/common-session* and add the following line to the end:

session required pam_limits.so

Raise number of files a process can open beyond 2^20

Okay, I got it. You can't just set fs.file-max. You also have to set fs.nr_open, which has a default value of 2^20. I also removed the /etc/pam.d/common-session I created and commented out the session required pam_limits.so line in /etc/pam.d/sudo.

How to effectively increase max number of open files of mongodb on Debian?

After days study, I have found solution.

I use /etc/inid.d/mongo.sh as autorun script, and use

sudo -u mongodb /mongodb/bin/mongo.auto

as startup script.
So I need set pam auth with sudo.

So the solution is - in /etc/pam.d, it need append below to /etc/pam.d/sudo

session    required   pam_limits.so

Then reboot, it DONE.



Related Topics



Leave a reply



Submit