Automating the creation of a MongoDB ReplicaSet

I have revisited an old Github Gist of mine, adding some bash nicety to allow the user to specify the number of servers and the starting port range.

This is really meant to be used solely for test / development purposes (really, what’s the point of having a replica set running off a single server in Production?).

Usage would be something like:

[~] $ repset-mongo.sh test-rs0 5 30100
[INFO] Starting 5 MongoDB servers on localhost, using ports starting at 30100;
the replica set will be named: test-rs0
Do you want to continue (y/N)? y
[WARN] Please define $MONGO_BASE to point to where you want data/logs to be created
Would you like to continue using the default (/Users/marco/mongod_base)? y
Using base directory for logs and data: /Users/marco/mongod_base
Logs sent to /Users/marco/mongod_base/logs, data saved in /Users/marco/mongod_base/data
[INFO] MongoDB server started on port 30100
[INFO] MongoDB server started on port 30101
[INFO] MongoDB server started on port 30102
[INFO] MongoDB server started on port 30103
[INFO] MongoDB server started on port 30104
[INFO] Configuring replica set test2 and initializing
[SUCCESS] Replica set test2 started and configured
[INFO] Waiting for replica set to sync and elect primary...
[SUCCESS] To connect to PRIMARY execute: mongo --port 30100 --host localhost

If you specify an environment variable $MONGO_BASE, data and logs will be placed there; otherwise, the script will by default use ${HOME}/mongo_base.

Again, use this just to do some quick tests in a dev environment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s