Hi Alan,
What instructions are you using? I have a feeling they might be for an earlier version of MongoDB, which would cause some issues. The best source for setting up a sharded cluster with MongoDB 3.4 is the Deploy a Sharded Cluster section in the MongoDB Manual.
The initial database servers look fine, although you can remove the --smallfiles
option as that only pertains to the MMAPv1 storage engine and CSRS
requires WiredTiger. Based on the steps you've tried, it may be that you
are missing the step to initiate the servers as a replica set. Replace localhost
with the hostnames for your servers:
mongod --shardsvr --replSet a --dbpath a0 --logpath log.a0 --port 27000 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet a --dbpath a1 --logpath log.a1 --port 27001 --fork --logappend --oplogSize 50
mongod --shardsvr --replSet a --dbpath a2 --logpath log.a2 --port 27002 --fork --logappend --oplogSize 50
mongo --port 27000
config = { _id: "a", members:[
{ _id : 0, host : "localhost:27000" },
{ _id : 1, host : "localhost:27001" },
{ _id : 2, host : "localhost:27002" }]};
rs.initiate(config)
Next, the config servers should be in a different replSet
than the database servers. I have used --replSet b
. They also need to be initiated as a replica set. Again, replace localhost
with the hostnames for your servers:
mongod --configsvr --replSet b --dbpath cfg0 --port 26050 --fork --logpath log.cfg0 --logappend
mongod --configsvr --replSet b --dbpath cfg1 --port 26051 --fork --logpath log.cfg1 --logappend
mongod --configsvr --replSet b --dbpath cfg2 --port 26052 --fork --logpath log.cfg2 --logappend
mongo --port 26050
config = { _id: "b",
configsvr: true,
members:[
{ _id : 0, host : "localhost:26050" },
{ _id : 1, host : "localhost:26051" },
{ _id : 2, host : "localhost:26052" }
]};
rs.initiate(config)
Finally, the --configdb
connection string for the mongos doesn't look quite right. The form is <config replset name>/<host1:port>,<host2:port>,[...]
:
mongos --configdb b/localhost:26050,localhost:26051,localhost:26052 --fork --logappend --logpath log.mongos0
You can now run mongo
to connect to the mongos
server and configure sharding.
Regards,
Brian