Can't start mongod for homework chapter2: mongod --config /etc/mongod-repl-1.conf

Hi,
I copied /etc/mongod.conf and edit to have /etc/mongod-repl-1.conf
&&& mongod-repl-1.cong &&&&
storage:
dbPath: /var/mongodb/db/1
systemLog:
destination: file
logAppend: true
path: /var/mongodb/db/mongod1.log
net:
port: 27001
bindIp: localhost,192.168.103.100
replication:
replSetName: m103-repl

security:
keyfile: /var/mongodb/pki/103-keyfile

and run the command:

mongod --config /etc/mongod-repl-1.conf

There is no error but mongod doesn’t start (I checked ps -ef| grep mongod, and there is no “mongod”)
Please help,
many thanks,

That’s because all the errors go into the log file you specified :wink:

path: /var/mongodb/db/mongod1.log

Check that file for the deets :slight_smile:

Hi denguyen,

Please check log file as @Tess_Sluijter suggested. It would be very tough to tell what is causing the issue without looking at the error message.

Possible cause:

  • You forgot to create db directory: /var/mongodb/db/1 . If yes, create one.
  • If you have created the directory, then make sure it has right permission to access. chown command will be the right way to change permission.
  • No other mongod is running and port 27001 is free.
  • /var/mongodb/pki/103-keyfile path or permission may not be correct for this.

Let me know!

Kanika

Hi Kanakasingla & Tess_Sluijter,
Thank you for your precious help. I deleted all my recent-created configuration files, go back to very first step, create new configuration files from scratch (last time I copied from the existing mongod.conf). It worked now.
Once again , thank you, both of you.
Denguyen

1 Like

Glad you got it working denguyen!

Happy Learning, Kanika

how to check this .log file ?
And,if there is error how to correct it.

Thank you

I checked your post and glad that our TA help you solve the issue.
To check .log file, I just use command, for example, "cat /var/mongodb/mongod1.log ", and look for error messages.

From my limited experience:
For example, when I use the command: rs.add(“m103”), there were a lot of errors: "Failed to connect to m103:27017 - HostUnreachable : Connection refused. The reason is that I forget to mention the correct port (2700X), and the default port 27017 would be used.

To be honest, error messages are not always helpful, especially, the option errors. I did get ( --dbPath option like yours). I think most of the times because of the tricky YAML format (it doesn’t like the TAB)

Regards,

On Linux it’s as simple as running “cat /var/log/mongod.log”, or whichever file you configured. “cat” will throw the whole file onto the output, so you’ll have to check only the last few lines. An easier approach would be “tail -20 /var/logmongod.log” or one of the many many other ways to do things on Linux :slight_smile: