I’m trying to setup the config servers for mongodb sharding. I created a specific config file that is set to log to
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…
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
/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:
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: Started High-performance, schema-free document-oriented database. Feb 22 14:52:17 server-test mongod: 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: mongod.service: Main process exited, code=exited, status=1/FAILURE Feb 22 14:52:17 server-test systemd: mongod.service: Unit entered failed state. Feb 22 14:52:17 server-test systemd: 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.
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
/yourMongoDBpath/mongod.conf, the logpath defined where to log.
$ cat /etc/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
Here i am mentioning one
mongod.conf file with
logpath. And i shall show here how to start the
mongod server as well as
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,
And to start the mongo shell
mongo --port 26001
Some of the MongoDB jira blog related to error 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 FilesMongoDBServer4.2" --logpath "C:MongoDatadata.log"
C:MongoDatadata.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 FilesMongoDBServer4.2log” didn’t have permission to write. Then, in “properties” of the file, aba “Security” in I put permission to “write”.