Could not add the replica set to the primary

Processes forked and running successfully

vagrant@m103:~$ ps -ef | grep mongod
vagrant 2047 1 1 09:45 ? 00:00:29 mongod -f node1.conf
vagrant 2081 1 0 09:46 ? 00:00:14 mongod -f node2.conf
vagrant 2115 1 0 09:46 ? 00:00:14 mongod -f node3.conf
vagrant 2456 2426 0 10:23 pts/2 00:00:00 grep --color=auto mongod

While adding replica set from PRIMARY connected shell

MongoDB Enterprise m103-example:PRIMARY> rs.add(“m103.mongodb.university:27002”,“m103.mongodb.university:27003”)
{
“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: m102.mongodb.university:27002 failed with HostUnreachable”,
“code” : 74,
“codeName” : “NodeNotFound”,
“operationTime” : Timestamp(1572084339, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1572084339, 1),
“signature” : {
“hash” : BinData(0,“be6SeCSkv8cm3rPao9RY92tMjw0=”),
“keyId” : NumberLong(“6752046141044424705”)
}
}
}

Replica set is master.

MongoDB Enterprise m103-example:PRIMARY> rs.isMaster()
{
“hosts” : [
“192.168.103.100:27001”
],
“setName” : “m103-example”,
“setVersion” : 1,
“ismaster” : true,
“secondary” : false,
“primary” : “192.168.103.100:27001”,
“me” : “192.168.103.100:27001”,
“electionId” : ObjectId(“7fffffff0000000000000001”),
“lastWrite” : {
“opTime” : {
“ts” : Timestamp(1572084360, 1),
“t” : NumberLong(1)
},
“lastWriteDate” : ISODate(“2019-10-26T10:06:00Z”),
“majorityOpTime” : {
“ts” : Timestamp(1572084360, 1),
“t” : NumberLong(1)
},
“majorityWriteDate” : ISODate(“2019-10-26T10:06:00Z”)
},
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 100000,
“localTime” : ISODate(“2019-10-26T10:06:18.058Z”),
“logicalSessionTimeoutMinutes” : 30,
“minWireVersion” : 0,
“maxWireVersion” : 6,
“readOnly” : false,
“ok” : 1,
“operationTime” : Timestamp(1572084360, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1572084360, 1),
“signature” : {
“hash” : BinData(0,“TmVcV0/j2qR9XFANwfDV4TgDbPY=”),
“keyId” : NumberLong(“6752046141044424705”)
}
}
}

Looks like there is a typo
Please check your node2-m102.mongodb.university

I double checked it, but I am getting the same errormsg

Why this error?

the following nodes did not respond affirmatively: m102.mongodb.university:27002 failed with HostUnreachable”

Did you run rs.initiate()
What does rs.status() show

Initiate

MongoDB Enterprise m103-example:PRIMARY> rs.initiate()
{
“info2” : “no configuration specified. Using a default configuration for the set”,
“me” : “192.168.103.100:27001”,
“info” : “try querying local.system.replset to see current configuration”,
“ok” : 0,
“errmsg” : “already initialized”,
“code” : 23,
“codeName” : “AlreadyInitialized”,
“operationTime” : Timestamp(1572087120, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1572087120, 1),
“signature” : {
“hash” : BinData(0,“k7AK7YvLJvCL8LE5XxOXwdPSQXw=”),
“keyId” : NumberLong(“6752046141044424705”)
}
}
}

Status

MongoDB Enterprise m103-example:PRIMARY> rs.status()
{
“set” : “m103-example”,
“date” : ISODate(“2019-10-26T10:52:52.935Z”),
“myState” : 1,
“term” : NumberLong(1),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1572087170, 1),
“t” : NumberLong(1)
},
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1572087170, 1),
“t” : NumberLong(1)
},
“appliedOpTime” : {
“ts” : Timestamp(1572087170, 1),
“t” : NumberLong(1)
},
“durableOpTime” : {
“ts” : Timestamp(1572087170, 1),
“t” : NumberLong(1)
}
},
“members” : [
{
“_id” : 0,
“name” : “192.168.103.100:27001”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 4013,
“optime” : {
“ts” : Timestamp(1572087170, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2019-10-26T10:52:50Z”),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1572083248, 2),
“electionDate” : ISODate(“2019-10-26T09:47:28Z”),
“configVersion” : 1,
“self” : true,
“lastHeartbeatMessage” : “”
}
],
“ok” : 1,
“operationTime” : Timestamp(1572087170, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1572087170, 1),
“signature” : {
“hash” : BinData(0,“Hcw8g0rKt2Js74Ll+x2cbCj1ri8=”),
“keyId” : NumberLong(“6752046141044424705”)
}
}
}

Are you using correct config parameter values?
Please check your replsetname
Your port number and replsetname should be exactly same as per lab requirements
Looks like you have some mixup

Add it one after another or use an array of member documents. If you try to add like above, you will end up with one node being an arbiter because the second parameter is a boolean value for arbiter.

To add to what @Ramachandra_37567 said, I don’t think that you’ve mapped m103.mongodb.university to the correct IP address because your rs.status() is using IP and the error message is 192 instead of 193. Look at your /etc/host/ file also.

This is hosts file, I don’t understand why this file is related

How do I map m103.mongodb.university?

vagrant@m103:/etc$ cat hosts
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

You should have one more entry for loopback mapped to your host
Did you edit the file and remove any entries?

127.0.0.1 m103.mongodb.university m103

Why is node2 and node3 (authentication: enabled) attribute is not present in conf file?

I have edited the conf of node2 and node3 file
i.e I removed authentication: enabled

I went according to the lecture notes but I got some info on rs.initiate()

MongoDB Enterprise > rs.initiate()
{
“info2” : “no configuration specified. Using a default configuration for the set”,
“me” : “192.168.103.100:27011”,
“ok” : 1
}

and after this i got OTHER, can anyone explain why?
I am making wrong please let me know

MongoDB Enterprise m103-example:OTHER>

MongoDB Enterprise m103-example:PRIMARY> rs.add(“m103.mongodb.university:27012”)
{
“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:27011; the following nodes did not respond affirmatively: m103.mongodb.university:27012 failed with HostUnreachable”,
“code” : 74,
“codeName” : “NodeNotFound”,
“operationTime” : Timestamp(1572094033, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1572094033, 1),
“signature” : {
“hash” : BinData(0,“8drDtukJKSAliUJSiEnr4kTnj3I=”),
“keyId” : NumberLong(“6752088588206211074”)
}
}
}

I am following lecture

It’s fine. The primary is just initiating. Hit Enter a few times and it’ll change.

By the way, are you following the lecture or is this for the lab?

I am following Lecture but I am not able to add

MongoDB Enterprise m103-example:PRIMARY> rs.add(“m103.mongodb.university:27012”)
{
“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:27011; the following nodes did not respond affirmatively: m103.mongodb.university:27012 failed with HostUnreachable”,
“code” : 74,
“codeName” : “NodeNotFound”,
“operationTime” : Timestamp(1572094033, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1572094033, 1),
“signature” : {
“hash” : BinData(0,“8drDtukJKSAliUJSiEnr4kTnj3I=”),
“keyId” : NumberLong(“6752088588206211074”)
}
}
}

When I try to add I am not able to

Add it using the IP address instead. Once you’ve figured out why the domain name isn’t working, then switch over.

Also note what @Ramachandra_37567 said.

Is there any conf file to edit like rsconf

Work using localhost or 127.0.0.1 until you resolve the domain name issue.

Steps I followed to solve the issue

  1. Preparing 3 config files under which 1 conf file must have

authentication: enabled

let us consider node1

rest 2 conf files do not specify authentication enabled

  1. Running all 3 mongod process

mongod -f node1.conf

mongod -f node2.conf

mongod -f node3.conf

  1. check the forked process running successfully

vagrant@m103:~$ ps -e |grep mongod
4947 ? 00:00:40 mongod
5043 ? 00:00:28 mongod
5073 ? 00:00:27 mongod

4947 5043 and 5073 are the forked process running successfully

  1. Connect, Initiate, Switch to admin, Create user, and exit

vagrant@m103:~$ mongo --host “127.0.0.1:27011”

MongoDB Enterprise > rs.initiate()

MongoDB Enterprise m103-example:PRIMARY> use admin

MongoDB Enterprise m103-example:PRIMARY> db.auth(“m103-admin”,“m103-pass”)

MongoDB Enterprise m103-example:PRIMARY> db.createUser({
… user: “m103-admin”,
… pwd: “m103-pass”,
… roles: [{role: “root”,db: “admin”}]
… })

exit

  1. Connect Mongo to the localhost with the authentication enabled port like below

vagrant@m103:~$ mongo --host “127.0.0.1:27011” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

  1. check the status

rs.status()

you should find a member in the menbers array with attritube

“stateSte”: “PRIMARY”

  1. Add replica set

Adding rs on port 27012 with IP 192.168.103.100

MongoDB Enterprise m103-example:PRIMARY> rs.add(“192.168.103.100:27012”)

Adding rs on port 27013 with IP 192.168.103.100

MongoDB Enterprise m103-example:PRIMARY> rs.add(“192.168.103.100:27013”)

@Rakshith_79674 I’m glad that you eventually setup a working replica set.

But for clarity, I want to elaborate on the problems you originally had which has only been partially solved.
image

  1. The domain name m103.mongodb.university isn’t mapped in your /etc/hosts file which is what we kept alluding to. And unfortunately, the lecture doesn’t mention this because it assumes that the vagrant provision file mapped it correctly, but it didn’t.
    As you can see, the /etc/hosts file it’s actually mapped m103 instead of the full m103.mongodb.university host name that was used in the lecture. I’ve now raised this problem to the Curriculum Engineers to fix.
    Therefore, as it stands, if you had used rs.add("m103:27002"), it will also have worked because m103 was already mapped to the IP that you’re binding to!
    Furthermore, if you edit your /etc/hosts file as follows:
    image
    Then you will be able to use the full domain name like so:
    rs.add("m103.mongodb.university:27002")
    Suggest you read more on /etc/hosts to understand how a Fully Qualified Domain Name is resolved to an IP.

  2. The format of rs.add is rs.add("host", arbiterOnly).
    From the screenshot above, the second parameter was wrong because it resulted in a boolean value of true. If your command was successful (which it thankfully wasn’t), you would have ended up with an Arbiter node instead of a Secondary. But I can see that you silently acknowledged this from your recent posts so this part was solved.

I hope this clears up the confusion.

2 Likes

Hi Rakshith_79674
Good that you are able to resolve the issue but i don’t think authentication parameter in other 2 nodes was the issue
It is hostname vs IP resolution issues
I asked you if you edited /etc/hosts file but you replied about editing config file
If you add an entry as below your rs.add works even with hostname

127.0.0.1 m103.mongodb.university m103

1 Like