您的位置:首页 > 数据库 > Mongodb

MongoDB分片集群之balance运维

2021-04-19 14:19 946 查看

查看mongo集群是否开启了balance

mongos> sh.getBalancerState()
true

查看是否正在有数据的迁移

mongos> sh.isBalancerRunning()
false

设置balance时间窗口

mongos> use config
switched to db config
mongos> db.settings.update({ _id : "balancer" }, { $set : { activeWindow : { start : "00:00", stop : "5:00" } } }, true )
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : "balancer" })

查看balance时间窗口

mongos> db.settings.find()
{ "_id" : "balancer", "activeWindow" : { "start" : "00:00", "stop" : "5:00" } }

停止balance

mongos> sh.stopBalancer()
{
"ok" : 1,
"operationTime" : Timestamp(1618812138, 3),
"$clusterTime" : {
"clusterTime" : Timestamp(1618812138, 3),
"signature" : {
"hash" : BinData(0,"gjGNaEdpTSZLmXRTVemQwphnW2Q="),
"keyId" : NumberLong("6941260985399246879")
}
}
}
mongos>
mongos>
mongos> sh.getBalancerState()
false

重新打开balance

mongos> sh.setBalancerState(true)
{
"ok" : 1,
"operationTime" : Timestamp(1618812177, 3),
"$clusterTime" : {
"clusterTime" : Timestamp(1618812177, 3),
"signature" : {
"hash" : BinData(0,"U6MqfK6GmY8Bv3jMRZbCJTJPZdY="),
"keyId" : NumberLong("6941260985399246879")
}
}
}
mongos> sh.getBalancerState()
true

删除balance时间窗口

mongos> use config
switched to db config
mongos> db.settings.update({ _id : "balancer" }, { $unset : { activeWindow : true } })
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
mongos>
mongos> db.settings.find()
{ "_id" : "balancer", "mode" : "full", "stopped" : false }
{ "_id" : "autosplit", "enabled" : true }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: