Nosql Mongodb之旅(28)—MongoDB管理维护Sharding

前端之家收集整理的这篇文章主要介绍了Nosql Mongodb之旅(28)—MongoDB管理维护Sharding前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、列出所有的Shard Server

[plain] view plain copy
  1. >db.runCommand({listshards:1})--列出所有的ShardServer
  2. {
  3. "shards":[
  4. "_id":"shard0000",
  5. "host":"localhost:20000"
  6. },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"
  7. }
  8. ],
  9. "ok":1
  10. }
2、查看Sharding信息
    >printShardingStatus()--查看Sharding信息
  1. ---ShardingStatus---
  2. shardingversion:{"_id":1,"version":3}
  3. shards:
  4. {"_id":"shard0000","host":"localhost:20000"}
  5. {"_id":"shard0001","host":"localhost:20001"}
  6. databases:
  7. {"_id":"admin","partitioned":false,"primary":"config"}
  8. {"_id":"test","partitioned":true,"primary":"shard0000"}
  9. test.userschunks:
  10. shard00001
  11. {"_id":{$minKey:1}}-->>{"_id":{$maxKey:1}}on:
  12. shard0000{"t":1000,"i":0}
  13. >
3、判断是否是Sharding
    >db.runCommand({isdbgrid:1})
  1. {"isdbgrid":1,"hostname":"localhost","ok":1}
  2. >
4、对现有的集合进行分片(实例)

刚才我们是对表test.users 进行分片了,下面我们将对库中现有的未分片的表test.users_2 进行分片处理。

表最初状态如下,可以看出他没有被分片过:

    >db.users_2.stats()
  1. "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":{
  2. "_id_":20807680
  3. "ok":1
  4. }
对其进行分片处理:
    >useadmin
  1. switchedtodbadmin
  2. >db.runCommand({shardcollection:"test.users_2",key:{_id:1}})
  3. {"collectionsharded":"test.users_2","ok":1}
再次查看分片后的表的状态,可以看到它已经被我们分片了
    >usetest
  1. switchedtodbtest
  2. >db.users_2.stats()
  3. "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"> ……
  4. "shards":{
  5. "shard0000":{
  6. },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "shard0001":{
  7. ……
  8. }
  9. >
原文链接:https://www.f2er.com/nosql/204148.html

猜你在找的NoSQL相关文章