Skip to content
Cédric Joron edited this page Aug 22, 2013 · 2 revisions

Before doing this tutorial, you must to do the Replicate Set Mongo tutorial (https://github.com/OpenCSI/lbe/wiki/Replicate-Set-Mongo).

You need to stop the 3 mongoDB instance and to add a argument for the Shard part: --shardsvr

mongod --port 27017 --dpath data/db1 --replSet repl --shardsvr
mongod --port 27018 --dpath data/db2 --replSet repl --shardsvr
mongod --port 27019 --dpath data/db3 --replSet repl --shardsvr

You need to create 3 mongoDB configuration server and files:

mkdir /data/config1
mkdir /data/config2
mkdir /data/config3
mongod --port 27027 --configsvr --dbpath /data/config1
mongod --port 27028 --configsvr --dbpath /data/config2
mongod --port 27029 --configsvr --dbpath /data/config3

Those mongo servers should make the link between the client query and the 3 (node) MongoDB server.

You need to create a routing mongo server to choice the good mongoDB configuration to manage queries:

mongos --port 27020 --configdb localhost:27027,localhost:27028,localhost:27029

This router mongo server will sync all configuration servers.

You need to connect to this server (router) in order to configure it:

mongo --port 27020

And to add shards (the replicate servers) node:

use admin
db.runCommand({addshard : "repl/localhost:27017,localhost:27018,localhost:27019"})

If this operation is success, you will see { "shardAdded" : "foo", "ok" : 1 } return value, else check the error message.

By default, the Sharding mode is not active. You need to active it to the Database lbe.

db.runCommand({enablesharding: "lbe"})

And to put the id value to use for the sharding for one collection:

db.runCommand({shardcollection: "lbe.employee", key:{"_id":1}})

You will need to do this command for each collection. For example, you will be able to do for the groups collection as

db.runCommand({shardcollection: "lbe.groups", key:{"_id":1}})

Then, the Shard and Replicate for Mongo are operational.

In order to use it into LBE, you need to change the Mongo Setting by putting the router values.

Clone this wiki locally