Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a MongoDB server that runs out of file descriptors for open connections. I changed the settings in /etc/security/limits.conf so that every user gets a hard and soft limit of 65000 of open files and added session require to /etc/pam.d/su, common-session, common-session-noninteractive, sshd. Server was restarted after changes made.

Afterwards, ulimit -a yields the desired result of having 65000 max file descriptors. Curiously though, while every process that gets started for any particular user uses the new file descriptor max of 65000, any MongoDB process that starts up (no matter the user) still only gets 1024 max file descriptors. I even tried opening a text file as the mongodb user, and that uses the 65000 limit.


  • Ubuntu Maverick
  • MongoDB 1.6.5

I am using an upstart script to start the MongoDB instance, which is here:

    pre-start script
        mkdir -p /var/lib/mongodb${PORT}
        mkdir -p /var/log/mongodb
        limit nofile 65000 65000
        limit nproc 65000 65000
    end script

    start on runlevel [2345]
    stop on runlevel [06]

      if [ -e /var/lib/mongodb${PORT}/mongod.lock ]; then rm /var/lib/mongodb${PORT}/mongod.lock; fi
      if [ ! -d /var/lib/mongodb${PORT} ]; then mkdir -p /var/lib/mongodb${PORT}; fi
      chown -R mongodb:mongodb /var/lib/mongodb${PORT}
      if [ "x$ENABLE_MONGODB" = "xyes" ]; then
            exec start-stop-daemon --start --quiet --chuid mongodb \
            --pidfile /var/lib/mongodb${PORT}/${PORT}.pid \
            --exec /usr/bin/mongod -- \
            --port ${PORT} \
            --dbpath /var/lib/mongodb${PORT} \
            --logpath /var/log/mongodb/mongodb${PORT}.log \
            --logappend  \
            --maxConns = 50000 \
            --replSet oascluster \
            --oplogSize 200 \
    end script


    respawn limit 20 30 

Am I missing a setting somewhere?

share|improve this question
up vote 1 down vote accepted

So it seems MongoDB 1.6.5 doesn't work with the limit nofile line. You need to put ulimit -n X (where X is the file descriptors you want) just after the script keyword.

        ulimit -n 60000

I guess the method using the pre-start block is for later versions of MongoDB.

Also for note, MongoDB has a hard limit of 20,000 connections, so it doesn't matter if you set file descriptors higher than that.

Another thing learned: starting and stopping using upstart scripts is not the same as REstarting. Starting and stopping threw errors on the limit nofile command, whereas restarting did not.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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