1、列出所有的Shard Server
- >db.runCommand({listshards:1})--列出所有的ShardServer
- {
- "shards":[
- "_id":"shard0000",
- "host":"localhost:20000"
- },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "_id":"shard0001",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "host":"localhost:20001"
- }
- ],
- "ok":1
- }
2、查看Sharding信息
>printShardingStatus()--查看Sharding信息
- ---ShardingStatus---
- shardingversion:{"_id":1,"version":3}
- shards:
- {"_id":"shard0000","host":"localhost:20000"}
- {"_id":"shard0001","host":"localhost:20001"}
- databases:
- {"_id":"admin","partitioned":false,"primary":"config"}
- {"_id":"test","partitioned":true,"primary":"shard0000"}
- test.userschunks:
- shard00001
- {"_id":{$minKey:1}}-->>{"_id":{$maxKey:1}}on:
- shard0000{"t":1000,"i":0}
- >
3、判断是否是Sharding
>db.runCommand({isdbgrid:1})
- {"isdbgrid":1,"hostname":"localhost","ok":1}
- >
4、对现有的集合进行分片(实例)
刚才我们是对表test.users 进行分片了,下面我们将对库中现有的未分片的表test.users_2 进行分片处理。
表最初状态如下,可以看出他没有被分片过:
>db.users_2.stats()
- "ns":"test.users_2",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "sharded":false,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "primary":"shard0000",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ns":"test.users_2",108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "count":500000,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "size":48000016,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "avgObjSize":96.000032,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "storageSize":61875968,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "numExtents":11,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nindexes":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "lastExtentSize":15001856,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "paddingFactor":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "flags":1,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "totalIndexSize":20807680,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "indexSizes":{
- "_id_":20807680
- "ok":1
- }
对其进行分片处理:
>useadmin
- switchedtodbadmin
- >db.runCommand({shardcollection:"test.users_2",key:{_id:1}})
- {"collectionsharded":"test.users_2","ok":1}
再次查看分片后的表的状态,可以看到它已经被我们分片了
>usetest
- switchedtodbtest
- >db.users_2.stats()
- "sharded":true,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "count":505462,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> ……
- "shards":{
- "shard0000":{
- },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "shard0001":{
- ……
- }
- >
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|