Hi
If you’re looking to automate starting up a MongoDB deployment for testing purposes (i.e. all mongod runs on localhost), then I would encourage you to take a look at mtools, especially the tool mlaunch.
From my understanding, the deployment you posted could be started by mlaunch using the following command:
mlaunch init --sharded 2 --replicaset --config 3
That is, initialize a sharded cluster with 2 shards, where each shard contains a 3-node replica set, and use a 3-node config server.
The sh.status() output of the result is:
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5a98de77fc15b1d0705111b5")
}
shards:
{ "_id" : "shard01", "host" : "shard01/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:27021,localhost:27022,localhost:27023", "state" : 1 }
active mongoses:
"3.4.9" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Balancer lock taken at Thu Mar 01 2018 21:17:45 GMT-0800 (Pacific Standard Time) by ConfigServer:Balancer
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
Please refer to the installation instruction to install mtools and the mlaunch manual for operating mlaunch.
Best regards
Kevin
Hi
“Unable to reach primary for set” conf
This means that the mongos process cannot connect to the primary of the shard replica set.
The full message in your mongos log generally look like this:
2018-04-17T15:13:41.328+1000 W NETWORK [conn6] Unable to reach primary for set shard01
2018-04-17T15:13:41.831+1000 W NETWORK [conn6] Failed to connect to 127.0.0.1:27018, in(checking socket for error after poll), reason: Connection refused
In the example above, the message Connection refused was due to the mongod process of the shard server is not running. Your actual message might be different, and would provide a hint of why mongos cannot connect to the relevant server.
Typically there are two possible causes:
mongos process cannot reach the shard due to some network issuesCould you confirm that all the mongod process (shard servers, config servers) are up and running, and there is no network connectivity issues between the nodes in your cluster?
Best regards
Kevin