MongoDB --- Failed global initialization: Failed to open "/var/log/mongodb/mongod-config.log" 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 &lt;path-to-config-file&gt;, I get this error: 

`F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open 
"/var/log/mongodb/mongod-config.log"`


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://127.0.0.1:27019/test
2018-05-01T03:13:13.399+0000 W NETWORK  [thread1] Failed to connect to 
127.0.0.1:27019, in(checking socket for error after poll), reason: Connection 
refused
2018-05-01T03:13:13.400+0000 E QUERY    [thread1] Error: couldn't connect to 
server 127.0.0.1:27019, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
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...
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 &lt;path-to-config-file&gt;


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

F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open 
"/var/log/mongodb/mongod-config.log"


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 &lt;ip_address_of_said_vm&gt;:27019