微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!
Nosql Mongodb之旅(29)—MongoDB新增Shard Server
分类:NoSQL作者:编程之家
1、启动一个新Shard Server 进程
- [root@localhost~]#mkdir/data/shard/s2
- [root@localhost~]#/Apps/mongo/bin/mongod--shardsvr--port20002--dbpath/data/shard/s2
- --fork--logpath/data/shard/log/s2.log--directoryperdb
- alloutputgoingto:/data/shard/log/s2.log
- forkedprocess:6772
2、配置新Shard Server
[root@localhost~]#/Apps/mongo/bin/mongoadmin--port40000
- MongoDBshellversion:1.8.1
- connectingto:127.0.0.1:40000/admin
- >db.runcommand({addshard:"localhost:20002"})
- {"shardAdded":"shard0002","ok":1}
- >printShardingStatus()
- ---ShardingStatus---
- shardingversion:{"_id":1,"version":3}
- shards:
- {"_id":"shard0000","host":"localhost:20000"}
- {"_id":"shard0001","host":"localhost:20001"}
- {"_id":"shard0002","host":"localhost:20002"}--新增ShardServer
- databases:
- {"_id":"admin","partitioned":false,"primary":"config"}
- {"_id":"test","partitioned":true,"primary":"shard0000"}
- test.userschunks:
- shard00022
- shard000021
- shard000121
- toomanychunksntoprint,useverboseifyouwanttoforceprint
- test.users_2chunks:
- shard000146
- shard00021
- shard000045
- toomanychunksntoprint,useverboseifyouwanttoforceprint
3、 查看分片表状态,以验证新Shard Server
>usetest
- switchedtodbtest
- >db.users_2.stats()
- {
- "sharded":true,
- "ns":"test.users_2",
- ……
- "shard0002":{--新的ShardServer已有数据
- "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":{
- "_id_":1277952
- },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
- }
- },248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
- }
- >
我们可以发现,当我们新增Shard Server 后数据自动分布到了新Shard 上,这是由MongoDB内部自已实现的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。