mongodb sharding基本概念
mongodb sharding基本概念这里先介绍sharding的架构和几个基本概念术语。shard server :shard server可以使一个mongod实例,也可以是replica set。config sever:为了将指定collection存储在多个shard中,那么就需要个key来进行分割,config server存储各个节点的配置信息。shard key的范围,以及分布情况。route process:由此介入客户端,通过询问config server,确定到那个shard上面查询,在连接相应的shard操作,不保存数据和配置信息。由于资源限制,在一台机子上做一下实验Shard Server 1:30000Shard Server 2:30001Config Server :40000Route Process:50000步骤:启动shard server 1和2[mongo@172_16_3_216 mongo]$ mkdir -p /mongo/shard/data0[mongo@172_16_3_216 mongo]$ mkdir -p /mongo/shard/data1[mongo@172_16_3_216 mongo]$ touch shard.log[mongo@172_16_3_216 mongo]$ mongod --shardsvr --port 30000 --dbpath /mongo/shard/data0 --fork --logpath shard.log --directoryperdb[mongo@172_16_3_216 mongo]$ touch shard1.log[mongo@172_16_3_216 mongo]$ mongod --shardsvr --port 30001 --dbpath /mongo/shard/data1 --fork --logpath shard1.log --directoryperdb启动config server[mongo@172_16_3_216 mongo]$ mkdir -p /mongo/shard/config[mongo@172_16_3_216 mongo]$ touch config.log[mongo@172_16_3_216 mongo]$ mongod --configsvr --port 40000 --dbpath /mongo/shard/config --fork --logpath config.log --directoryperdb启动route process[mongo@172_16_3_216 mongo]$ touch route.log[mongo@172_16_3_216 mongo]$ mongos --port 50000 --configdb localhost:40000 --fork --logpath route.log --chunkSize 2初始化shardingmongo admin --port 50000MongoDB shell version: 1.8.4connecting to: 127.0.0.1:50000/admin> db.runCommand({addshard:"localhost:30000"}) ----添加shard1{ "shardAdded" : "shard0000", "ok" : 1 }> db.runCommand({addshard:"localhost:30001"}) -----添加shard2{ "shardAdded" : "shard0001", "ok" : 1 }> db.runCommand({enablesharding:"test"}) ---对数据库test分片{ "ok" : 1 }> db.runCommand({shardcollection:"test.tb1",key:{_id:1}}) ---对数据库test中tb1按_id作为key{ "collectionsharded" : "test.tb1", "ok" : 1 }验证sharding> for (var i=1;i<=50000;i++) db.tb1.insert({age:i,name:"hank",addr:"HangZhou"})> db.tb1.stats(){"sharded" : true,"ns" : "test.tb1","count" : 50000,"size" : 3600016,"avgObjSize" : 72.00032,"storageSize" : 13975552,"nindexes" : 1,"nchunks" : 4,"shards" : {"shard0000" : {"ns" : "test.tb1","count" : 17888,"size" : 1287944,"avgObjSize" : 72.00044722719142,"storageSize" : 2793472,"numExtents" : 5,"nindexes" : 1,"lastExtentSize" : 2097152,"paddingFactor" : 1,"flags" : 1,"totalIndexSize" : 753664,"indexSizes" : {"_id_" : 753664},"ok" : 1},"shard0001" : {"ns" : "test.tb1","count" : 32112,"size" : 2312072,"avgObjSize" : 72.00024912805182,"storageSize" : 11182080,"numExtents" : 6,"nindexes" : 1,"lastExtentSize" : 8388608,"paddingFactor" : 1,"flags" : 1,"totalIndexSize" : 1343488,"indexSizes" : {"_id_" : 1343488},"ok" : 1}},"ok" : 1}查看sharding信息:> db.runCommand({listshards:1}){"shards" : [{&nb上一个:Sqlite数据库的加密
下一个:查找数据库中所有有自增列的用户表
- 更多mongodb疑问解答:
- 【急】MongoDB写入错误~~~~
- Mongodb NOSql 数据库问题,是否可以插入带接口的类
- java操作mongodb
- Spring data MongoDB 更新整个内嵌文档时报错???????
- node.js连接mongodb更新
- MongoDB Java驱动 WriteConcern.SAFE非常浪费资源
- 求科普,hibernate怎样操作mongodb?
- 问一下mongodb怎么用hibernate整合
- mongodb查询的数据过多
- 使用JAVA创建MongoDB的问题
- Mongodb事务管理问题?
- mongodb利用java进行模糊查询
- spring 抽象类 注入值为空(spring3+mongodb+morphia)
- 【急】MongoDB写入错误~~~~
- Mongodb NOSql 数据库问题,是否可以插入带接口的类