Could not add the replica set to the primary

Sorry I did not reply to /etc/hosts, I did not edit hosts file but I used to have

127.0.0.1 m103 m103

I have no idea why they were recorded, and the myth behind these files in Linux. I came to know after reading the above explanation by @007_jb

Even now my hosts file looks like this

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

Host Name was the problem, it is better to replace it with IP

Can anyone explain why soo many localhosts?
and what does the file say?

I was only teasing you @Rakshith_79674 :wink:

Not really! In the real world you would most likely use FQDN for several reasons… IP addresses can change, FQDN are easier to remember and read, no reliance on a DNS server. There are other lectures or labs where FQDN are used/preferred (I don’t remember if it’s in this course or not), so it would be beneficial to get yourself acquainted with it and start using it.

Thanks @007_jb and @Ramachandra_37567 for your contribution.

Hi @Rakshith_79674,

I am definitely late to the party but I would like to add couple of points here.

  1. As mentioned by @007_jb, when we are adding more than one node in the replica set using the rs.add() function, you need to pass them as an array.

  2. The error message says that the host is unreachable. This means either the node which you were trying to add is not running at the moment or you have provided the address of an incorrect node. However, in your case the nodes are up and running so we can say that the address that you have provided is incorrect.

If you want to verify the mapping of any domain name either you can refer the /etc/hosts file or you can ping the domain name to see the actual IP address to which it is mapped. Such as :

 ping m103.mongodb.university

This is not the right way of adding the replica set. When you don’t have authentication enabled on the other two nodes then it would be added in a STARTUP mode and would continue to have that state. Which basically means that this node is not a recognized member of any replica set.

In a replica set, when we are specifying {authorization : enabled} then you must specify the Authentication Mechanism as well such as using key-file.

If you do not specify this then it would throw an error : failed with not authorized on admin to execute command

You can do this using the vim editor. Follow the steps mentioned below.

sudo vim /etc/hosts

This will open the hosts file in your terminal.

Now press i and hit enter to enter the insert mode

Add an entry -> 192.168.103.100 m103.mongodb.university

Also make sure m103.mongodb.university is not mapped to any other IP address. If so then remove it.

Press esc

Press :x and enter to save and exit

Now, you are all set.

Hope it helps!

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

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer