Nosql Mongodb之旅(29)—MongoDB新增Shard Server

1、启动一个新Shard Server 进程

[plain] view plain copy
  1. [root@localhost~]#mkdir/data/shard/s2
  2. [root@localhost~]#/Apps/mongo/bin/mongod--shardsvr--port20002--dbpath/data/shard/s2
  3. --fork--logpath/data/shard/log/s2.log--directoryperdb
  4. alloutputgoingto:/data/shard/log/s2.log
  5. forkedprocess:6772
2、配置新Shard Server
    [root@localhost~]#/Apps/mongo/bin/mongoadmin--port40000
  1. MongoDBshellversion:1.8.1
  2. connectingto:127.0.0.1:40000/admin
  3. >db.runCommand({addshard:"localhost:20002"})
  4. {"shardAdded":"shard0002","ok":1}
  5. >printShardingStatus()
  6. ---ShardingStatus---
  7. shardingversion:{"_id":1,"version":3}
  8. shards:
  9. {"_id":"shard0000","host":"localhost:20000"}
  10. {"_id":"shard0001","host":"localhost:20001"}
  11. {"_id":"shard0002","host":"localhost:20002"}--新增ShardServer
  12. databases:
  13. {"_id":"admin","partitioned":false,"primary":"config"}
  14. {"_id":"test","partitioned":true,"primary":"shard0000"}
  15. test.userschunks:
  16. shard00022
  17. shard000021
  18. shard000121
  19. toomanychunksntoprint,useverboseifyouwanttoforceprint
  20. test.users_2chunks:
  21. shard000146
  22. shard00021
  23. shard000045
  24. toomanychunksntoprint,useverboseifyouwanttoforceprint
3、 查看分片表状态,以验证新Shard Server
    >usetest
  1. switchedtodbtest
  2. >db.users_2.stats()
  3. {
  4. "sharded":true,
  5. "ns":"test.users_2",
  6. ……
  7. "shard0002":{--新的ShardServer已有数据
  8. "ns":"test.users_2",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "count":21848,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "size":2097408,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "avgObjSize":96,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "storageSize":2793472,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "numExtents":5,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nindexes":1,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "lastExtentSize":2097152,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "paddingFactor":1,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "flags":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "totalIndexSize":1277952,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "indexSizes":{
  9. "_id_":1277952
  10. },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
  11. }
  12. },248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
  13. }
  14. >
我们可以发现,当我们新增Shard Server 后数据自动分布到了新Shard 上,这是由MongoDB内部自已实现的。

相关文章

校园网上订餐系统系统主要功能模块包括公告内容(公告栏、轮...
从今天开始,正式进入项目阶段。本次的项目是跟着黑马的瑞吉...
在可预见的将来,IT不会萎缩,只会越发展越庞大,最终会渗透...
vulntarget-b靶场最详细通关记录。
MongoDB是一个开源、高性能、支持海量数据存储的。
【NoSQL数据库技术与应用】课本代码、课后答案(持续更新)