MongoDB Sharding Guide: Server Setup on Ubuntu + EC2

Now that we have the overview of sharding out of the way, it’s time to build the servers. I’ll be using EC2 and Ubuntu 9.10 in this guide. If you’d like to skip the manual labor in this part of the guide, the complete build scripts are available on github.

Shard Servers

First, we’ll need to get our shards up and running. If you are deploying to EC2, make sure you have the following completed before you get started:

Create two EBS boot EC2 instances using an up to date Ubuntu 9.10 AMI (as of this writing: ami-7d43ae14)

Create and attach two EBS volumes to /dev/sdf for storing your data on each of the shards

Change your security group to allow for the MongoDB ports we’ll be using (27017-27019)

Once your instances are up and running, ssh in to your first shard server (Shard A) and perform the following:

Change the default configuration located at /etc/init/mongodb.conf to run MongoDB as a routing server. Change the three config server hostnames (configA,configB,configC) to point to your config servers (If using EC2, make sure to use the private IP addresses to avoid bandwidth charges)