Lab: Deploy a replica set -- Unable to connect replica set error

Launch a replica set with three members:

  1. There are three configuration files in your IDE workspace, but they are incomplete.Update these configuration files so that all three mongod processes:
    • authenticate internally using the keyfile /var/mongodb/pki/m103-keyfile
    • belong to the replica set m103-repl
  2. Once your configuration files are complete, start a mongod process using one of them.
  3. When this node is running, use the mongo shell to connect and initiate your replica set with rs.initiate(). The shell prompt will read PRIMARY when the election is complete.
  4. Because the replica set uses a keyfile for internal authentication, clients must authenticate before performing any actions.While still connected to the primary node, create the admin user for your replica set:
    db.createUser({ user: "m103-admin", pwd: "m103-pass", roles: [ {role: "root", db: "admin"} ] })

After completing above steps, i am trying to use below command for the replica set using below command:

mongo --host “m103-repl/m103:27001” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

But i am getting following error while connecting to the replica set

2021-11-22T19:51:35.039+0000 I NETWORK  [js] Cannot reach any nodes for set m103-repl. Please check network connectivity and the status of the set. This has happened for 21 checks in a row.
2021-11-22T19:51:35.539+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:36.040+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:36.541+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:37.041+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:37.542+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:38.042+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:38.543+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:39.043+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:39.544+0000 W NETWORK  [js] Unable to reach primary for set m103-repl
2021-11-22T19:51:39.544+0000 E QUERY    [js] Error: connect failed to replica set m103-repl/m103:27001 :
connect@src/mongo/shell/mongo.js:328:13
@(connect):1:6

The above command looks wrong. I do not think that the host name m103 is correct. Look at bindId in the configuration file. If I remember correctly it is localhost.

Thanks Steeve for your inputs, after updating the hostname as localhost my command worked fine and able to proceed further.

After adding two more replica sets for port 27002 and 27003, i have ran rs.status() and rs.isMaster() commands. I can see that 27001 as primary and 27002 as secondary but 27003 is in “stateStr” : “(not reachable/healthy)” .

when i tried to re-add it again, i am getting below error message

rs.add("localhost:27003")
{
        "operationTime" : Timestamp(1637615286, 1),
        "ok" : 0,
        "errmsg" : "Found two member configurations with same host field, members.2.host == members.3.host == localhost:27003",
        "code" : 103,
        "codeName" : "NewReplicaSetConfigurationIncompatible",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1637615286, 1),
                "signature" : {
                        "hash" : BinData(0,"QEmdHWLeIG1aUD7e4ysVPpnuWnk="),
                        "keyId" : NumberLong("7033477639801143297")
                }

Also i can see the test results state that i have skipped the “localhost:27003” replication enablement.

The error you are getting is because localhost:27003 is already in the replica set (just not healthy). If you wanted to try and re-add it you would need to remove localhost:27003 first (using rs.remove) and then add it again.

If the node is still unhealthy after re-adding it, I would verify that the 27003 node is successfully started and you can access it’s mongo shell. If you are able to do that, I would validate the config file again.

1 Like