i have mongodb replica set , 1 primary 1 secondary , arbiter vote. i'm planning implement sharding data expected grow exponentially.i find difficult in following mongodb document sharding. explain set up. in advance.
if accomplish replicaset, sharding pretty simple. pretty repeating mongo documentation in fast forward here:
below sample setup: 3 configdb , 3 shards below example can run of 1 machine see working.
- if need 3 shards setup 3 replica sets. (assuming 3 primary's 127:0.0.1:27000, 127.0.0.1:37000, 127.0.0.1:47000)
- run 3 instances mongod 3 config servers. (assuming: 127.0.0.1:27020, 127.0.0.1:27021, 127.0.0.1:270122)
- start mongos (note s in mongos) letting know config servers are. (ex: 127.0.0.1:27023)
- connect mongos mongo shell , add 3 primary mongod's of 3 replica sets shards.
- enable sharding db.
- if required enable sharding collection.
- select shard key if required. (very important right first time!!!)
- check shard status
- pump data; connect individual mongod primarys , see data distributed across 3 shards.
#start mongos 3 configs: mongos --port 27023 --configdb localhost:27017,localhost:27018,localhost:27019 mongos> sh.addshard("127.0.0.1:27000"); { "shardadded" : "shard0000", "ok" : 1 } mongos> sh.addshard("127.0.0.1:37000"); { "shardadded" : "shard0001", "ok" : 1 } mongos> sh.addshard("127.0.0.1:47000"); { "shardadded" : "shard0002", "ok" : 1 } mongos> sh.enablesharding("db_to_shard"); { "ok" : 1 } mongos> use db_to_shard; switched db db_to_shard mongos> mongos> sh.shardcollection("db_to_shard.coll_to_shard", {collid: 1, createddate: 1} ); { "collectionsharded" : "db_to_shard.coll_to_shard", "ok" : 1 } mongos> show databases; admin (empty) config 0.063gb db_to_shard 0.078gb mongos> sh.status(); --- sharding status --- sharding version: { "_id" : 1, "mincompatibleversion" : 5, "currentversion" : 6, "clusterid" : objectid("557003eb4a4e61bb2ea0555b") } shards: { "_id" : "shard0000", "host" : "127.0.0.1:27000" } { "_id" : "shard0001", "host" : "127.0.0.1:37000" } { "_id" : "shard0002", "host" : "127.0.0.1:47000" } balancer: enabled: yes running: no failed balancer rounds in last 5 attempts: 0 migration results last 24 hours: no recent migrations databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "test", "partitioned" : false, "primary" : "shard0000" } { "_id" : "db_to_shard", "partitioned" : true, "primary" : "shard0000" } db_to_shard.coll_to_shard shard key: { "collid" : 1, "createddate" : 1 } chunks: shard0000 1 { "collid" : { "$minkey" : 1 }, "createddate" : { "$minkey" : 1 } } -->> { "collid" : { "$maxkey" : 1 }, "createddate" : { "$maxkey" : 1 } } on : shard0000 timestamp(1, 0)
Comments
Post a Comment