How do I set ulimits for the mongod process/user on CentOS?

I've read the official documentation but it doesn't provide OS-specific instructions.

  • I need to set ulimit -u 64000 and need this to persist after reboot.

  • I'm running CentOS 5.5 although will be upgrading to 6.5 soon.

  • I'd prefer not to modify any scripts installed by the package manager

5 Answers 5


Modify /etc/security/limits.conf with what you need. Example:

user soft nproc 64000

This line will set the number of processors (-u) to 64000 for "user". Soft/hard limits can be the same (soft allows spikes while hard prevents spawning).

  • Thanks, but after doing this and restarting mongod cat /proc/{pid}/limits shows no change. Does something additional need to be done to ensure the conf is read?
    – Tim
    Apr 28, 2014 at 17:07
  • 1
    Yes, reboot the server. It's set by the kernel.
    – Nathan C
    Apr 28, 2014 at 17:49

The newer version of the CentOS mongod startup script (/etc/init.d/mongod) has the default settings built into the start option:

  # Recommended ulimit values for mongod or mongos
  # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
  ulimit -f unlimited
  ulimit -t unlimited
  ulimit -v unlimited
  ulimit -n 64000
  ulimit -m unlimited
  ulimit -u 32000

  echo -n $"Starting mongod: "
  daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod

If you want to change the values and not modify the script, copy the script to /etc/init.d/mongod-custom, then edit the custom init script, set your values and change chkconfig to use mongod-custom instead of mongod.


To add to thaspius's answer, the limits seem to be set as he describes in the init script, but I was still getting the warning

[initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.

This seems to suggest that files limit defined in the init script had taken effect, but not the processes limit. Also following Nathan C's answer and adding

mongod soft nproc 64000

to /etc/security/limits.d/90-nproc.conf and restarting the system solved the issue.

If anyone is able to shed light on why that was necessary despite having the values in the mongodb init script I'm all ears!

  • same here, why "nproc" setting was ignored is a mistery to me.
    – Ostati
    Jan 9, 2017 at 16:49

Make this change in the /etc/security/limits.conf file. Set the hard and soft limits, and you should be good.

  • I'd recommend using files inside /etc/security/limits.d/ rather than messing with the limits.conf file directly Apr 26, 2018 at 18:52

For the change to be persistent you have to edit de init script, for example, in Red Hat 7, the init script has the following line:


You have to add the next one:


And then restart the service.

I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.