mongodb移除分片
MongoDB的Shard集群来说,添加一个分片很简单,AddShard就可以了。
但是缩减集群(删除分片)这种一般很少用到。由于曙光的某服务器又挂了,所以我们送修之前必须把它上面的数据自动迁移到其他Shard上。
1、执行RemoveShard命令
1 |
db.runCommand( { removeshard: "your_shard_name" } ) |
2 |
3 |
{ msg : "draining started successfully" , state: "started" , shard : "mongodb0" , ok : 1 } |
上面这句会立即返回,实际在后台执行。
2、查看迁移状态
我们可以反复执行上面语句,查看执行结果。
1 |
db.runCommand( { removeshard: "your_shard_name" } ) |
2 |
3 |
{ msg: "draining ongoing" , state: "ongoing" , remaining: { chunks: 42, dbs : 1 }, ok: 1 } |
从上面可以看到,正在迁移,还剩下42块没迁移完。
当remain为0之后,这一步就结束了。
3、移出非Shard数据
1 |
db.runCommand( { movePrimary: "myapp" , to: "mongodb1" }) |
这次就不是立即返回了,需要很久,然后会返回如下:
1 |
{ "primary" : "mongodb1" , "ok" : 1 } |
4、最后的清理
上面步骤都完成后,还需要再执行一次RemoveShard,清理残余数据。
1 |
db.runCommand( { removeshard: "mongodb0" } ) |
执行成功后,会如下结果:
1 |
{ msg: "remove shard completed succesfully" , stage: "completed" , host: "mongodb0" , ok : 1 } |
显示completed后,就可以安心的关闭mongod的进程了。
一些遇到的问题:
Popgo: In my MongoDB sharding cluster, i used db.runCommand( { removeshard: "shard3" } )
command to remove a shard "shard3", but it just puts the shard in draining mode, which will never end and three days past. All chunks of the shard "shard3" are moved into "shard1" or "shard2", but the APP read request can use it to query data. So i want to know which process of the sharding now or how to diagnose this problem?
MrKurt:You probably have a database using shard3
as its primary shard, check the output ofdb.printShardingStatus()
to see where each database resides.
Once you figure out which database it is, move it to a different shard with the movePrimary
command. Then run removeShard
again and you should be good to go.
Popgo:
It is confirmed that there is a unsharded database test on the shard "shard3" and "shard3" is not the primary shard, then i drop "test" database and re-run removeshard
command. It is success to remove the "shard3". From document, "Do not run the movePrimary until you have finished draining the shard". But our program also use the "shard3" with 3 nodes replicaset to query data. Why not to router APP requests to other available shards by mongos server?
Andre: You do need to run movePrimary to complete draining in the case of a db being on the primary. If you look at the results of the removeshard
and see "chunks" : NumberLong(0)
but "dbs": NumberLong(
some number other than 0 )
you probably have a DB whose primary is the shard you are removing and will probably have to run movePrimary even though removeshard
hasn't said "draining is complete". Check out this discussion on mongodb-user for more information:
相关的官方文档:http://docs.mongodb.org/manual/tutorial/remove-shards-from-cluster/
注意官方关于是否需要运行movePrimary的说明:
Databases with non-sharded collections store those collections on a single shard known as the primary shardfor that database. The following step is necessary only when the shard to remove is also the primary shard for one or more databases.
也就是说,如果在这个片上有非分片的collection,这样的话,分片的数据合到其他片上了,那么剩下的非分片数据,没法通过合并分片的方式合到其他服务器上,所以这时要运行一个movePrimary命令将这些非分片的数据移到另一个服务器上。db.runCommand( { movePrimary: "myapp", to: "mongodb1" })
This command migrates all remaining non-sharded data in the database named myapp to the shard namedmongodb1
还有一个官方说明需要注意的是:
Warning
Do not run the movePrimary until you have finished draining the shard
也就是说,一定要等到分片数据迁移完了,再运行movePrimary命令!!!
而且这句命令不像removeshard是异步的,这个movePrimary命令会等到将所有非分片数据都移到其他服务器后,才响应,所以时间有可能会比较长,主要还是看这个服务器上,非分片数据有多少。
另外,movePrimary执行完后,还记得将db.runCommand({removeshard:"shardx"})再运行一遍,直到看到如下结果{ msg: "remove shard completed successfully" , stage: "completed", host: "mongodb0", ok : 1 }
到此为止,迁移才真正完成,可以放心地关闭mongod。
about how to identify the non-sharding databases int server2, to run:db.printShardingStatus();
to, you can use the printShardingStatus command. It will tell you what
is the "primary" shard for each non-partitioned database.
If any of the DBs have the drained shard listed as the primary, you
will need to issue a move primary command (again listed on the page
linked).
mongodb移除分片的更多相关文章
- mongodb移除分片和添加分片(转)
首先我们要移除的分片之后再次添加此分片时会出现添加失败的情况,需要在添加的分片上登录进行删除此分片之前数据库的历史数据比如testdb,删除分片上的数据库之后就可重新添加此分片到mongos中 1.执 ...
- Mongodb 笔记07 分片、配置分片、选择片键、分片管理
分片 1. 分片(sharding)是指将数据拆分,将其分散存放在不同的机器上的过程.有时也用分区(partitioning)来表示这个概念.将数据分散到不同的机器上,不需要功能强大的大型计算机就可以 ...
- [置顶] MongoDB 分布式操作——分片操作
MongoDB 分布式操作——分片操作 描述: 像其它分布式数据库一样,MongoDB同样支持分布式操作,且MongoDB将分布式已经集成到数据库中,其分布式体系如下图所示: 所谓的片,其实就是一个单 ...
- MySQL Cluster 与 MongoDB 复制群集分片设计及原理
分布式数据库计算涉及到分布式事务.数据分布.数据收敛计算等等要求 分布式数据库能实现高安全.高性能.高可用等特征,当然也带来了高成本(固定成本及运营成本),我们通过MongoDB及MySQL Clus ...
- MongoDB学习笔记——分片(Sharding)
分片(Sharding) 分片就是将数据进行拆分,并将其分别存储在不同的服务器上 MongoDB支持自动分片能够自动处理数据在分片上的分布 MongoDB分片有三种角色 配置服务器:一个单独的mong ...
- 【七】MongoDB管理之分片集群介绍
分片是横跨多台主机存储数据记录的过程,它是MongoDB针对日益增长的数据需求而采用的解决方案.随着数据的快速增长,单台服务器已经无法满足读写高吞吐量的需求.分片通过水平扩展的方式解决了这个问题.通过 ...
- 测试MongoDB的自动分片
MongoDB的自动分片: test库分片配置: db.shards.find(){ "_id" : "shard0000", "host" ...
- MongoDB 副本集+分片 认证方式搭建
MongoDB 副本集+分片 认证方式搭建 参考资料: https://www.cnblogs.com/ityouknow/p/7344005.htmlhttps://jorwen-fang.itey ...
- MongoDB集群分片部署
MongoDB中使用分片集群结构分布: 三个主要组件: Shard: 用于存储实际的数据块,实际生产环境中一个shard server角色可由几台机器组个一个replica set承担,防止主机单点故 ...
随机推荐
- 《Mastering Opencv ...读书笔记系列》车牌识别(I)
http://blog.csdn.net/jinshengtao/article/details/17883075/ <Mastering Opencv ...读书笔记系列>车牌识别(I ...
- socket的accept函数解析
今天与同学争执一个话题:由于socket的accept函数在有客户端连接的时候产生了新的socket用于服务该客户端,那么,这个新的socket到底有没有占用一个新的端口? 讨论完后,才发现,自己虽然 ...
- javascript基础(三)运算
原文http://pij.robinqu.me/ 递增递减操作符(包括前置和后置).一元正负符号操作符 这些操作符适用于任何数据类型的值,针对不同类型的值,该操作符遵循以下规则(经过对比发现,其规则与 ...
- CSS制作照片墙
资料来源:慕课网(点击这里) 课程结束后有两个效果: 效果一:CSS制作照片墙(点击这里) 效果二:旋转出现文字效果(点击这里) 实现代码: <!DOCTYPE html> <htm ...
- Excel教程(6) - 外部函数
EUROCONVERT 用途:将数字转换为欧元形式,将数字由欧元形式转换为 欧盟成员国货币形式,或利用欧元作为中间货币将数字由某一 欧盟成员国货币转化为另一欧盟成员国货币的形式(三角转换 关系). 语 ...
- C库 - 常用文件IO函数
#include<stdio.h> 0. 文件打开关闭FILE *fp = fopen("C:\\a.dat","wb+");fclose(fp); ...
- NOIP2012-普及组复赛-第一题-质因数分解
题目描述 Description 已知正整数n是两个不同的质数的乘积,试求出两者中较大的那个质数. 输入输出格式 Input/output 输入格式:输入只有一行,包含一个正整数n.输出格式:输出只 ...
- IAR和Keil文件包含路径设置
在模块化编程时,为一个模块单独设置头文件是必不可少的. 在两款主流编译器中,在引用模块函数时候,包含头文件路径是必须的,那么设置文件路径的准确性就显得尤为重要. 否则,编译器会报错,无法打开某某头文件 ...
- 关于css的hack问题
<!--[if <keywords>? IE <version>?]> HTML代码块 <![endif]--> 取值: <keywords> ...
- zabbix3.2在lamp环境安装
zabbix官网下载zabbix-3.2.1.tar.gz wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20 ...