Lab - Initiate a replica set locally

I’ve done the .conf files + launched the primary daemon and got connected with the shell to it.
Used
rs.initiate()
It worked, but gave me this “warning”:
MongoDB Enterprise > rs.initiate()
{
"info2" : “no configuration specified. Using a default configuration for the set”,
“me” : “192.168.103.100:27001”,
“ok” : 1
}

1st question: What does info2 refers to?

After this, I made the root user and it said OTHER rather than PRIMARY as shown on the next lines:
MongoDB Enterprise m103-repl:OTHER> db.createUser({user:“m103-admin”,pwd:“m103-
pass”,roles:[{role:“root”,db:“admin”}]})
Successfully added user: {
“user” : “m103-admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
But after creating the user, then it changed to PRIMARY:
MongoDB Enterprise m103-repl:PRIMARY> exit
bye

Then I reconnected to the primary this way and it allowed me to get connected. I did it by mistake but I noticed how it allowed the connection:
vagrant@m103:/var/mongodb/db$ mongo --host localhost:27001
MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27001/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“d9cc2c07-818f-463e-b20d-adb4340261f9”) }
MongoDB server version: 3.6.17
MongoDB Enterprise m103-repl:PRIMARY>

2nd question: Why does it allows to get connected with no credentials?

Then, I got connected with the credentials as shown:
MongoDB Enterprise m103-repl:PRIMARY> exit
bye
vagrant@m103:/var/mongodb/db$ mongo --host localhost:27001 -u m103-admin -p m103-pass
MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27001/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“8b644c9a-fb45-4176-b266-ded41e04fbcd”) }
MongoDB server version: 3.6.17
Server has startup warnings:
2020-03-27T15:47:09.516+0000 I STORAGE [initandlisten]
2020-03-27T15:47:09.516+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem
is strongly recommended with the WiredTiger storage engine
2020-03-27T15:47:09.516+0000 I STORAGE [initandlisten] ** See
http://dochub.mongodb.org/core/prodnotes-filesystem
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten]
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten] ** WARNING:
/sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten]
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten] ** WARNING:
/sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2020-03-27T15:47:09.969+0000 I CONTROL [initandlisten]
MongoDB Enterprise m103-repl:PRIMARY>

But I noticed that I missed the replica set’s name in the connection and the authenticationDatabase info.

3rd question Do I need to have the replica set’s name and the authenticationDatabase on or it is just a recommendation to make sure that it gets connected where I want to?

When I try to connect to the other nodes, I get this message:
MongoDB Enterprise m103-repl:PRIMARY> rs.add(“m103-repl/192.168.103.100:27002”)
{
“ok” : 0,
"errmsg" : “Quorum check failed because not enough voting nodes responded; required 2 but only
the following 1 voting nodes responded: 192.168.103.100:27001; the following nodes did not
respond affirmatively: m103-repl/192.168.103.100 failed with HostUnreachable”,

“code” : 74,
“codeName” : “NodeNotFound”,
“operationTime” : Timestamp(1585326426, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1585326426, 1),
“signature” : {
“hash” : BinData(0,“eo759/PLTUwz7dSaGmSzM3+Gh7A=”),
“keyId” : NumberLong(“6808918753653293057”)
}
}
}

I’ve checked the post of this issue in the forum and found that I do have the file /etc/hosts issue. (3rd point in the post). Here is my file:

vagrant@m103:~$ cat /etc/hosts
127.0.1.1       m103.mongodb.university m103
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1       localhost localhost.localdomain localhost6 localhost6.localdomain6
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
192.168.103.100    m103 m103

I’ve tried to modify it with VI or PICO; but in both cases, it states that this is a read only file.

4th question How can I modify the first IP to be able to connect with 192.168.103.100?

Thank you

Informational message telling you that it will create a new rs.config() because it’s a new replica set. You can safely ignore this.

Because you didn’t set authorization: enabled. However, you won’t be able to run show dbs or interact with the db.

Using mongo

  1. If you want to be connected to the Primary of the replica set, it’s recommended that you include the replica set name in the connection string
  2. If you created the user on the admin db, then you need to specify this db in the connection string. Two ways:
    • mongo admin --<other options> ...
    • mongo --authenticationDatabase admin --<other options> ...
  1. Recommended way is to do a rolling upgrade (discussed later in the course)
  2. Other way is to remove the node > check/fix the rs.config() > re-add the node
  3. Quickest way is to killall mongod > delete all data files > bring all the nodes back up again… essentially starting afresh

#1 Thank you
#2 I do have the security:authorization: enabled flag in the configuration file.
Configuration file:
net:
port: 27001
bindIp: localhost,192.168.103.100
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
storage:
dbPath: /var/mongodb/db/1
systemLog:
path: /var/mongodb/db/mongod1.log
destination: file
logAppend: true
operationProfiling:
mode: slowOp
slowOpThresholdMs: 50
processManagement:
fork: true
replication:
replSetName: m103-repl

#3 I’ll just get used to typing those parameters. Yet, my question was more on the practical side of it, if you really don’t need to specify this, but it is just better to do it.

#4 I did the 3rd option, but ended up with the same issues on the same step. I’ve checked the /etc/hosts file, and it is exactly as it was last time. BTW, I only rm /var/mongodb/db/(1, 2 & 3), not the file in /etc/hosts, do I need to remove it and redo the 3rd step?

Thank you for your help and fast response!

#2 The other scenario is you connected before creating the first user

#3 That’s why I started my answers using “if” and I stated the word “recommended” where it was recommended. As with authenticationDatabase, it’s always better to be explicit than implicit.

#4 Please go through this post

I read the whole post and what worked for me is to use this code:
rs.add(“192.168.103.100:27002”)
That way, it worked. I wonder why if I add the replica set’s name, it doen’t work. I double checked my .conf files and the three of them have the value
replication:
replSetName: m103-repl

Should I continue on or this is an issue that must be addressed?

Thanks again!!

It worked because it’s the correct syntax. Replica set name should not be part of rs.add()

Perfect.

Then it is all set!

Thank you for your time.

:slightly_smiling_face: :+1:

Closing this thread as the issue has been resolved.