1. Home
  2. MongoDB Tutorial
  3. MongoDB Too many open files

MongoDB Too many open files

MongoDB Too many open files, NETWORK  [listener] Error accepting new connection on 0.0.0.0:27017: Too many open files

If you are getting above error on Ubuntu 18.04/16.04 LTS or any other cloud platform like Amazon EC2, Azure VM, Google Cloud Compute, etc. with preinstalled Ubuntu.

Follow below steps to fix.

Linux systems limit the number of file descriptors for one process may open to 1024 per process.

Switch to root user

# sudo su

To Change temporarily or per session enter below command

# ulimit -n 102400

To change Permanently. To Change system limits, modify/etc/security/limits.conf,

# nano /etc/security/limits.conf

Add the below lines in it

* soft nofile 102400

* hard nofile 102400

Output:

# - chroot - change root to directory (Debian-specific)
#
#<domain> <type> <item> <value>
#

#* soft core 0
#root hard core 100000
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#ftp - chroot /ftp
#@student - maxlogins 4


* soft nofile 102400
* hard nofile 102400

# End of file

Ubuntu 16.04/18.04 uses systemd, You have to Change the ulimit settings in MongoDB service file

Navigate to /etc/systemd/system/ and open mongodb.service file

# cd /etc/systemd/system/
# nano mongodb.service

Add below lines as shown below.

[Unit]

Description=High-performance, schema-free document-oriented database

After=network.target

[Service]

User=mongodb

Group=mongodb

ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

LimitNOFILE=infinity

LimitNPROC=infinity

[Install]

WantedBy=multi-user.target

Reload to daemon to apply settings

# systemctl daemon-reload

Start the MongoDB Service

# systemctl start mongodb

Check the MongoDB Service

# systemctl status mongodb

Output:

  mongodb.service - High-performance, schema-free document-oriented database

   Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: enabled)

   Active: active (running)

 Main PID: 84070 (mongod)

    Tasks: 82

   Memory: 276.5M

      CPU: 53.064s

   CGroup: /system.slice/mongodb.service

           └─84070 /usr/bin/mongod --quiet --config /etc/mongod.conf

Related Articles:

How to Install MongoDB on Ubuntu 18.04/16.04 LTS

Reference:

https://docs.mongodb.com/manual/reference/ulimit/

Tags

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.