🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] > [参考](https://blog.51cto.com/john88wang/1619817) ## 1. 确保Blancer进程已经开启 ``` mongos> sh.getBalancerState() true // 开启 mongos > sh.startBalancer(); /*{ "ok" : 1 }*/ //停止 mongos > sh.stopBalancer(); /*{ "ok" : 1 }*/ ``` ## 2.移走你要的分片 ``` mongos> sh.status(); mongos> use admin; //移走分片上的数据块 mongos> db.runCommand({removeShard : "shard3"}) // 查看迁移状态 mongos> db.runCommand({removeShard : "shard3"}) /* { "msg" : "draining ongoing", "state" : "ongoing", "remaining" : { "chunks" : NumberLong(0), //降为0 "dbs" : NumberLong(2) }, "note" : "you need to drop or movePrimary these databases", "dbsToMove" : [ "taiwan_game4", "taiwan_game5" ], "ok" : 1 } */ ``` ## 如果一个分片是一个或者多个数据库的primary shard ``` mongos> use admin; mongos> db.runCommand( { movePrimary: "taiwan_game4", to: "taiwan_shard2" }) mongos> db.runCommand( { movePrimary: "taiwan_game5", to: "taiwan_shard2" }) ``` ## 结束迁移过程 ``` mongos> db.runCommand({removeShard : "taiwan_shard1"}) { "msg" : "removeshard completed successfully", "state" : "completed", "shard" : "taiwan_shard1", "ok" : 1 } ``` 当state状态为completed时,迁移完成。