OverviewThis is a sample sharding architecture that is a good starting point for building your cluster. Goal
Machines Locations
Datacenter RolesWe'll use datacenter East as the primary, and data center West as disaster recovery. Replica setsThe replica set nodes in West will be priority 0 so they don't become master automatically. The first thing we need to do is setup the 3 replica sets
Start the mongod process on each node, e.g. e1.acme.com# mongod --shardsvr --replSet rs_a e2.acme.com# mongod --shardsvr --replSet rs_a w1.acme.com# mongod --shardsvr --replSet rs_a Note: --shardsvr will default the port to 27018 In the mongo shell, create the replica set > cfg = {
_id : "rs_a",
members : [
{_id : 0, host : "e1.acme.com:27018", priority : 1},
{_id : 1, host : "e2.acme.com:27018", priority : 1},
{_id : 2, host : "w1.acme.com:27018", priority : 0}
]
}
> rs.initiate(cfg)
Repeat for each replica set as follows
Config ServersThe next thing we need is to choose 3 config server locations. We'll pick 2 random nodes in E (primary) and 1 in W (backup/DR). Since we have multiple MongoDB process on a node we need to ensure that different ports are being used, so we will use 27019 for the Config Servers.
Start up the config servers, e.g. e1.acme.com> mongod --configsvr e4.acme.com> mongod --configsvr w1.acme.com> mongod --configsvr Note: --configsvr will default the port to 27019 MongoS (routers)The last question is where to put the mongos. SuggestedThe suggested configuration is to run an instance on each app-server (as shown by a1-a4 in diagram above). AlternativeThese are the other common options:
Startup OptionsWhen we start the mongos, we'll use > mongos --configdb c1.acme.com:27019,c2.acme.com:27019,c3.acme.com:27019 Note: be sure to use DNS names for yoru configdb names, not ip addresses. Otherwise moving a config server later will be quite difficult. Then we'll need to add the 3 replica sets as shards > db.adminCommand( { addShard : "rs_a/e1.acme.com:27018,e2.acme.com:27018,w1.acme.com:27018" } )
> db.adminCommand( { addShard : "rs_b/e3.acme.com:27018,e4.acme.com:27018,w2.acme.com:27018" } )
> db.adminCommand( { addShard : "rs_c/e5.acme.com:27018,e6.acme.com:27018,w3.acme.com:27018" } )
Everything is runningAt this point your basic architecture is ready to go. You've got 3 shards for scalability, and 3 copies of each piece of data (with one ready for DR). There are obviously many ways to configure this, but this is a pretty simple way to get started. Your next step is to enable sharding for any database you would like to use sharded, and to then enable sharding for any collection you want sharded. Databases and collections by default will be "unsharded" and simply reside in the first shard.
Notes
|


PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus