mongodb分片balance
檢視balance狀態
mongos> sh.getBalancerState()
true
true
透過balance鎖檢視balance活動
如果state是2,表示balance鎖已經被獲取
mongos> db.locks.find({"_id" : "balancer"}).pretty()
{
"_id" : "balancer",
"state" : 2,
"who" : "db10:4001:1427696724:1804289383:Balancer:1681692777",
"ts" : ObjectId("5519158885c46501a2380c4a"),
"process" : "db10:4001:1427696724:1804289383",
"when" : ISODate("2015-03-30T09:21:12.689Z"),
"why" : "doing balance round"
}
{
"_id" : "balancer",
"state" : 2,
"who" : "db10:4001:1427696724:1804289383:Balancer:1681692777",
"ts" : ObjectId("5519158885c46501a2380c4a"),
"process" : "db10:4001:1427696724:1804289383",
"when" : ISODate("2015-03-30T09:21:12.689Z"),
"why" : "doing balance round"
}
設定balance視窗
db.settings.update({ _id : "balancer" }, { $set : { activeWindow : { start : "23:00", stop : "6:00" } } }, true )
檢視
mongos> sh.getBalancerWindow()
{ "start" : "23:00", "stop" : "22:00" }
{ "start" : "23:00", "stop" : "22:00" }
手動執行balance
mongos> sh.startBalancer()
集合級別啟用、禁用balance
sh.enableBalancing("test.doc2")
sh.disableBalancing("test.doc2")
檢視
mongos> db.getSiblingDB("config").collections.findOne({_id : "test.doc2"})
{
"_id" : "test.doc2",
"lastmod" : ISODate("2015-03-30T06:40:58.730Z"),
"dropped" : false,
"key" : {
"_id" : "hashed"
},
"unique" : false,
"lastmodEpoch" : ObjectId("5518effa291477d087fdc6fe"),
"noBalance" : true
}
{
"_id" : "test.doc2",
"lastmod" : ISODate("2015-03-30T06:40:58.730Z"),
"dropped" : false,
"key" : {
"_id" : "hashed"
},
"unique" : false,
"lastmodEpoch" : ObjectId("5518effa291477d087fdc6fe"),
"noBalance" : true
}
當發現資料分配不平均時
如:
mongos> sh.status()
--- Sharding Status ---
sharding version: {
--- Sharding Status ---
sharding version: {
...
...
test.doc0
shard key: { "int1" : 1, "int2" : 1 }
chunks:
rs0 1
rs1 1
rs2 1
{ "int1" : { "$minKey" : 1 }, "int2" : { "$minKey" : 1 } } -->> { "int1" : 0, "int2" : 1 } on : rs1 Timestamp(2, 0)
{ "int1" : 0, "int2" : 1 } -->> { "int1" : 0, "int2" : 9 } on : rs2 Timestamp(3, 0)
{ "int1" : 0, "int2" : 9 } -->> { "int1" : { "$maxKey" : 1 }, "int2" : { "$maxKey" : 1 } } on : rs0 Timestamp(3, 1)
shard key: { "int1" : 1, "int2" : 1 }
chunks:
rs0 1
rs1 1
rs2 1
{ "int1" : { "$minKey" : 1 }, "int2" : { "$minKey" : 1 } } -->> { "int1" : 0, "int2" : 1 } on : rs1 Timestamp(2, 0)
{ "int1" : 0, "int2" : 1 } -->> { "int1" : 0, "int2" : 9 } on : rs2 Timestamp(3, 0)
{ "int1" : 0, "int2" : 9 } -->> { "int1" : { "$maxKey" : 1 }, "int2" : { "$maxKey" : 1 } } on : rs0 Timestamp(3, 1)
...
...
上面的doc0,有3個chunk,其中rs0上的chunk包含了從0,9一直到最大值的所有資料。
此時可以split這個chunk
mongos> sh.splitAt( "test.doc0", { int1:30, int2:30 });
{ "ok" : 1 }
mongos> sh.splitAt( "test.doc0", { int1:60, int2:60 });
{ "ok" : 1 }
{ "ok" : 1 }
mongos> sh.splitAt( "test.doc0", { int1:60, int2:60 });
{ "ok" : 1 }
手工移動chunk
透過find條件,將這條記錄所在的chunk移動到指定rs
mongos> db.runCommand({moveChunk:"test.doc0", find:{int1:30, int2:30}, to:"rs1"})
{ "millis" : 11137, "ok" : 1 }
{ "millis" : 11137, "ok" : 1 }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26239116/viewspace-1485441/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MongoDB分片MongoDB
- MongoDB 分片管理MongoDB
- MongoDB之分片MongoDB
- mongodb分片搭建MongoDB
- mongodb 分片叢集建立分片集合MongoDB
- MongoDB分片叢集新增分片(自用)MongoDB
- mongodb之shard分片MongoDB
- mongodb複製+分片MongoDB
- MongoDB 分片叢集搭建MongoDB
- MongoDB叢集之分片MongoDB
- 搭建MongoDB分片叢集MongoDB
- mongodb 分片叢集設定MongoDB
- mongodb分片物理搬遷方案MongoDB
- MongoDB分片叢集常用操作MongoDB
- 【Mongodb】分片加複製集MongoDB
- MongoDB 3.4配置sharding分片MongoDB
- mongodb簡單分片實驗MongoDB
- mongodb 分片群集(sharding cluster)MongoDB
- MongoDB分片鍵選擇指南MongoDB
- 【Mongodb】分片複製集環境新增新的分片MongoDB
- MongoDB分片叢集chunk的概念MongoDB
- MongoDB何時考慮使用分片MongoDB
- MongoDB 分片的原理、搭建、應用MongoDB
- 高可用mongodb叢集(分片+副本)MongoDB
- MongoDB4.2 分片掃盲說明MongoDB
- MongoDB Sharding(二) -- 搭建分片叢集MongoDB
- Mongodb分散式叢集副本集+分片MongoDB分散式
- MongoDB 分片鍵的選擇與案例MongoDB
- MongoDB分片需要考慮的事項MongoDB
- mongodb的分散式叢集(3、分片)MongoDB分散式
- mongoDB研究筆記:分片叢集部署MongoDB筆記
- 搭建高可用MongoDB叢集(四):分片MongoDB
- MongoDB叢集設定集合分片生效及檢視集合分片情況MongoDB
- mongodb分片(sharding)搭建、應用及管理MongoDB
- MongoDB的分片資料庫命令總結MongoDB資料庫
- linux下Mongodb叢集搭建:分片+副本集LinuxMongoDB
- MongoDB分片群集的部署(用心描述,詳細易懂)!!MongoDB
- MongoDB mongoshake 遷移分片到複製集合MongoDB