Database Reference
In-Depth Information
Ensure that each config server is up and running by connecting with the shell or by
tailing the log file and verifying that each process is listening on the configured port.
Looking at the logs for any one config server, you should see something like this:
Wed Mar 2 15:43:28 [initandlisten] waiting for connections on port 27020
Wed Mar 2 15:43:28 [websvr] web admin interface listening on port 28020
If each config server is running, you can go ahead and start the mongos . The mongos
must be started with the configdb option, which takes a comma-separated list of con-
fig database addresses: 8
$ mongos --configdb arete:27019,arete:27020,arete:27021 \
--logpath /data/mongos.log --fork --port 40000
C ONFIGURING THE CLUSTER
You have all the sharding components in place. Now it's time to configure the cluster.
Start by connecting to the mongos . To simplify the task, you'll use the sharding helper
methods. These are methods run on the global sh object. To see a list of all available
helper methods, run sh.help() .
You'll enter a series of configuration commands beginning with the addshard com-
mand. The helper for this command is sh.addShard() . This method takes a string
consisting of the name of a replica set followed by the addresses of two or more seed
nodes for connecting. Here you specify the two replica sets you created along with the
addresses of the two non-arbiter members of each set:
$ mongo arete:40000
> sh.addShard("shard-a/arete:30000,arete:30001")
{ "shardAdded" : "shard-a", "ok" : 1 }
> sh.addShard("shard-b/arete:30100,arete:30101")
{ "shardAdded" : "shard-b", "ok" : 1 }
If successful, the command response will include the name of the shard just added.
You can examine the config database's shards collection to see the effect of your
work. Instead of using the use command, you'll use the getSiblingDB() method to
switch databases:
> db.getSiblingDB("config").shards.find()
{ "_id" : "shard-a", "host" : "shard-a/arete:30000,arete:30001" }
{ "_id" : "shard-b", "host" : "shard-b/arete:30100,arete:30101" }
As a shortcut, the listshards command returns the same information:
> use admin
> db.runCommand({listshards: 1})
While we're on the topic of reporting on sharding configuration, the shell's
sh.status() method nicely summarizes the cluster. Go ahead and try running it
now.
8
Be careful not to put spaces between the config server addresses when specifying them.
Search WWH ::




Custom Search