Unable to start mongos - Lab: Deploy a Sharded Cluster

I am working on the IDE session.

Lab note states:

  • the Configuration Server Replica Set csrs is running on csrs/localhost:27004,localhost:27005,localhost:27006
  • a replica set shard1 is running on shard1/localhost:27001,localhost:27002,localhost:27003
  • the m103-admin user has been created on both replica sets with password m103-pass

I can see the csrs rs and shared1 rs processes running.

csrs:PRIMARY> rs.status()
{
        "set" : "csrs",
        "date" : ISODate("2022-05-03T13:23:09.756Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "configsvr" : true,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1651584188, 1),
                        "t" : NumberLong(1)
                },
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1651584188, 1),
                        "t" : NumberLong(1)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1651584188, 1),
                        "t" : NumberLong(1)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1651584188, 1),
                        "t" : NumberLong(1)
                }
        },
        "lastStableCheckpointTimestamp" : Timestamp(1651584145, 1),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "localhost:27004",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 165,
                        "optime" : {
                                "ts" : Timestamp(1651584188, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2022-05-03T13:23:08Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1651584025, 2),
                        "electionDate" : ISODate("2022-05-03T13:20:25Z"),
                        "configVersion" : 3,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 1,
                        "name" : "localhost:27005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 161,
                        "optime" : {
                                "ts" : Timestamp(1651584188, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1651584188, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2022-05-03T13:23:08Z"),
                        "optimeDurableDate" : ISODate("2022-05-03T13:23:08Z"),
                        "lastHeartbeat" : ISODate("2022-05-03T13:23:08.396Z"),
                        "lastHeartbeatRecv" : ISODate("2022-05-03T13:23:09.200Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "localhost:27004",
                        "syncSourceHost" : "localhost:27004",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 3
                },
                {
                        "_id" : 2,
                        "name" : "localhost:27006",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 161,
                        "optime" : {
                                "ts" : Timestamp(1651584188, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1651584188, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2022-05-03T13:23:08Z"),
                        "optimeDurableDate" : ISODate("2022-05-03T13:23:08Z"),
                        "lastHeartbeat" : ISODate("2022-05-03T13:23:08.396Z"),
                        "lastHeartbeatRecv" : ISODate("2022-05-03T13:23:07.787Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "localhost:27005",
                        "syncSourceHost" : "localhost:27005",
                        "syncSourceId" : 1,
                        "infoMessage" : "",
                        "configVersion" : 3
                }
        ],
        "ok" : 1,
        "operationTime" : Timestamp(1651584188, 1),
        "$gleStats" : {
                "lastOpTime" : Timestamp(0, 0),
                "electionId" : ObjectId("7fffffff0000000000000001")
        },
        "lastCommittedOpTime" : Timestamp(1651584188, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1651584188, 1),
                "signature" : {
                        "hash" : BinData(0,"/OQmLyRvJ8X2cQdX8vpjdu75Dfs="),
                        "keyId" : NumberLong("7093499386855948294")
                }
        }
}

mongos.conf file

sharding:
  configDB: m103-csrs/localhost:27004,localhost:27005,localhost:27006
security:
  keyFile: /var/mongodb/pki/m103-keyfile
net:
  bindIp: localhost
  port: 27000
systemLog:
  destination: file
  path: /var/mongodb/logs/mongos.log
  logAppend: true
processManagement:
  fork: true

mongos -f mongos.conf

user@M103# mongo --port 27000 -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27000/?authSource=admin&gssapiServiceName=mongodb
2022-05-03T13:42:42.433+0000 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27000, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27000 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:328:13
@(connect):1:6
exception: connect failed

What am i missing here? Plz help.

Is your mongod up?
Check mongos.log
Check configDB param in mongod.conf

This

and the following

are not equivalent.

Thanks Steeve & Ram for the input.

It was the typo. I fixed the replica set name, it allowed me to connect to mongod.

Also, I completed all the LAB tasks but IDE still show failure as below:

_______________________
2 total, 0 passed, 0 skipped:
[FAIL] "mongos is running"
Did you launch mongos on port 26000?
[FAIL] "shard1 has been added to cluster"
Did you add shard1 to the cluster?
_______________________

shard1 is added and mongos is running.

mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("6271a7c68d1ea6231aa9667d")
  }
  shards:
        {  "_id" : "shard1",  "host" : "shard1/localhost:27001,localhost:27002,localhost:27003",  "state" : 1 }
  active mongoses:
        "4.0.5" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours: 
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }

Any clue?

I changed the mongos port from 27000 to 26000 and IDE is now able to validate. Pass. Thanks for the help.

1 Like