6

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 
"/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...

  • Welcome to the site. The error message spells out the problem. Your MongoDB confguration file has a relative path, not an absolute path. – Md Haidar Ali Khan May 1 '18 at 3:55
  • I don't think that's the error... I ran the same mongod command, mongod --config <path-to-config-file> now with an absolute path to my config file, starting from the root directory "/". Still same error as above. – rapidDev May 1 '18 at 4:29
  • Did you checked your mongod.conf file. where it is directed to logpath. – Md Haidar Ali Khan May 1 '18 at 4:33
  • The path to the log is set to the log file I created /var/log/mongodb/mongod-config.log. So, the issue doesn't seem to be there. – rapidDev May 1 '18 at 4:43
  • ,Did you try to start mongod with port (27019) with --fork. use the --fork and --logpath options. – Md Haidar Ali Khan May 1 '18 at 5:02
3

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 
"/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 <ip_address_of_said_vm>:27019
1

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.

logpath

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

/etc/mongod.conf

$ 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.

dbpath=/var/lib/mongodb

where to log

logpath=/var/log/mongodb/mongod.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.

sharding:
  clusterRole: configsvr
replication:
  replSetName: repltest
security:
  keyFile: /var/mongodb/pki/replkeyfile
net:
  bindIp: localhost,192.168.103.100
  port: 26001
systemLog:
  destination: file
  path: /var/mongodb/db/csrs1/mongod.log
  logAppend: true
processManagement:
  fork: true
storage:
  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

0

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

0

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.txt"

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

New contributor
Steve Stilson is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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