bzz1ra
Last Updated: December 05, 2017
·
7.089K
· pensacola1989

Set up mongodb shard(windows local)

shard

Sharding is a method for storing data across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations.

config server

A mongod instance that stores all the metadata associated with a sharded cluster. A production sharded cluster requires three config servers, each on a separate machine.

Query Routers

mongos

shard instance

port struct

Shard Server 1:27020 Shard Server 2:27021 Config Server :27100 Route Process:40000

step 1

start shard server one by one

mongod --port 27020 --dbpath=/www/mongoDB/shard/s0 --logpath=/www/mongoDB/shard/log/s0.log --logappend

mongod --port 27021 --dbpath=/www/mongoDB/shard/s0 --logpath=/www/mongoDB/shard/log/s0.log --logappend

step 2

start config server

mongod --port 27100 --dbpath=/www/mongoDB/shard/config --logpath=/www/mongoDB/shard/log/config.log --logappend

no need to add —shardsvr and --configsvr paramters,
we point a port for ourselves;

step 3

start a route process

mongod --port 40000 --configdb localhost:27100 --logpath=/www/mongoDB/shard/log/route.log --chunkSize 500

chunkSize -->default 200MB

step 4 (config sharding)

*use shell to connect mongos *

mongo admin --port 40000 MongoDB shell version: 3.0.2 connecting to: 127.0.0.1:40000/admin

mongos>

mongos> db.runCommand({ addshard:"localhost:27020" }) { "shardAdded" : "shard0000", "ok" : 1 }

another one

mongos> db.runCommand({ addshard:"localhost:27021" }) { "shardAdded" : "shard0000", "ok" : 1 }

set a db instance that you want to sharded

mongos> db.runCommand({ enablesharding:"test" })

{ "ok" : 1 }

which db to be sharded

mongos> db.runCommand({ shardcollection: "test.log", key: { id:1,time:1}})

step 5

use mongodb like before

1 Response
Add your response

29470

I read this tutorial and it is very informative but it is not working for MongoDB version 3.4

over 1 year ago ·