Lab 1: Can't add replica

Hello. I can’t add replicas
My mongod-repl-1.conf:

net:
    port: 27001
    bindIp: 127.0.0.1,192.168.103.100
storage:
    dbPath: /var/mongodb/db/1
security:
    authorization: "enabled"
    keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
    destination: "file"
    path: /var/mongodb/db/mongod1.log
    logAppend: true
processManagement:
    fork: true
replication:
    replSetName: m103-repl

My steps according to the point lists from here https://university.mongodb.com/mercury/M103/2020_January_21/chapter/Chapter_2_Replication/lesson/5a4d32d779235b109001c7a4/problem :
2. mongo --host localhost:27001 -u m103-admin -p m103-pass --authenticationDatabase admin
3. 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(1579784531, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1579784531, 1),
		"signature" : {
			"hash" : BinData(0,"qvPnyt+wLj2ZWzlAwoJkjNzB1Lg="),
			"keyId" : NumberLong("6785111754226532353")
		}
	}
}
  1. rs.status()
MongoDB Enterprise m103-repl:PRIMARY> rs.status()
{
	"set" : "m103-repl",
	"date" : ISODate("2020-01-23T13:03:18.947Z"),
	"myState" : 1,
	"term" : NumberLong(6),
	"syncingTo" : "",
	"syncSourceHost" : "",
	"syncSourceId" : -1,
	"heartbeatIntervalMillis" : NumberLong(2000),
	"optimes" : {
		"lastCommittedOpTime" : {
			"ts" : Timestamp(1579784591, 1),
			"t" : NumberLong(6)
		},
		"readConcernMajorityOpTime" : {
			"ts" : Timestamp(1579784591, 1),
			"t" : NumberLong(6)
		},
		"appliedOpTime" : {
			"ts" : Timestamp(1579784591, 1),
			"t" : NumberLong(6)
		},
		"durableOpTime" : {
			"ts" : Timestamp(1579784591, 1),
			"t" : NumberLong(6)
		}
	},
	"members" : [
		{
			"_id" : 0,
			"name" : "192.168.103.100:27001",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 439,
			"optime" : {
				"ts" : Timestamp(1579784591, 1),
				"t" : NumberLong(6)
			},
			"optimeDate" : ISODate("2020-01-23T13:03:11Z"),
			"syncingTo" : "",
			"syncSourceHost" : "",
			"syncSourceId" : -1,
			"infoMessage" : "",
			"electionTime" : Timestamp(1579784160, 1),
			"electionDate" : ISODate("2020-01-23T12:56:00Z"),
			"configVersion" : 1,
			"self" : true,
			"lastHeartbeatMessage" : ""
		}
	],
	"ok" : 1,
	"operationTime" : Timestamp(1579784591, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1579784591, 1),
		"signature" : {
			"hash" : BinData(0,"KgzaZsVN7Z7c9nt6JTQcuc65t6w="),
			"keyId" : NumberLong("6785111754226532353")
		}
	}
}
  1. mongo --host "192.168.103.100:27011" -u "m103-admin" -p "m103-pass" --authenticationDatabase admin
MongoDB Enterprise m103-repl:PRIMARY> rs.add("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: 192.168.103.100:27002 failed with not authorized on admin to execute command { replSetHeartbeat: \"m103-repl\", configVersion: 2, hbv: 1, from: \"192.168.103.100:27001\", fromId: 0, term: 6, $replData: 1, $clusterTime: { clusterTime: Timestamp(1579784781, 1), signature: { hash: BinData(0, F7E5DB3FAA75F9A35EB9FA7852A0C71A424495F8), keyId: 6785111754226532353 } }, $db: \"admin\" }",
	"code" : 74,
	"codeName" : "NodeNotFound",
	"operationTime" : Timestamp(1579784781, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1579784781, 1),
		"signature" : {
			"hash" : BinData(0,"9+XbP6p1+aNeufp4UqDHGkJElfg="),
			"keyId" : NumberLong("6785111754226532353")
		}
	}
}

if I change the address from 192… to localhost:

MongoDB Enterprise m103-repl:PRIMARY> rs.add("127.0.0.1:27002")
{
	"ok" : 0,
	"errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2",
	"code" : 103,
	"codeName" : "NewReplicaSetConfigurationIncompatible",
	"operationTime" : Timestamp(1579784811, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1579784811, 1),
		"signature" : {
			"hash" : BinData(0,"VwGZe1bim0lG21QiwuEbKLiOB6M="),
			"keyId" : NumberLong("6785111754226532353")
		}
	}
}

I’ve modified my etc/hosts:

vagrant@m103:~$ cat /etc/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.mongodb.university m103

Please check your steps again.May be some mixup of ports,replicas
Before you run rs.add() make sure all 3 nodes are up and running
ps -ef|grep mongo

After rs.initiate() add other two nodes in the same session
At step 6 why you connected to port 27011
Best thing is to repeat from scratch instead of debugging

1 Like

How to start it’s from the scratch properly since it keeps the current state.
Just log out from vagrant and log in?

Couple of things…

As it says, the host names must match with the Primary. You can’t add a localhost (127.0.0.1) node to the replica set if your Primary is on 192.168.103.100 (as can be seen in rs.status())

In this scenario you’re using IP addresses so the /etc/hosts/ file is not related.

  1. The error message indicates an authorisation problem on the second node 27002. But as @Ramachandra_37567 pointed out you’re connected to 27011 instead of 27001.
  2. He also mentioned that you should run ps -ef | grep [m]ongod to ensure that all the instances are running
  3. Lastly, log in to the 27002 to ensure that you can authenticate on the admin db:
    mongo --host "192.168.103.100:27002" -u "m103-admin" -p "m103-pass" --authenticationDatabase admin

NB: Please edit your original post and remove any potential answers to the lab

Hi @todor.ilya,

As I can see, you have successfully completed this lab. Please feel free to get back to us if you have any other query.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

Yeah, I have a question: How to start it’s from the scratch properly since it keeps the current state?
Just log out from vagrant and log in?

Hi @todor.ilya,

In general, when someone asks you to start from scratch they basically mean -> delete the directories -> recreate it again -> follow the instructions mentioned in the labs/lecture notes from beginning.

No, the above mentioned points.

Hope it helps. Please let me know if you still have any question.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

What directories? The db directory?

Yes dbpath dir ,logpath dir(in case you are using a different location) and keyfile path
Basically you are going to start clean