Setting up and configuring a sharded cluster
In this recipe, we will look at how to set up a sharded cluster in MongoDB. The cluster includes config servers, shards, and mongos servers. As this is a test setup, we will be running all relevant binaries from a single virtual machine; however, in production, they should be located on separate nodes. Next, we will look at how to enable sharding on a database, followed by sharding an actual collection. Once the sharded cluster is ready, we will import some data to the cluster and execute queries that would give us a glimpse of how the data is partitioned across the shards. Much fun awaits, let's get started!
Getting ready
There are no additional components required besides standard MongoDB binaries. Create the following directories in advance for the config server as well as the shards:
mkdir -p /data/{cfgserver1,shard1,shard2,shard3}/data
How to do it...
- Start the config server:
mongod --configsvr --dbpath /data/cfgserver1/data --port 27019 --replSet...