When working with databases like MongoDB and Redis, you often run into this pitfall. A MongoDB instance suddenly crashes while running; Redis greets you with a warning at startup, and a closer look at the log reveals the maximum number of open files is insufficient.
# You requested maxclients of 10000 requiring at least 10032
# max file descriptors.
# Redis can't set maximum open files to 10032 because of OS error:
# Operation not permitted.
# Current maximum open files is 1024.
# maxclients has been reduced to 4064
# to compensate for low ulimit.
# If you need higher maxclients increase 'ulimit -n'.MongoDB's official documentation also tells you that you can simply adjust ulimit.
But in reality, if the user is a regular user
$ ulimit -n 65535
-bash: ulimit: open files: cannot modify limit: Operation not permittedusing root will of course work, but do you really want to run a database as root?
The correct way to handle this is actually to modify the limit.
Open /etc/security/limits.conf and add the following:
your_user_name soft nofile 65535
your_user_name hard nofile 65535Or if you want to add it for a group:
@your_group_name soft nofile 65535
@your_group_name hard nofile 65535Then save.
Check /etc/pam.d/sudo or /etc/pam.d/common-session-noninteractive; if you don't see the following line, add it manually:
session required pam_limits.soThen regular users need to log in again for the change to take effect. If it still doesn't take effect, by now the regular user should also be able to run ulimit -n 65535 themselves.
Comments
No comments yet — be the first to write one.