温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MongoDB Sharding学习操作篇二

发布时间:2020-07-21 11:01:35 来源:网络 阅读:562 作者:自由linux 栏目:MongoDB数据库

接上一篇

14.配置集群中的balancer进程

balancer进程运行在集群中的某一个mongos实例上,确保chunks均匀分布在整个集群上。


更改指定shard的最大存储大小




15.移除已有分片集群中的一个分片

在移除一个分片之前需要先确保这个分片上的数据已经移动到其他分片上。

1)确保Blancer进程已经开启

sh.getBalancerState()

2)确定需要被移除的分片名称

db.adminCommand( { listShards: 1 } )

或者

db.printShardingStatus()

或者

sh.status()


3)移走分片上的数据块

mongos> use admin;
switched to db admin
mongos> db.runCommand({removeShard : "taiwan_shard1"})
{
	"msg" : "draining started successfully",
	"state" : "started",
	"shard" : "taiwan_shard1",
	"ok" : 1
}


根据网络状况和数据量大小,这个操作可能花费几分钟或者几天时间完成


4)检查迁移的状态

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
}


这里需要注意的是,如果一个分片是一个或者多个数据库的primary shard,那么这个分片上就存有未被分片的数据。

mongos> use admin;
switched to db admin
mongos> 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)结束迁移过程

mongos> db.runCommand({removeShard : "taiwan_shard1"})
{
	"msg" : "removeshard completed successfully",
	"state" : "completed",
	"shard" : "taiwan_shard1",
	"ok" : 1
}

当state状态为completed时,迁移完成。




参考文档:

http://docs.mongodb.org/v2.4/tutorial/remove-shards-from-cluster/


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI