Lab 3.1. Configure a Sharded Cluster: connecting to secondary node after updating .conf files

Hi there again:

I’m at this point:

How do I get this?

image

Cause after quitting mongos, I get this:

vagrant@m103:~$

So when I try to start a secondary node:

vagrant@m103:~$ mongo --port 27002 -u m103-admin -p m103-pass --authenticationDatabase admin

MongoDB shell version v3.6.14
connecting to: mongodb://127.0.0.1:27002/?authSource=admin&gssapiServiceName=mongodb
2019-11-28T12:04:33.323+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27002, in(checking socket for error after poll), reason: Connection refused
2019-11-28T12:04:33.323+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27002, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

It doesn’t work.

This has no relation to the error message you’re getting. This is the current working directory that the Curriculum Engineer was using right from the beginning of the lecture. You wouldn’t have gotten halfway through if this was the issue.

If you recall from your recent post, this was the same error message that you received. And in there, we explained why you received the error message and also stated that mongo is simply for login in, it doesn’t run/start/initiate any nodes.

Hi @JavierBlanco,

As @007_jb mentioned, you are getting the error because most likely you do not have a mongod instance running on the port 27002 at the time of running the mongo command.

In conclusion - before you run any mongo command, you need to make sure that the mongod process is up and running.

The first prompt just says that current working directory is sharding. For instance, you have a /shared directory inside your vagrant environment. If you run this command :

cd /shared

Your, prompt will change to this vagrant@m103:/shared$.

Hope it helps!

If you still have any other query then please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Sorry about my lame questions, using the CMD is like arcane sorcery for me.

OK, here we go again, it seems it’s impossible to take two steps in a row:

vagrant@m103:~$ mongod --config /shared/mongod-repl-2.conf

about to fork child process, waiting until server is ready for connections.
forked process: 2298
ERROR: child process failed, exited with error number 100
To see additional information in this output, start without the "--fork" option.

Different error message… you’re making progress!

Next, do what it says above in order to get more info about what’s wrong. Do this in your config file.

1 Like

If I delete this from the mongod-repl-2.conf:

processManagement:
  fork: true

Then I get no output:

vagrant@m103:~$ mongod --config /shared/mongod-repl-2.conf

vagrant@m103:~$

Have a look in the log file itself.
Or take out path under systemlog in the config file. That way, you can see the error message on the console.

2019-11-29T12:14:23.566+0000 I CONTROL  [main] ***** SERVER RESTARTED *****
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] MongoDB starting : pid=2513 port=27002 dbpath=/var/mongodb/db/node2 64-bit host=m103
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] db version v3.6.14
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] git version: cbef87692475857c7ee6e764c8f5104b39c342a1
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] modules: enterprise
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] build environment:
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten]     distmod: ubuntu1404
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten]     distarch: x86_64
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] options: { config: "/shared/mongod-repl-2.conf", net: { bindIp: "localhost,192.168.103.10$2019-11-29T12:14:23.581+0000 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /var/mongodb/db/node2 not fou$2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] now exiting
2019-11-29T12:14:23.581+0000 I CONTROL  [initandlisten] shutting down with code:100

OK, do I have to create new directories -again- after modifying .confs?

OK, I created them, run mongod, but now it doesn’t connect to the shell. This is very annoying.

vagrant@m103:/$ mongo --port 27002 --username m103-admin --password m103-pass --authenticationDatabase admin

MongoDB shell version v3.6.14
connecting to: mongodb://127.0.0.1:27002/?authSource=admin&gssapiServiceName=mongodb
2019-11-29T12:22:14.290+0000 E QUERY    [thread1] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

By the way, are you following the videos or just the Lecture Instructions in text? The videos are more comprehensive and sometimes there are things mentioned there that are not in the Lecture Instructions.

In the video I think he doesn’t even run mongod, he connects to the shell directly.

I don’t follow either.
Perhaps it’s just a matter of terminology, but mongod doesn’t connect to the shell. So what exactly is failing and what is the error message?

Remember what happens when you run mongod without fork? What happens to the terminal?

Let’s see the screenshot of the successful run of mongod

Nothing, I get no output.

From the log:

2019-11-29T12:14:23.581+0000 I CONTROL [initandlisten] options: { config: "/shared/mongod-repl-2.conf", net: { bindIp: "localhost,192.168.103.10$2019-11-29T12:14:23.581+0000 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /var/mongodb/db/node2 not fou$2019-11-29T12:14:23.581+0000 I CONTROL [initandlisten] now exiting

So I created new directories:

mkdir /var/mongodb/db/{node1,node2,node3}

And succesfully run mongod:

vagrant@m103:/$ mongod --config /shared/mongod-repl-2.conf

about to fork child process, waiting until server is ready for connections.
forked process: 2557
child process started successfully, parent exiting

But now it doesn’t connect to the shell, something about authentication.

It’s saying that the username/password combination is wrong. Can you connect to node1 with the same username and password?
Let’s see ps -ef | grep [m]ongo

No, it fails too.

vagrant@m103:/$ ps -ef | grep [m]ongo

vagrant   1971     1  1 11:46 ?        00:00:36 mongod --config /shared/mongod-csrs-1.conf
vagrant   2054     1  1 11:46 ?        00:00:35 mongod --config /shared/mongod-csrs-2.conf
vagrant   2151     1  1 11:46 ?        00:00:40 mongod --config /shared/mongod-csrs-3.conf
vagrant   2257     1  0 11:50 ?        00:00:06 mongos --config /shared/mongos.conf
vagrant   2557     1  0 12:22 ?        00:00:06 mongod --config /shared/mongod-repl-2.conf
vagrant   2639     1  2 12:37 ?        00:00:00 mongod --config /shared/mongod-repl-1.conf

It doens’t appear mongod-repl-3.conf, is it normal?

From the shared directory:

image

Because you haven’t run mongod on node3 yet.

It’s a wrong username/password combination or it was created on the wrong database.
What about this? What do you get?
mongo --port 27002 --username m103-admin --password m103-pass --authenticationDatabase test