/mongoDBonWindows

Deploy MongoDB shard cluster on Windows in one click

Primary LanguageShell

Deploy MongoDB shard cluster on Windows in one click.
---------------------------------------------------------------------

Deploy MongoDB shard cluster on Linux is very easy with fork option (http://docs.mongodb.org/manual/reference/program/mongod/).
But if you want to do that on Windows (yes i know ...), it's a little bit more complicated.

In this post, i will show you how to use batch and javascript to easily deploy MongoDB (without Windows service).

MongoDB must be already installed, if you need information, read that excellent post : 
	http://blog.ajduke.in/2013/04/10/install-setup-and-start-mongodb-on-windows/

The first problem is to successfully launch mongo executables in "background" from a batch.
The syntax is very simple (see http://technet.microsoft.com/en-us/library/bb491005.aspx) :
	start /b "title" myExe arg0 arg1 ...
I add /b to start an application without opening a new command prompt window.
So, for example to launch the mongo shell,  i just create the following command :
	start /b "test launching mongo shell" "C:\Program Files\MongoDB 2.6 Standard\bin\mongo"

Second step, create a sweet cluster on my computer (nodes can also be remote).
Here is the structure of folders : 
    https://gist.github.com/asicfr/fbece3bc3bc4630aa8b9

The last step is to create the complete script to deploy MongoDB that shard cluster.
What we have to do (see http://docs.mongodb.org/manual/tutorial/deploy-shard-cluster/ for more details) ?
- Start our two replicatSets
- Start the Config Server Database Instances
- Start the mongos Instances
- Add Shards to the Cluster
- Enable Sharding for a Database
- Enable Sharding for a Collection

Here is the script : 
    https://gist.github.com/asicfr/2c7b99947083d13a9c6b

This script uses three javascript to interact with mongo shell :
- configS1.js : define the members of first replicatSet
	https://gist.github.com/asicfr/207682eeca5a6ac836ea
- configS2.js : define the members of second replicatSet
	https://gist.github.com/asicfr/9e70a374480dd5d85519
- configShard.js : configure sharding and show the status of the sharding configuration
	https://gist.github.com/asicfr/12d50de4f792fe165290

If the script work, you must see the following status : 
	https://gist.github.com/asicfr/548941c0b9de7abe17fd

I added some pauses, especially before the last action (define sharding configuration) otherwise the sharding configure is not applied.
If you find a better solution, tell me.

Conclusion :
You no longer have excuses for not testing MongoDB shard cluster on Windows.
All script and folders are available on github :
	https://github.com/asicfr/mongoDBonWindows