Not able to connect to Shard cluster

Hi Team ,

Getting below error while trying to connect to Shard cluster .
pprbj@XXXXXXXXXbin % ./mongo --port 27021

MongoDB shell version v5.0.9

connecting to: mongodb://127.0.0.1:27021/?compressors=disabled&gssapiServiceName=mongodb

Error: couldn’t connect to server 127.0.0.1:27021, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27021 :: caused by :: Operation timed out :

connect@src/mongo/shell/mongo.js:372:17

@(connect):2:6

exception: connect failed

exiting with code 1

Note: Config server,Mongos and replicaset are up and running fine.
issue is while connecting to shard .

any help will be appreciated .

Regards
Prince.

Need the output of the commands:

ss -tlnp
ps -aef | grep [m]ongo

Do you get the same with the new mongosh? With Compass?

How do you start mongos? Can you share the logs of mongos?

Have you check your firewall rules to make sure you can connect to this address:port?

1 Like

mongodb.log (26.9 KB)

Do you get the same with the new mongosh? Yes.
With Compass ? No
Have you check your firewall rules to make sure you can connect to this address:port? yes.
Can you share the logs of mongos? Uploaded .
How do you start mongos? ./mongod --config /Users/pprbj/config/mongos.conf

Note: I am building a single sharded cluster.

Prince.

That looks very wrong. You are starting mongod with something that looks like a mongos configuration file.

I got 403 ERROR when trying to look at the logs.

Please share the configuration file /Users/pprbj/config/mongos.conf.

So you are able to connect with Compass with the same URI? Please post a screenshot.

@steevej : Sorry for providing wrong details. Please check the details

1: ps -aef | grep mongo

  501  1906  1738   0 12:45PM ttys000    0:03.79 ./mongod -f /Users/pprbj/config/config1.conf
  501  1976  1775   0 12:49PM ttys001    0:00.00 grep mongo
  501  1929  1785   0 12:46PM ttys002    0:00.14 ./mongos -f /Users/pprbj/config/mongos.conf
ss -tlnp ==>Not working ,I am using MAC os.

2:Starting of Mongos :

pprbj@MN-C02FH9LAMD6N bin % ./mongos -f /Users/pprbj/config/mongos.conf 
{"t":{"$date":"2022-08-04T07:16:43.989Z"},"s":"W",  "c":"SHARDING", "id":24132,   "ctx":"-","msg":"Running a sharded cluster with fewer than 3 config servers should only be done for testing purposes and is not recommended for production."}
{"t":{"$date":"2022-08-04T07:16:43.992Z"},"s":"I",  "c":"CONTROL",  "id":20697,   "ctx":"-","msg":"Renamed existing log file","attr":{"oldLogPath":"/Users/pprbj/Desktop/data/shard/mongodb.log","newLogPath":"/Users/pprbj/Desktop/data/shard/mongodb.log.2022-08-04T07-16-43"}}

3:With Compass : I am not using compass (It’s in a built state.)
4: Please find the config file.

net:
 port: 27021
sharding:
  configDB: MPODS-PRA-001/localhost:27009
systemLog:
 destination: file
 path: /Users/pprbj/Desktop/data/shard/mongodb.log

What does your latest mongos.log show?
Please show your config server config file also
Is your data replicaset up?

Yes, Replica set is up and running fine .

output from below mongos.log

Preference: Could not find host matching read preference { mode: “nearest” } for set MPODS-PRA-001"}}
{“t”:{"$date":“2022-08-04T15:57:49.619+05:30”},“s”:“W”, “c”:“SHARDING”, “id”:23834, “ctx”:“mongosMain”,“msg”:“Error initializing sharding state, sleeping for 2 seconds and retrying”,“attr”:{“error”:{“code”:133,“codeName”:“FailedToSatisfyReadPreference”,“errmsg”:“Error loading clusterID :: caused by :: Could not find host matching read preference { mode: “nearest” } for set MPODS-PRA-001”}}}
{“t”:{"$date":“2022-08-04T15:58:03.225+05:30”},“s”:“I”, “c”:“NETWORK”, “id”:4333208, “ctx”:“ReplicaSetMonitor-TaskExecutor”,“msg”:“RSM host selection timeout”,“attr”:{“replicaSet”:“MPODS-PRA-001”,“error”:“FailedToSatisfyReadPreference: Could not find host matching read preference { mode: “nearest” } for set MPODS-PRA-001”}}

Please show contents of config file you have used to start config servers
Check if any misconfiguration or reference to configdb is correct or not

Content of config file .

auditLog:
  destination: syslog
  filter: '{ roles:{role:"root", db: "admin"} }'
net:
  port: 27009
#processManagement:
 # fork: "true"
replication:
  replSetName: MPODS-PRA-001 
storage:
  dbPath: /Users/pprbj/Desktop/data
  engine: wiredTiger
systemLog:
  destination: file
  path: /Users/pprbj/Desktop/data/mongodb.log
sharding:
  clusterRole: configsvr

Have you initialized your config server?
Please show output of rs.status() from both config server and data replica set

Output of config server :
MongoDB Enterprise MPODS-PRA-001:PRIMARY> rs.status()
{
“set” : “MPODS-PRA-001”,
“date” : ISODate(“2022-08-05T10:23:07.831Z”),
“myState” : 1,
“term” : NumberLong(1),
“syncSourceHost” : “”,
“syncSourceId” : -1,
“configsvr” : true,
“heartbeatIntervalMillis” : NumberLong(2000),
“majorityVoteCount” : 1,
“writeMajorityCount” : 1,
“votingMembersCount” : 1,
“writableVotingMembersCount” : 1,
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1659694987, 1),
“t” : NumberLong(1)
},
“lastCommittedWallTime” : ISODate(“2022-08-05T10:23:07.091Z”),
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1659694987, 1),
“t” : NumberLong(1)
},
“appliedOpTime” : {
“ts” : Timestamp(1659694987, 1),
“t” : NumberLong(1)
},
“durableOpTime” : {
“ts” : Timestamp(1659694987, 1),
“t” : NumberLong(1)
},
“lastAppliedWallTime” : ISODate(“2022-08-05T10:23:07.091Z”),
“lastDurableWallTime” : ISODate(“2022-08-05T10:23:07.091Z”)
},
“lastStableRecoveryTimestamp” : Timestamp(1659694986, 1),
“electionCandidateMetrics” : {
“lastElectionReason” : “electionTimeout”,
“lastElectionDate” : ISODate(“2022-08-05T10:21:06.007Z”),
“electionTerm” : NumberLong(1),
“lastCommittedOpTimeAtElection” : {
“ts” : Timestamp(1659694865, 1),
“t” : NumberLong(-1)
},
“lastSeenOpTimeAtElection” : {
“ts” : Timestamp(1659694865, 1),
“t” : NumberLong(-1)
},
“numVotesNeeded” : 1,
“priorityAtElection” : 1,
“electionTimeoutMillis” : NumberLong(10000),
“newTermStartDate” : ISODate(“2022-08-05T10:21:06.217Z”),
“wMajorityWriteAvailabilityDate” : ISODate(“2022-08-05T10:21:07.634Z”)
},
“members” : [
{
“_id” : 0,
“name” : “localhost:27009”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 215,
“optime” : {
“ts” : Timestamp(1659694987, 1),
“t” : NumberLong(1)
},
“optimeDate” : ISODate(“2022-08-05T10:23:07Z”),
“lastAppliedWallTime” : ISODate(“2022-08-05T10:23:07.091Z”),
“lastDurableWallTime” : ISODate(“2022-08-05T10:23:07.091Z”),
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1659694866, 1),
“electionDate” : ISODate(“2022-08-05T10:21:06Z”),
“configVersion” : 1,
“configTerm” : 1,
“self” : true,
“lastHeartbeatMessage” : “”
}
],
“ok” : 1,
“$gleStats” : {
“lastOpTime” : Timestamp(1659694865, 1),
“electionId” : ObjectId(“7fffffff0000000000000001”)
},
“lastCommittedOpTime” : Timestamp(1659694987, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1659694987, 1),
“signature” : {
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),
“keyId” : NumberLong(0)
}
},
“operationTime” : Timestamp(1659694987, 1)
}
MongoDB Enterprise MPODS-PRA-001:PRIMARY> exit

Output from data node :

MongoDB Enterprise MPODS-PRA-001:PRIMARY> rs.status()
{
“set” : “MPODS-PRA-001”,
“date” : ISODate(“2022-08-05T11:15:48.369Z”),
“myState” : 1,
“term” : NumberLong(6),
“syncSourceHost” : “”,
“syncSourceId” : -1,
“heartbeatIntervalMillis” : NumberLong(2000),
“majorityVoteCount” : 2,
“writeMajorityCount” : 2,
“votingMembersCount” : 2,
“writableVotingMembersCount” : 2,
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“lastCommittedWallTime” : ISODate(“2022-08-05T11:15:45.185Z”),
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“appliedOpTime” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“durableOpTime” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“lastAppliedWallTime” : ISODate(“2022-08-05T11:15:45.185Z”),
“lastDurableWallTime” : ISODate(“2022-08-05T11:15:45.185Z”)
},
“lastStableRecoveryTimestamp” : Timestamp(1659698085, 1),
“electionCandidateMetrics” : {
“lastElectionReason” : “electionTimeout”,
“lastElectionDate” : ISODate(“2022-08-05T10:23:53.911Z”),
“electionTerm” : NumberLong(6),
“lastCommittedOpTimeAtElection” : {
“ts” : Timestamp(0, 0),
“t” : NumberLong(-1)
},
“lastSeenOpTimeAtElection” : {
“ts” : Timestamp(1659628001, 1),
“t” : NumberLong(5)
},
“numVotesNeeded” : 2,
“priorityAtElection” : 1,
“electionTimeoutMillis” : NumberLong(10000),
“numCatchUpOps” : NumberLong(0),
“newTermStartDate” : ISODate(“2022-08-05T10:23:53.973Z”),
“wMajorityWriteAvailabilityDate” : ISODate(“2022-08-05T10:23:54.870Z”)
},
“members” : [
{
“_id” : 0,
“name” : “localhost:27010”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 3192,
“optime” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“optimeDate” : ISODate(“2022-08-05T11:15:45Z”),
“lastAppliedWallTime” : ISODate(“2022-08-05T11:15:45.185Z”),
“lastDurableWallTime” : ISODate(“2022-08-05T11:15:45.185Z”),
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1659695033, 1),
“electionDate” : ISODate(“2022-08-05T10:23:53Z”),
“configVersion” : 3,
“configTerm” : 6,
“self” : true,
“lastHeartbeatMessage” : “”
},
{
“_id” : 1,
“name” : “localhost:27011”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 3119,
“optime” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“optimeDurable” : {
“ts” : Timestamp(1659698145, 1),
“t” : NumberLong(6)
},
“optimeDate” : ISODate(“2022-08-05T11:15:45Z”),
“optimeDurableDate” : ISODate(“2022-08-05T11:15:45Z”),
“lastAppliedWallTime” : ISODate(“2022-08-05T11:15:45.185Z”),
“lastDurableWallTime” : ISODate(“2022-08-05T11:15:45.185Z”),
“lastHeartbeat” : ISODate(“2022-08-05T11:15:48.164Z”),
“lastHeartbeatRecv” : ISODate(“2022-08-05T11:15:47.167Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncSourceHost” : “localhost:27010”,
“syncSourceId” : 0,
“infoMessage” : “”,
“configVersion” : 3,
“configTerm” : 6
}
],
“ok” : 1,
“$clusterTime” : {
“clusterTime” : Timestamp(1659698145, 1),
“signature” : {
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),
“keyId” : NumberLong(0)
}
},
“operationTime” : Timestamp(1659698145, 1)
}
MongoDB Enterprise MPODS-PRA-001:PRIMARY>

I am suspecting issue with replicaset names
Both data replicaset and config replicaset are having same name?
They should be different

Can you share some sample config file for
1:config server file.
2:Mongos conf file.
3:Replica ser conf file.

Please search our forum threads
You will get many sample files for each
Also check mongo documentation
Did you try by changing name of replset?

Above setup is similiar to yours without security/auth params(advised only for practice/test envs)

I am also getting 403 error while looking at log files of a website. How i don’t understand what is going wrong in db while migration. There is lot other files in db that are removed.

I got 403 ERROR when trying to look at the logs of site.

Hi All ,

After lot of fight/struggle issue got fixed.
Below are steps that made it work.
1:Created two config replicaset service(As the name describe we need to create two configserver).
Note: Will try again using single config server will post the outcome.
2:Added bindIp in config file of config server.
3:Able to connect shard cluster and able to add replica set.

It was nice learning and thanks to all of you who jumped into the issue and tried to help.

Regards
Prince.