MongoDB分片集群配置
#对数据库启用sharding功能mongos> sh.enableSharding("testdb")
{ "ok" : 1 }
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("55c3fa618addd3d263602205")
}
shards:
{"_id" : "shard0000","host" : "192.168.3.32:27017" }
{"_id" : "shard0001","host" : "192.168.3.33:27017" }
balancer:
Currently enabled:yes
Currently running:no
Failed balancer rounds in last 5 attempts:0
Migration Results for the last 24 hours:
No recent migrations
databases:
{"_id" : "admin","partitioned" : false,"primary" : "config" }
{"_id" : "test","partitioned" : false,"primary" : "shard0000" }
{"_id" : "testdb","partitioned" : true,"primary" : "shard0000" } #已生效
#指定需要分片的Collection及索引
mongos> sh.shardCollection("testdb.students",{"age":1})
{ "collectionsharded" : "testdb.students", "ok" : 1 }
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("55c3fa618addd3d263602205")
}
shards:
{"_id" : "shard0000","host" : "192.168.3.32:27017" }
{"_id" : "shard0001","host" : "192.168.3.33:27017" }
balancer:
Currently enabled:yes
Currently running:no
Failed balancer rounds in last 5 attempts:0
Migration Results for the last 24 hours:
No recent migrations
databases:
{"_id" : "admin","partitioned" : false,"primary" : "config" }
{"_id" : "test","partitioned" : false,"primary" : "shard0000" }
{"_id" : "testdb","partitioned" : true,"primary" : "shard0000" }
testdb.students
shard key: { "age" : 1 }
chunks:
shard00001
{ "age" : { "$minKey" : 1 } } -->> { "age" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
页:
[1]