I have joined Anti-IF Campaign

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 :

This structure enables us to dissociate data and logs of different nodes.


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) ?
The todo list :
  1. Start our two replicatSets
  2. Start the Config Server Database Instances
  3. Start the mongos Instances
  4. Add Shards to the Cluster
  5. Enable Sharding for a Database
  6. Enable Sharding for a Collection

Here is the script, all options and parameters are explained inline  :
This script uses three javascript to interact with mongo shell :
- configS1.js : define the members of first replicatSet
- configS2.js : define the members of second replicatSet
- configShard.js : configure sharding and show the status of the sharding configuration

If the script work, you must see the following status :
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

Thanks.

Aucun commentaire:

Enregistrer un commentaire