MongoDB Sharding Learning Operation part 2
Take on the last article
14. Configure the balancer process in the cluster
The balancer process runs on one of the mongos instances in the cluster, ensuring that the chunks is evenly distributed across the cluster.
Change the maximum storage size of the specified shard
15. Remove a shard from an existing sharding cluster
Before removing a shard, you need to make sure that the data on that shard has been moved to another shard.
1) make sure that the Blancer process is enabled
Sh.getBalancerState ()
2) determine the name of the shard to be removed
Db.adminCommand ({listShards: 1})
Or
Db.printShardingStatus ()
Or
Sh.status ()
3) remove data blocks from the shard
Mongos > use admin;switched to db adminmongos > db.runCommand ({removeShard: "taiwan_shard1"}) {"msg": "draining started successfully", "state": "started", "shard": "taiwan_shard1", "ok": 1}
Depending on the state of the network and the amount of data, this operation may take several minutes or days to complete.
4) check the status of the migration
Mongos > db.runCommand ({removeShard: "taiwan_shard1"}) {"msg": "draining ongoing", "state": "ongoing", "remaining": {"chunks": NumberLong (0), "dbs": NumberLong (2)}, "note": "you need to drop or movePrimary these databases" "dbsToMove": ["taiwan_game4", "taiwan_game5"], "ok": 1}
It is important to note that if a shard is the primary shard of one or more databases, then the shard contains unshredded data.
Mongos > use admin Switched to db adminmongos > db.runCommand ({movePrimary: "taiwan_game4", to: "taiwan_shard2"}) {"primary": "taiwan_shard2:taiwan_shard2/gintama-taiwan-mongodb2:28018", "ok": 1} mongos > db.runCommand ({movePrimary: "taiwan_game5", to: "taiwan_shard2"}) {"primary": "taiwan_shard2:taiwan_shard2/gintama-taiwan-mongodb2:28018" "ok": 1}
5) end the migration process
Mongos > db.runCommand ({removeShard: "taiwan_shard1"}) {"msg": "removeshard completed successfully", "state": "completed", "shard": "taiwan_shard1", "ok": 1}
When the state status is completed, the migration is complete.
Reference documentation:
Http://docs.mongodb.org/v2.4/tutorial/remove-shards-from-cluster/