mongoDB 分片示例 [英] mongoDB sharding example

查看:61
本文介绍了mongoDB 分片示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 上使用 mongo 2.0.1 32 位的新手尝试测试分片如下:

Newbie using mongo 2.0.1 32-bit on windows tried testing out shards as follows:

(4) 个进程:2 个分片 + config srver + mongos w tiny chunksize

(4) processes: 2 shards + config srver + mongos w tiny chunksize

mongod.exe --shardsvr  --port 10001  --dbpath <folder1>       > shard1.log
mongod.exe --shardsvr  --port 10002  --dbpath <folder2>       > shard2.log
mongod.exe --configsvr --port 20000  --dbpath <configfolder>  > config.log
mongos.exe --configdb localhost:20000 --chunkSize 1           > mongos.log

我运行了 shell 并设置了 2 个分片:

I ran the shell and set up 2 shards:

mongos> use admin
switched to dbadmin

mongos> db.runCommand( { addshard : "localhost:10001" } );
{ "shardAdded" : "shard0000", "ok" : 1 }

mongos> db.runCommand( { addshard : "localhost:10002" } );
{ "shardAdded" : "shard0001", "ok" : 1 }

然后我为测试数据库 (dbTest) 和集合 (cTest) 启用了分片:

Then I enabled sharding for a test database (dbTest) and collection (cTest):

mongos> db.runCommand( { enablesharding  : "dbTest" } );
{ "ok" : 1 }

mongos> db.runCommand( { shardcollection : "dbTest.cTest", key : { Name : 1 } } );
{ "collectionssharded" : "dbTest.cTest", "ok" : 1 }

最后,我用 1,000,005 条样本记录填充了 cTest 集合(按名称索引):

Finally I populated the cTest collection (indexed by Name) with 1,000,005 sample records:

mongos> use dbTest
switched to db dbTest

db.cTest.drop();
db.cTest.ensureIndex({ Name : 1 });
db.cTest.save({Name: "Frank", Age:56, Job: "Accountant", State: "NY"});
db.cTest.save({Name: "Bill" , Age:23,                    State: "CA"});
db.cTest.save({Name: "Janet", Age:34, Job: "Dancer"                 });
db.cTest.save({Name: "Andy",  Age:44                                });
db.cTest.save({Name: "Zach",  Age:23, Job: "Fireman",    State: "CA"});
i=1;
while(i<=1000) 
{ 
  j=1;
  while (j<=1000) 
  { 
    db.cTest.save({Name:"Person("+i+","+j+")", Age:i+j}); 
    j = j+1
  }; 
  i=i+1; 
};

然而……

看起来实际上没有任何东西被分片.在配置数据库中,db.chunks.count() 为零,我可以从 Windows 资源管理器文件大小中看到所有数据都进入了第一个分片的物理文件设置设置,而第二个分片没有.

It appears that nothing actually got sharded. In the config database, db.chunks.count() is zero, and I can see from windows explorer file sizes that all the data went into the physical file setup setup for the first shard, and none to the second.

谁能发现我做错了什么,并提供一些有关如何管理和操作的提示?调试这种类型的东西&看看发生了什么?

Can anyone spot what I've done wrong, and also provide some tips on how to admin & debug this type of thing & see what's going on ?

谢谢

推荐答案

一旦你shardcollection",不要丢弃它.它将删除有关分片集合的元数据.

Once you "shardcollection", don't drop it. It will remove metadata about sharded collection.

这篇关于mongoDB 分片示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆