Increasing ulimit on CentOS
We have a CentOS box that I'm trying to increase the max number of files that a user can have open. Currently when I run ulimit -Sn
I get 1024
and ulimit -Hn
gives 4096
. I need that number up around 6000.
In /etc/sysctl.conf
I've set fs.file-max = 100000
. In /etc/security/limits.conf
I have the following set:
username soft nofile 6000
username hard nofile 65535
I've logged out and logged back in as username
but am still not seeing my changes. What do I need to get this value changed?
All I have in /etc/security/limits.d
is 90-nproc.conf
. I've also ensured that ulimit is not being called in my .bash_profile or .bashrc.
When I run sysctl -p
it spits out the settings I want and it shows the value for fs.file-max
that I want. But when I run ulimit -Sn
, I get 1048. If I try to run sysctl --system
I get error: Unknown parameter "--system"
.
To force /etc/sysctl.conf
to be read again run sysctl -p
.
File /etc/security/limits.conf
is read by login shells and you should close active sessions windows if in GUI. For remote logins, it takes effect on relog.
As another poster has said, you need to have sysctl set the value in the running kernel. There are several ways you can set the value without rebooting:
sysctl -p /etc/sysctl.conf
sysctl -w fs.file-max=100000
sysctl --system
IMHO the last method is the best, as it replicates the order that the settings would be applied during boot (and thus if you have a conflict it will become apparent).
Note: I'm not sure which version of CentOS you're using, but on 7 at least I have run into a problem where if dracut rebuilds the initramfs for any reason (such as when installing a new kernel module) it will copy over the contents of /etc/sysctl.* into the initramfs, which will then be executed by systemd-sysctl during that phase, even if you later delete those entries out of /etc/sysctl.conf.
In my environment I've edited the systemd dracut module to exclude /etc/sysctl.* from that environment (as those settings will get set once the rootfs is mounted and systemd-sysctl runs again). It's just a gotcha that you might run into.