Lab: Configuration File - Start mongod with config file

Hi, I am having some issues with the second lab, Configuration File.

This is what my file structure looks like right now within my Vagrant VM:
terminal

This is my mongod.conf file:

storage:
  dbPath: "/data/db"
systemLog:
  path: "/data/db/mongod.log"
  destination: "file"
  logAppend: true
net:
  port: 27000
  bindIp: "192.168.103.100,127.0.0.1"
security:
  authorization: enabled

Now, when I run my config file, I don’t get any results saying that it was an error or a success. But when I run the validate_lab_configuration_file command, this is the error I get:
terminal2

I’ve been tinkering with it but I have had no success whatsoever. Does anyone know what might be wrong?

1 Like

Where are you storing your configuration file?

Mine goes as this:

net:
   bindIp: "192.168.103.100,localhost"
   port: 27000
security:
   authorization: enabled
storage:
   dbPath: "/data/db"

No idea about how to enable authentication; cannot find it in Mongo docs, so I have copied your lines regarding authorization.

I have saved the file with a .yaml extension, so its name is mongod.conf.yaml… Is that OK? And where do I have to save it? users/my_name/m103?

And I get:

vagrant@m103:~$ mongod --config mongod.conf
Error reading config file: No such file or directory

It doesn’t mind if I try with mongod.conf.yaml or if I remove the .yaml extension from the file name.

I do not have an answer to your problem, by the way… I’m lost as usual. Lab instructions are quite cryptic.

1 Like

Hi @Jonathan_96839,

It looks like your mongod process is not started. Please check that your configuration file follows the YAML file specification and also try to launch your mongod using the following command:

mongod --config mongod.conf

You can check if mongod is running, using the following command:

ps -ef | grep mongod

Then you can run the validation script.

Please let me know, if you have any doubts.

Thanks,
Sonali

OK, I had to store the file without the .yaml extension in the shared directory of Vagrant and everything worked.

1 Like

In the second screenshot I provided, I do execute the mongod --config mongod.conf command. It’s just that the mongo process does not start. I know my path is correct as you can see in my second screenshot. I typed ls to show the different files and folders in my home directory and my mongod.conf is there.

I took a look at your config file and copied it to see if that worked and it did. It just doesn’t fork the process. So I had to open a new terminal and run the validation command and it worked! So, I think you are on the right track! I just need to know how to fork the process.

To fork the process, add the command line argument --fork to the mongod command.

Alternatively you can add this to the configuration file (this comes up in a later lab)

processManagement:
  fork: true

In both cases you need to also specify a log file path in order to fork the process, because a background process can’t write its output to the screen. This comes up in a later lab too, so don’t worry about it too much for the moment, but you can read about it here:

https://docs.mongodb.com/manual/reference/configuration-options/#processManagement.fork

and

https://docs.mongodb.com/manual/reference/configuration-options/#systemlog-options

Great, I added that and now we are smooth sailing! Thanks.

In the long run, I still don’t know what was wrong. But the only thing I notice is that the order of my mongod.conf settings are different. Same properties and values, just in different orders. I wonder if that has an influence.

Glad to hear you’re up and running now :slight_smile:

I don’t think the order of the sections and values (which probably isn’t the correct terminology, I’m just a fellow student, and YAML is new to me) in the config file is significant, as long as the right values are in the right sections. For example, I noticed after completing a lab and it had been passed by the validation script, that I actually had two net: sections

net:
  port: 27000

and then some other stuff, and then

net:
  bindIp: "192.168.103.100,localhost"

And it still worked.

In a tidy configuration file, I’d have put the port: and bindIp: values into a single net: section (and I did in later labs, once I’d spotted this), but it seems that as long as the child elements have the right parent elements (yes, I’m using XML terminology now, which probably isn’t correct for YAML either, but bear with me), everthing seems to work, even if the config file is a bit untidy.

But like I said, I’m not an expert, so I’d be interested to hear what the experts have to say on the subject of ordering the contents of a config file.

My issue is very similar to the one above.

  1. agrant@m103:/data/db$ mongod --config /data/db/mongod.conf
    vagrant@m103:/data/db$

  2. vagrant@m103:/data/db$ validate_lab_launch_mongod

Client experienced a timeout when connecting to the database - check that mongod is running on the correct port, and that your user was created with the correct settings.

  1. inside my file is the following

storage:
dbPath: “/data/db”
systemLog:
path: “/data/db/mongod.log”
destination: “file”
logAppend: true
net:
port: 27000
bindIp: “192.168.103.100,127.0.0.1”
security:
authorization: enabled

Does anyone have an idea what i may be missing? Thanks.

Hi James_68753

Is mongod up and running on port 27000?
ps -ef|grep mongod

Did you create the m103-admin user?
If yes are you able to connect to DB using this user?
Also make sure your local host mapping to 127.0.0.1
ping localhost

@Ramachandra_37567 mongoDB is running

vagrant@m103:/data/db$ ps -ef | grep -i mongod
vagrant 5300 3377 0 14:33 pts/0 00:00:38 mongod
vagrant 5852 2752 0 16:13 pts/3 00:00:00 grep --color=auto -i mongod

User already exists from other section

MongoDB Enterprise > db.getUsers()
[
{
“_id” : “test.m103-admin”,
“user” : “m103-admin”,
“db” : “test”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
]

  1. where do I verify that? in /etc?

@Ramachandra_37567

Heres where the config file lives:
/data/db config file name is mongod.conf

storage:
dbPath: “/data/db”
systemLog:
path: “/data/db/mongod.log”
destination: “file”
logAppend: true
net:
port: 27000
bindIp: “192.168.103.100,localhost”
security:
authorization: enabled
processManagement:
fork: true

I just added forking and am receiving a new area

vagrant@m103:/data/db$ mongod --config /data/db/mongod.conf

Unrecognized option: security.fork

try ‘mongod --help’ for more information

vagrant@m103:/data/db$

Your user is not created in admin
It shows DB as test
You should be in admin DB when creating m103-admin user
How did you connect to mongod?

For local host just run this

vagrant@m103:/var/mongodb/db$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.

Seems indentation issue to me for fork error
Make sure fork is moved to right under processManagement

1 Like

Unfortunately you’ve provided the content of the config file without its indentation:

If I’ve understood the YAML specification correctly then indentation is significant. Unlike JSON, there are no commas or curly brackets to help define what is a child or sibling of what else, instead this is all controlled by the indentation.

Your error message…

Unrecognized option: security.fork

… appears to be saying that your config file has been interpreted as having a fork element within a security element, when it should be within a processManagement element.

If you post content from a config file here, it’s probably best to highlight it and then use the image button to render it as pre-formatted text in your post. That way it’ll look like this:

processManagement:
  fork: true
replication:
  replSetName: m103-example

… which will make it much easier for us to spot indentation issues.

MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.getUsers()
[
{
“_id” : “admin.m103-admin”,
“user” : “m103-admin”,
“db” : “admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
]

MongoDB Enterprise >

vagrant@m103:/data/db$ ping localhost

PING localhost (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.023 ms

64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.039 ms

64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.034 ms

64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.031 ms

64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.053 ms

64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.027 ms

64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.060 ms

64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.016 ms

64 bytes from localhost (127.0.0.1): icmp_seq=9 ttl=64 time=0.081 ms

64 bytes from localhost (127.0.0.1): icmp_seq=10 ttl=64 time=0.066 ms

64 bytes from localhost (127.0.0.1): icmp_seq=11 ttl=64 time=0.025 ms

64 bytes from localhost (127.0.0.1): icmp_seq=12 ttl=64 time=0.072 ms

Its pingable and this time i was the admin as above. Still same error

@Simon_39939 should of posted screenshot here. sorry

@James_68753 that’s quite a large screenshot, and the interesting text is only a small part of it. I can’t actually read it because the text is so small :frowning:

Please familiarise yourself with the image button, it’ll make life easier for all of us in the long run :slight_smile:

storage:
  dbPath: "/data/db"
systemLog:
  path: "/data/db/mongod.log"
  destination: "file"
  logAppend: true
net:
  port: 27000
  bindIp: "192.168.103.100,localhost"
security:
  authorization: enabled
processManagement:
  fork: true

is this better?