MongoDB分布式(分片存储)部署
生活随笔
收集整理的這篇文章主要介紹了
MongoDB分布式(分片存储)部署
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
分別開啟一個Config和兩個Shard D:\mongodb1\bin\mongod --configsvr --dbpath D:\mongodb1\db\ --port 27020 D:\mongodb2\bin\mongod --dbpath D:\mongodb2\db\ --port 27021 D:\mongodb3\bin\mongod --dbpath D:\mongodb3\db\ --port 27022 啟動mongos(Sharding controller分片控制器) D:\mongodb1\bin\mongos --configdb 192.168.0.109:27020
配置 D:\mongodb1\bin\mongo use admin db.runCommand( { addshard : "192.168.0.109:27021", allowLocal : 1, maxSize:2 , minKey:1, maxKey:10} ) --添加分片,maxsize單位是M,此處設(shè)置比較小的數(shù)值只為演示分片效果 --或者使用sh.addShard("192.168.0.109:27021") db.runCommand( { addshard : "192.168.0.109:27022", allowLocal : 1, minKey:1000} ) --移除分片可以用?db.runCommand( { removeshard : "localhost:10000" } ); db.runCommand({listshards:1});? --查看分片節(jié)點列表 sh.status() --查看狀態(tài)?db.printShardingStatus() sh.enableSharding("records") --允許數(shù)據(jù)庫records分片 db.runCommand( { shardcollection : "records.posts", key : {_id : 1}, unique: true } )? --records.posts數(shù)據(jù)集分片存儲(默認一個數(shù)據(jù)集在一個分片上) 用程序向records.posts數(shù)據(jù)集中插入100000條數(shù)據(jù) 查看效果 use records db.posts.stats() 觀察結(jié)果中的shards.shard0000.count和shards.shard0001.count即可得出兩個分片服務(wù)器的存儲量
配置 D:\mongodb1\bin\mongo use admin db.runCommand( { addshard : "192.168.0.109:27021", allowLocal : 1, maxSize:2 , minKey:1, maxKey:10} ) --添加分片,maxsize單位是M,此處設(shè)置比較小的數(shù)值只為演示分片效果 --或者使用sh.addShard("192.168.0.109:27021") db.runCommand( { addshard : "192.168.0.109:27022", allowLocal : 1, minKey:1000} ) --移除分片可以用?db.runCommand( { removeshard : "localhost:10000" } ); db.runCommand({listshards:1});? --查看分片節(jié)點列表 sh.status() --查看狀態(tài)?db.printShardingStatus() sh.enableSharding("records") --允許數(shù)據(jù)庫records分片 db.runCommand( { shardcollection : "records.posts", key : {_id : 1}, unique: true } )? --records.posts數(shù)據(jù)集分片存儲(默認一個數(shù)據(jù)集在一個分片上) 用程序向records.posts數(shù)據(jù)集中插入100000條數(shù)據(jù) 查看效果 use records db.posts.stats() 觀察結(jié)果中的shards.shard0000.count和shards.shard0001.count即可得出兩個分片服務(wù)器的存儲量
總結(jié)
以上是生活随笔為你收集整理的MongoDB分布式(分片存储)部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【开源项目】二、Smart Admin
- 下一篇: Visual Studio调试ASP代码