Hello,
I followed the instruction from here: https://www.mongodb.com/docs/manual/tutorial/deploy-shard-cluster/#start-each-member-of-the-shard-replica-set to setup a shard.
- Here is the rs.config(); for the configuration servers:
{
"set" : "rs0",
"date" : ISODate("2022-08-08T06:36:33.451Z"),
"myState" : 1,
"term" : NumberLong(133),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"configsvr" : true,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"lastCommittedWallTime" : ISODate("2022-08-08T06:36:31.072Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"readConcernMajorityWallTime" : ISODate("2022-08-08T06:36:31.072Z"),
"appliedOpTime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"durableOpTime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"lastAppliedWallTime" : ISODate("2022-08-08T06:36:31.072Z"),
"lastDurableWallTime" : ISODate("2022-08-08T06:36:31.072Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1659940572, 1),
"lastStableCheckpointTimestamp" : Timestamp(1659940572, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "stepUpRequestSkipDryRun",
"lastElectionDate" : ISODate("2022-08-07T18:00:50.758Z"),
"electionTerm" : NumberLong(133),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1659895248, 2),
"t" : NumberLong(132)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1659895248, 2),
"t" : NumberLong(132)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 2,
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2022-08-07T18:00:51.320Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2022-08-07T18:00:52.676Z")
},
"electionParticipantMetrics" : {
"votedForCandidate" : true,
"electionTerm" : NumberLong(132),
"lastVoteDate" : ISODate("2022-08-07T18:00:48.115Z"),
"electionCandidateMemberId" : 2,
"voteReason" : "",
"lastAppliedOpTimeAtElection" : {
"ts" : Timestamp(1659895244, 1),
"t" : NumberLong(130)
},
"maxAppliedOpTimeInSet" : {
"ts" : Timestamp(1659895246, 3),
"t" : NumberLong(131)
},
"priorityAtElection" : 1
},
"members" : [
{
"_id" : 0,
"name" : "mongodb-conf1:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 45347,
"optime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"optimeDate" : ISODate("2022-08-08T06:36:31Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1659895250, 1),
"electionDate" : ISODate("2022-08-07T18:00:50Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "mongodb-conf2:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 45345,
"optime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"optimeDurable" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"optimeDate" : ISODate("2022-08-08T06:36:31Z"),
"optimeDurableDate" : ISODate("2022-08-08T06:36:31Z"),
"lastHeartbeat" : ISODate("2022-08-08T06:36:31.539Z"),
"lastHeartbeatRecv" : ISODate("2022-08-08T06:36:32.860Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "mongodb-conf1:27017",
"syncSourceHost" : "mongodb-conf1:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "mongodb-conf3:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 45338,
"optime" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"optimeDurable" : {
"ts" : Timestamp(1659940591, 1),
"t" : NumberLong(133)
},
"optimeDate" : ISODate("2022-08-08T06:36:31Z"),
"optimeDurableDate" : ISODate("2022-08-08T06:36:31Z"),
"lastHeartbeat" : ISODate("2022-08-08T06:36:31.519Z"),
"lastHeartbeatRecv" : ISODate("2022-08-08T06:36:33.304Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "mongodb-conf2:27017",
"syncSourceHost" : "mongodb-conf2:27017",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("7fffffff0000000000000085")
},
"lastCommittedOpTime" : Timestamp(1659940591, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1659940591, 1),
"signature" : {
"hash" : BinData(0,"xdvd4H1nUSIA2sIqQ8vxQHoaO+o="),
"keyId" : NumberLong("7127557678649311233")
}
},
"operationTime" : Timestamp(1659940591, 1)
}```
2. Here is the rs.config() for the shards:
{
“_id” : “rs1”,
“version” : 1,
“protocolVersion” : NumberLong(1),
“writeConcernMajorityJournalDefault” : true,
“members” : [
{
“_id” : 0,
“host” : “mongodb-shard1-01:27017”,
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : false,
“priority” : 1,
“tags” : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "mongodb-shard1-02:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "mongodb-shard1-03:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("62effe83cfa06cab70c2d2c0")
}
}
3. Here is the mongos.log output when trying to do a connection:
022-08-08T08:48:55.683+0200 I CONNPOOL [ShardRegistry] Connecting to mongodb-conf1:27017
2022-08-08T08:48:55.690+0200 I CONTROL [LogicalSessionCacheRefresh] Failed to refresh session cache: ShardingStateNotInitialized: Cannot accept sharding commands if sharding state has not been initialized with a shardIdentity document
2022-08-08T08:49:00.369+0200 I NETWORK [conn21] received client metadata from 10.135.169.16:33198 conn21: { driver: { name: “mongoc / ext-mongodb:PHP”, version: “1.16.2 / 1.7.4” }, os: { type: “Linux”, name: “Debian GNU/Linux”, version: “9”, architecture: “x86_64” }, platform: “PHP 7.4.4cfg=0x015156a8e9 posix=200809 stdc=201112 CC=GCC 6.3.0 20170516 CFLAGS=”" LDFLAGS=“”" }
2022-08-08T08:49:20.617+0200 I COMMAND [conn21] command feeder.logs command: create { create: “logs”, capped: false, $db: “feeder”, lsid: { id: UUID(“9ac401d6-0352-423a-9c8e-4557be32ecc3”) }, $clusterTime: { clusterTime: Timestamp(1659941336, 1), signature: { hash: BinData(0, 26334C49AAEA28A44B3DFF3A9911AFBD09350A29), keyId: 7127557678649311233 } } } numYields:0 ok:0 errMsg:“Could not find host matching read preference { mode: "primary" } for set rs1” errName:FailedToSatisfyReadPreference errCode:133 reslen:306 protocol:op_msg 20220ms
2022-08-08T08:50:16.066+0200 I CONNPOOL [ShardRegistry] Ending idle connection to host mongodb-conf1:27017 because the pool meets constraints; 1 connections to that host remain open
2022-08-08T08:53:55.686+0200 I CONTROL [LogicalSessionCacheRefresh] Failed to refresh session cache: ShardingStateNotInitialized: Cannot accept sharding commands if sharding state has not been initialized with a shardIdentity document
Can you please help me with some suggestions?