I'm trying to setup the config servers for mongodb sharding. I created a specific config file that is set to log to /var/log/mongodb/mongod-config.log.

When I run mongod --config <path-to-config-file>, I get this error:

`F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open 

When I run the same command but with sudo, it runs but there's no output.

But then when I try starting the mongo shell at the port (27019) specified by my config file, I get this:

MongoDB shell version v3.6.4
connecting to: mongodb://
2018-05-01T03:13:13.399+0000 W NETWORK  [thread1] Failed to connect to, in(checking socket for error after poll), reason: Connection 
2018-05-01T03:13:13.400+0000 E QUERY    [thread1] Error: couldn't connect to 
server, connection attempt failed :
exception: connect failed

I'm just following the MongoDB sharding documentation

I've seen some of the previous posts on here and one was the same problem. No solution there, but I want to try again and see if anybody has a solution to this.

Not sure if I missed something or what the issue is...


5 Answers 5


So, I have figured out my own question.

Firstly, the issue was that since I was using a different port 27019 for the config servers, I needed to open that port from the firewall.

Second, I changed the dbPath in my config file from /var/lib/mongodb to /data/db since that is the default path for mongodb to store data.

Make sure to run sudo service mongod restart after.

With that done, I was able to start mongod with my specific config file:

sudo mongod --config <path-to-config-file>

The key is to include sudo for me. That solved the issue of:

F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open 

After running the command, I see that mongod has started on my virtual machine (vm) and now I am able to connect to the mongo shell of said vm from another machine with:

mongo <ip_address_of_said_vm>:27019

I also faced the same problem while trying to start mongodb service in my Debian9 64bit server. I could see the below information while checking status.

:~# systemctl status mongod.service
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2019-02-22 14:52:17 CET; 11s ago
     Docs: https://docs.mongodb.org/manual
  Process: 20914 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
 Main PID: 20914 (code=exited, status=1/FAILURE)

Feb 22 14:52:17 server-test systemd[1]: Started High-performance, schema-free document-oriented database.
Feb 22 14:52:17 server-test mongod[20914]: 2019-02-22T14:52:17.650+0100
F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"
Feb 22 14:52:17 server-test systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Feb 22 14:52:17 server-test systemd[1]: mongod.service: Unit entered failed state.
Feb 22 14:52:17 server-test systemd[1]: mongod.service: Failed with result 'exit-code'.

I have also got detailed information of each start command result in "/var/log/daemon.log". I could see the information "Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log" which was one of the clue for the issue. While checking i could see mongod.log file was under root ownership and service was starting under the user "mongodb". So applied the below fix.

fix1: -  chown mongodb:mongodb /var/log/mongodb/mongod.log

While trying to start again, i could see service showing new error this time in "daemon.log"

mongod.service: Main process exited, code=exited, status=100/n/a
mongod.service: Unit entered failed state.

This error caused as mongodb file storage location has issues and unable to access its files.

fix2.  chown -R mongodb:mongodb /var/lib/mongodb/*

See the screen shot attached. Now I am able to start the service.

enter image description here


Default, MongoDB creates the log file at this path /var/log/mongodb/mongodb.log, if the log file is not found, please check with the MongoDB config file.


Check the MongoDB config file at /etc/mongod.conf or /yourMongoDBpath/mongod.conf, the logpath defined where to log.


$ cat /etc/mongod.conf # mongod.conf

Where to store the data.

Note: if you run mongodb as a non-root user (recommended) you may need to create and set permissions for this directory manually, e.g., if the parent directory isn't mutable by the mongodb user.


where to log



For Example

Here i am mentioning one mongod.conf file with dbpath and logpath. And i shall show here how to start the mongod server as well as mongo shell.

  clusterRole: configsvr
  replSetName: repltest
  keyFile: /var/mongodb/pki/replkeyfile
  bindIp: localhost,
  port: 26001
  destination: file
  path: /var/mongodb/db/csrs1/mongod.log
  logAppend: true
  fork: true
  dbPath: /var/mongodb/db/csrs1

Then to start mongod with --fork , used the command such as

/var/mongodb/db/csrs1$ mongod -f csrs1.conf

about to fork child process, waiting until server is ready for connections. forked process: 2101 child process started successfully, parent exiting

And to start the mongo shell

mongo --port 26001

Some of the MongoDB jira blog related to error here and here.

For further your ref here and here


You will need to create your own logFile in your own directory. You can't use the existing mongod.log. If you try to write to the mongod.log file that came with the MongoDB installation, you'll get Failed to Open and Access is Denied.

If you are running Mongo on a Windows laptop, you should start it with a command similar to this:

mongod --dbpath "C:\Program Files\MongoDB\Server\4.2" --logpath "C:\MongoData\data.log"

where C:\MongoData\data.log is an empty file I created in a new directory.


In Windows OS, I had that same problem. The problem was permission of the file. Then, in file "mongod.log" in "C:\Program Files\MongoDB\Server\4.2\log" didn't have permission to write. Then, in "properties" of the file, aba "Security" in I put permission to "write".

Your Answer

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

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