MongoDB 3.4 Sharded Server

85 views
Skip to first unread message

Alan

unread,
Aug 10, 2017, 2:09:42 AM8/10/17
to mongodb-user
The Mongo 3.4 Shard setup is different compared to previous versions from what I understand.  Here are the instructions that I am supposed to perform: 

Stop the mongod process. Now, restart the mongod process adding the option --shardsvr. If you started mongod with a --dbpath option, specify that as well.

mongod --shardsvr ...

Note that with --shardsvr specified the default port for mongod becomes 27018.


Start a mongo config server:

mongod --configsvr ...


Note: configuration server setup has changed. If you are using MongoDB 3.4 you must set up your configuration servers with CSRS. An example setup is as follows:


mongod --configsvr --replSet csReplSet ...
mongod --configsvr --replSet csReplSet ...
mongod --configsvr --replSet csReplSet ...

mongo --port 27019

config = { _id: "csReplSet", members:[
         { _id : 0, host : "localhost:27019" },
         { _id : 1, host : "localhost:27020" },
         { _id : 2, host : "localhost:27021" }]};
rs.initiate(config)


(Note with --configsvr specified the default port for listening becomes 27019 and the default data directory /data/configdb. Wherever your data directory is, it is suggested that you verify that the directory is empty before you begin.)


Start a mongos:

mongos --configdb your_host_name:27019


These are the steps I tried from what I have gathered so far: 

mongod --shardsvr --replSet a --dbpath a0 --logpath log.a0 --port 27000 --fork --logappend --smallfiles --oplogSize 50
mongod --shardsvr --replSet a --dbpath a1 --logpath log.a1 --port 27001 --fork --logappend --smallfiles --oplogSize 50
mongod --shardsvr --replSet a --dbpath a2 --logpath log.a2 --port 27002 --fork --logappend --smallfiles --oplogSize 50

mongod --configsvr --replSet a --dbpath cfg0 --port 26050 --fork --logpath log.cfg0 --logappend
mongod --configsvr --replSet a --dbpath cfg1 --port 26051 --fork --logpath log.cfg1 --logappend
mongod --configsvr --replSet a --dbpath cfg2 --port 26052 --fork --logpath log.cfg2 --logappend

mongos --configdb m034:26050,m034:26051,m034:26052 --fork --logappend --logpath log.mongos0


It looks like I'm missing the step where it says if you're using Mongo 3.4, you must set up you configuration servers with CSRS.  What steps am I missing in order to get it to work?  Please help me fill in the missing steps.  Thanks.
- show quoted text -

Brian Moss

unread,
Aug 18, 2017, 12:36:57 AM8/18/17
to mongodb-user

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

Alan

unread,
Aug 23, 2017, 9:50:51 PM8/23/17
to mongodb-user
Yeah the instructions I was using were from an earlier version of MongoDB.  Thanks Brian!

Brian Moss

unread,
Aug 24, 2017, 12:01:27 AM8/24/17
to mongodb-user
You're very welcome. Glad I could help!

Cheers,
Brian
Reply all
Reply to author
Forward
0 new messages