Deploy a replica set: did I miss something?

Did i miss a step here? I connected successfully to the mongod, but when I try rs.initiate() I get no output:

image

Update: after 20 minutes, it finally output syntax error: unexpected end of file

Are your 3 mongods up and running?

You have to run the rs.initiate() at mongo prompt not at os/terminal prompt

I understand now about starting up all three mongods. But I only see one kind of prompt.

the prompt bash-4.4# is the bash shell prompt, the mongo shell prompt, when connected to a replica set will print the set name.

Well, it keeps refusing the connection. I use, per the previous lesson:

mongo --host localhost
or:
mongo --port 27001
or, thinking that perhaps the root user already exists:
mongo admin -u “m103-admin” -p “m103-pass” --port 27001

But it always refuses the connection.
The full output is:

connecting to: mongodb://127.0.0.1:27001/?gssapiServiceName=mongodb
2020-09-13T20:38:52.855+0000 E QUERY [js] Error: couldn’t connect to server 127.0.0.1:27001, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27001 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:328:13
@(connect):1:6
exception: connect failed

If you think root user exists connect with that user authenticating against admin DB

We need to see if the mongod are running. Please provide the output of

ps -aef | grep [m]ongo

There is no output. It just gives me the same prompt again.

The complete trace is:
sh-4.4# mongod --port 27003
2020-09-14T21:45:09.406+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’
2020-09-14T21:45:09.412+0000 I CONTROL [initandlisten] MongoDB starting : pid=346 port=27003 dbpath=/data/db 64-bit host=YwzEsP3LBCnylJHyAF
2020-09-14T21:45:09.412+0000 I CONTROL [initandlisten] db version v4.0.5
2020-09-14T21:45:09.412+0000 I CONTROL [initandlisten] git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] allocator: system
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] modules: none
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] build environment:
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] distarch: x86_64
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] target_arch: x86_64
2020-09-14T21:45:09.413+0000 I CONTROL [initandlisten] options: { net: { port: 27003 } }
2020-09-14T21:45:09.453+0000 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2020-09-14T21:45:09.453+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets…
2020-09-14T21:45:09.453+0000 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27003.sock
2020-09-14T21:45:09.453+0000 I CONTROL [initandlisten] now exiting
2020-09-14T21:45:09.454+0000 I CONTROL [initandlisten] shutting down with code:100
sh-4.4# ps -aef | grep [m]ongo
sh-4.4#

It means you have no mongod running.

You are supposed to start the 3 mongod processes with the configuration files.

Well, I did that, but still a similar problem as before. I started the mongods with the config files, I connected to one of them with mongo --port 27001. I succeeded in switching to use admin. But then the attempt to create user threw error message:

2020-09-15T15:08:52.155+0000 E QUERY [js] Error: couldn’t add user: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1491:15

And, thinking that maybe it was because that user already existed, I tried rs.initiate() anyway, which resulted in:

rs.initiate()
{
“info2” : “no configuration specified. Using a default configuration for the set”,
“me” : “localhost:27001”,
“ok” : 1
}
m103-repl:OTHER>

I know this cannot be right because where the word OTHER appears, the instructions say is supposed to say PRIMARY.

but the error was

Please provide a screenshot of

and the output of

ps -aef | grep [m]ongo

I think if you exit the mongo shell and re-enter it should now say PRIMARY. May be a couple of [ENTER] will also do.

rs.initiate() still outputs OTHER.

Also, one thing about your instructions confuses me. You have been telling me to start all three mongod processes. The written instructions for the lab say to start just one, then rs.initiate(), then create the admin user, and then start up the other two mongod processes. Which way is correct?

Correct
Instructions say start first mongod and do the rs.initiate()
It should work with first mongod also
For a brief period it shows other and becomes primary

May be this port was used to initiate another replicaset
What does it show if you run again rs.initiate()?
What does rs.status() show
Best thing is to kill all mongods ,remove dirs and repeat the lab fresh

Okay, thank you. But it looks like I’m going to need to start a new thread, because now I have a new problem…

Closing this thread as the original issue has been resolved.