我嘗試在MongoDB中測試分片。例如,我使用host1.com和host2.com來代替真實的服務器名稱。在MongoDB中分片
所以我創建的配置服務器在host1.com:
mongod --dbpath /path/to/configdb/ --configsvr
開始mongos
在同一臺機器上:
mongos --configdb host1.com --port 27020
而在兩臺機器開始mongod
(host1.com和host2.com) :
mongod --dbpath /path/to/test_shard_db/ --shardsvr
我添加了碎片,爲數據庫01啓用了分片和集合test
與分片鍵{'名稱':1}(集合只有這個領域和測試_id
),如教程中所述。但是在所有這些操作完成後,我所有的數據都只寫入一個數據庫的主要碎片。
下面是配置:
拆分狀態:
mongos> db.printShardingStatus()
--- Sharding Status ---
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id" : "shard0000", "host" : "host1.com:27018", "maxSize" : NumberLong(1) }
{ "_id" : "shard0001", "host" : "host2.com:27018", "maxSize" : NumberLong(10) }
databases:
...
{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
test.test chunks:
shard0001 1
{ "name" : { $minKey : 1 } } -->> { "name" : { $maxKey : 1 } } on : shard0001 Timestamp(1000, 0)
收集統計:
mongos> db.printCollectionStats()
test
{
"sharded" : false,
"primary" : "shard0000",
"size" : 203535788,
...
}
均衡狀態:
mongos> sh.isBalancerRunning()
true
那麼,爲什麼在集合中的所有數據駐留的地方Ø儘管我添加了超過1兆字節的數據,但只有一個碎片?爲什麼db.printCollectionStats()
告訴我test
數據庫"sharded" : false
。我做錯了什麼?
默認塊大小爲64MB,因此在分割發生之前您有足夠的空間來增長。您可以事先自行分割分片鍵範圍,這可以使寫入從一開始就轉到多個分片。有關詳細信息,請參閱以下內容:http://docs.mongodb.org/manual/tutorial/manage-chunks-in-sharded-cluster/#split-chunks – 2013-04-04 13:56:23
@James Wahlin,所以shard maxSize和chunkSize與每個其他? – 2013-04-04 14:23:36
maxSize將限制給定分片上的數據量。到達時,平衡器會將塊移動到尚未達到maxSize的碎片。塊是屬於分片鍵範圍的一部分的文檔的集合。 MongoDB平衡器將在塊級別的碎片之間移動數據以達到平衡。當某個塊接近maxSize值時,它將被拆分爲2,這可能會導致移動。 – 2013-04-04 14:30:07