MongoDB分片集群还原
从mongodb 3.0开始,mongorestore还原的时候,需要一个运行着的实例。早期的版本没有这个要求。
1.为每个分片部署一个复制集
(1)复制集中的每个成员启动一个mongod
- mongod --dbpath /mdb/data/s11 --logpath /mdb/mlog/s11.log --fork --port 27017 --replSet s1 --smallfiles &
- mongod --dbpath /mdb/data/s12 --logpath /mdb/mlog/s12.log --fork --port 27018 --replSet s1 --smallfiles &
- mongod --dbpath /mdb/data/s21 --logpath /mdb/mlog/s21.log --fork --port 27019 --replSet s2 --smallfiles &
- mongod --dbpath /mdb/data/s22 --logpath /mdb/mlog/s22.log --fork --port 27020 --replSet s2 --smallfiles &
(2)通过mongo连接到实例,运行:
- mongo --port=27017
- >rs.initiate()
- >rs.add("11.11.11.195:27018")
- mongo --port=27019
- >rs.initiate()
- >rs.add("11.11.11.195:27020")
2.部署config服务器
- mongod --dbpath /mdb/data/sc --logpath /mdb/mlog/sc.log --fork --port 27021 --configsvr &
3.启动mongos实例
- mongos --logpath /mdb/mlog/ss.log --fork --port 30000 --configdb 11.11.11.195:27021
4.集群添加分片
- 登陆路由器
- ./mongo --port 30000
- 增加片节点
- sh.addShard("s1/11.11.11.195:27018")
- sh.addShard("s2/11.11.11.195:27020")
- mongos> sh.status()
- --- Sharding Status ---
- sharding version: {
- "_id" : 1,
- "minCompatibleVersion" : 5,
- "currentVersion" : 6,
- "clusterId" : ObjectId("5722c003710922b361783847")
- }
- shards:
- { "_id" : "s1", "host" : "s1/11.11.11.195:27018,11.11.11.195:27017" }
- { "_id" : "s2", "host" : "s2/11.11.11.195:27020,11.11.11.195:27019" }
- balancer:
- Currently enabled: yes
- Currently running: no
- Failed balancer rounds in last 5 attempts: 0
- Migration Results for the last 24 hours:
- No recent migrations
- databases:
- { "_id" : "admin", "partitioned" : false, "primary" : "config" }
- mongos>
5.关闭mongos instances
分片集群启动后,关闭mongos实例
6.还原分片数据
- mongorestore --drop /mdb/bin/s1 --port 27017
- 2016-04-29T10:20:20.643+0800 building a list of dbs and collections to restore from /mdb/bin/s1 dir
- 2016-04-29T10:20:20.657+0800 reading metadata file from /mdb/bin/s1/snps/elegans.metadata.json
- 2016-04-29T10:20:20.658+0800 reading metadata file from /mdb/bin/s1/test/system.users.metadata.json
- 2016-04-29T10:20:20.658+0800 reading metadata file from /mdb/bin/s1/snps/system.users.metadata.json
- 2016-04-29T10:20:20.658+0800 restoring snps.elegans from file /mdb/bin/s1/snps/elegans.bson
- 2016-04-29T10:20:20.658+0800 restoring test.system.users from file /mdb/bin/s1/test/system.users.bson
- 2016-04-29T10:20:20.666+0800 restoring snps.system.users from file /mdb/bin/s1/snps/system.users.bson
- 2016-04-29T10:20:22.974+0800 restoring indexes for collection snps.system.users from metadata
- 2016-04-29T10:20:22.975+0800 finished restoring snps.system.users
- 2016-04-29T10:20:23.073+0800 restoring indexes for collection test.system.users from metadata
- 2016-04-29T10:20:23.074+0800 finished restoring test.system.users
- 2016-04-29T10:20:23.644+0800 [##......................] snps.elegans 1.6 MB/13.3 MB (11.8%)
- 2016-04-29T10:20:26.644+0800 [##############..........] snps.elegans 7.9 MB/13.3 MB (59.3%)
- 2016-04-29T10:20:29.239+0800 restoring indexes for collection snps.elegans from metadata
- 2016-04-29T10:20:29.660+0800 finished restoring snps.elegans
- 2016-04-29T10:20:29.660+0800 done
- mongorestore --drop /mdb/bin/s2 --port 27019
- 2016-04-29T10:20:44.153+0800 building a list of dbs and collections to restore from /mdb/bin/s2 dir
- 2016-04-29T10:20:44.165+0800 reading metadata file from /mdb/bin/s2/snps/elegans.metadata.json
- 2016-04-29T10:20:44.165+0800 restoring snps.elegans from file /mdb/bin/s2/snps/elegans.bson
- 2016-04-29T10:20:44.184+0800 restoring indexes for collection snps.elegans from metadata
- 2016-04-29T10:20:44.186+0800 finished restoring snps.elegans
- 2016-04-29T10:20:44.186+0800 done
然后关闭所有分片实例
7.还原config server数据
- mongorestore --drop /mdb/bin/config_server --port 27021
- 2016-04-29T10:26:24.294+0800 building a list of dbs and collections to restore from /mdb/bin/config_server dir
- 2016-04-29T10:26:24.296+0800 reading metadata file from /mdb/bin/config_server/config/changelog.metadata.json
- 2016-04-29T10:26:24.296+0800 reading metadata file from /mdb/bin/config_server/config/locks.metadata.json
- 2016-04-29T10:26:24.297+0800 restoring config.locks from file /mdb/bin/config_server/config/locks.bson
- 2016-04-29T10:26:24.297+0800 reading metadata file from /mdb/bin/config_server/config/actionlog.metadata.json
- 2016-04-29T10:26:24.302+0800 reading metadata file from /mdb/bin/config_server/config/chunks.metadata.json
- 2016-04-29T10:26:24.302+0800 restoring config.chunks from file /mdb/bin/config_server/config/chunks.bson
- 2016-04-29T10:26:24.303+0800 restoring indexes for collection config.locks from metadata
- 2016-04-29T10:26:24.303+0800 restoring config.actionlog from file /mdb/bin/config_server/config/actionlog.bson
- 2016-04-29T10:26:24.303+0800 restoring indexes for collection config.chunks from metadata
- 2016-04-29T10:26:24.304+0800 restoring config.changelog from file /mdb/bin/config_server/config/changelog.bson
- 2016-04-29T10:26:24.304+0800 finished restoring config.locks
- 2016-04-29T10:26:24.306+0800 restoring indexes for collection config.actionlog from metadata
- 2016-04-29T10:26:24.306+0800 reading metadata file from /mdb/bin/config_server/config/shards.metadata.json
- 2016-04-29T10:26:24.306+0800 restoring config.shards from file /mdb/bin/config_server/config/shards.bson
- 2016-04-29T10:26:24.307+0800 finished restoring config.chunks
- 2016-04-29T10:26:24.307+0800 finished restoring config.actionlog
- 2016-04-29T10:26:24.307+0800 restoring indexes for collection config.shards from metadata
- 2016-04-29T10:26:24.308+0800 restoring indexes for collection config.changelog from metadata
- 2016-04-29T10:26:24.308+0800 reading metadata file from /mdb/bin/config_server/config/databases.metadata.json
- 2016-04-29T10:26:24.308+0800 restoring config.databases from file /mdb/bin/config_server/config/databases.bson
- 2016-04-29T10:26:24.308+0800 reading metadata file from /mdb/bin/config_server/config/lockpings.metadata.json
- 2016-04-29T10:26:24.308+0800 finished restoring config.shards
- 2016-04-29T10:26:24.308+0800 reading metadata file from /mdb/bin/config_server/config/collections.metadata.json
- 2016-04-29T10:26:24.308+0800 finished restoring config.changelog
- 2016-04-29T10:26:24.309+0800 restoring config.lockpings from file /mdb/bin/config_server/config/lockpings.bson
- 2016-04-29T10:26:24.309+0800 restoring config.collections from file /mdb/bin/config_server/config/collections.bson
- 2016-04-29T10:26:24.325+0800 reading metadata file from /mdb/bin/config_server/config/mongos.metadata.json
- 2016-04-29T10:26:24.325+0800 restoring indexes for collection config.databases from metadata
- 2016-04-29T10:26:24.326+0800 restoring config.mongos from file /mdb/bin/config_server/config/mongos.bson
- 2016-04-29T10:26:24.326+0800 restoring indexes for collection config.lockpings from metadata
- 2016-04-29T10:26:24.327+0800 restoring indexes for collection config.collections from metadata
- 2016-04-29T10:26:24.327+0800 finished restoring config.databases
- 2016-04-29T10:26:24.327+0800 finished restoring config.lockpings
- 2016-04-29T10:26:24.328+0800 reading metadata file from /mdb/bin/config_server/config/version.metadata.json
- 2016-04-29T10:26:24.328+0800 restoring config.version from file /mdb/bin/config_server/config/version.bson
- 2016-04-29T10:26:24.328+0800 reading metadata file from /mdb/bin/config_server/config/settings.metadata.json
- 2016-04-29T10:26:24.328+0800 restoring config.settings from file /mdb/bin/config_server/config/settings.bson
- 2016-04-29T10:26:24.328+0800 finished restoring config.collections
- 2016-04-29T10:26:24.328+0800 reading metadata file from /mdb/bin/config_server/config/tags.metadata.json
- 2016-04-29T10:26:24.328+0800 restoring config.tags from file /mdb/bin/config_server/config/tags.bson
- 2016-04-29T10:26:24.366+0800 restoring indexes for collection config.tags from metadata
- 2016-04-29T10:26:24.366+0800 restoring indexes for collection config.settings from metadata
- 2016-04-29T10:26:24.366+0800 restoring indexes for collection config.version from metadata
- 2016-04-29T10:26:24.375+0800 restoring indexes for collection config.mongos from metadata
- 2016-04-29T10:26:24.376+0800 finished restoring config.settings
- 2016-04-29T10:26:24.376+0800 finished restoring config.tags
- 2016-04-29T10:26:24.376+0800 finished restoring config.mongos
- 2016-04-29T10:26:24.376+0800 finished restoring config.version
- 2016-04-29T10:26:24.376+0800 done
8.启动mongos instance
- mongos --logpath /mdb/mlog/ss.log --fork --port 30000 --configdb 11.11.11.195:27021
- 2016-04-29T10:27:56.855+0800 W SHARDING running with 1 config server should be done only for testing purposes and is not recommended for production
- about to fork child process, waiting until server is ready for connections.
- forked process: 25444
- child process started successfully, parent exiting
9.如果shard的主机名发生了变化,需要更新config数据库
- mongos> db.shards.find()
- { "_id" : "s1", "host" : "s1/genome_svr1:27501,genome_svr2:27502,genome_svr2:27503" }
- { "_id" : "s2", "host" : "s2/genome_svr4:27601,genome_svr5:27602,genome_svr5:27603" }
- mongos> db.shards.update( { "_id": "s1" }, { $set: { "host": "s1/11.11.11.195:27017,11.11.11.195:27018" } }, { multi: true })
- mongos> db.shards.update( { "_id": "s2" }, { $set: { "host": "s2/11.11.11.195:27019,11.11.11.195:27020" } }, { multi: true })
- mongos> db.shards.find()db.shards.find()
- { "_id" : "s1", "host" : "s1/11.11.11.195:27018,11.11.11.195:27017" }
- { "_id" : "s2", "host" : "s2/11.11.11.195:27020,11.11.11.195:27019" }
- mongos>
10.重启所有的shard mongod实例
11.重启其它的mongos实例
12.验证集群环境
- mongos> db.printShardingStatus()
- --- Sharding Status ---
- sharding version: {
- "_id" : 1,
- "minCompatibleVersion" : 5,
- "currentVersion" : 6,
- "clusterId" : ObjectId("553f0cc819d7841961ac8f4b")
- }
- shards:
- { "_id" : "s1", "host" : "s1/11.11.11.195:27018,11.11.11.195:27017" }
- { "_id" : "s2", "host" : "s2/11.11.11.195:27020,11.11.11.195:27019" }
- balancer:
- Currently enabled: yes
- Currently running: no
- Failed balancer rounds in last 5 attempts: 0
- Migration Results for the last 24 hours:
- No recent migrations
- databases:
- { "_id" : "admin", "partitioned" : false, "primary" : "config" }
- { "_id" : "snps", "partitioned" : true, "primary" : "s1" }
- snps.elegans
- shard key: { "snp" : 1 }
- chunks:
- s1 1
- s2 1
- { "snp" : { "$minKey" : 1 } } -->> { "snp" : "haw100000" } on : s2 Timestamp(2, 0)
- { "snp" : "haw100000" } -->> { "snp" : { "$maxKey" : 1 } } on : s1 Timestamp(2, 1)
- { "_id" : "test", "partitioned" : false, "primary" : "s1" }
- mongos>
MongoDB分片集群还原的更多相关文章
- MongoDB分片集群原理、搭建及测试详解
随着技术的发展,目前数据库系统对于海量数据的存储和高效访问海量数据要求越来越高,MongoDB分片机制就是为了解决海量数据的存储和高效海量数据访问而生. MongoDB分片集群由mongos路由进程( ...
- mongodb分片集群
第一章 1.mongodb 分片集群解释和目的 一组Mongodb复制集,就是一组mongod进程,这些进程维护同一个数据集合.复制集提供了数据冗余和高等级的可靠性,这是生产部署的基础. 第二章 1. ...
- TiDB和MongoDB分片集群架构比较
此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 最近阅读了TiDB源码的说明文档,跟MongoDB的分片集群做了下简单对比. 首先展示TiDB的整体架构 M ...
- 搭建MongoDB分片集群
在部门服务器搭建MongoDB分片集群,记录整个操作过程,朋友们也可以参考. 计划如下: 用5台机器搭建,IP分别为:192.168.58.5.192.168.58.6.192.168.58.8.19 ...
- 网易云MongoDB分片集群(Sharding)服务已上线
此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MongoDB sharding cluster(分片集群)是MongoDB提供的数据在线水平扩展方案,包括 ...
- MongoDB 分片集群实战
背景 在如今的互联网环境下,海量数据已随处可见并且还在不断增长,对于如何存储处理海量数据,比较常见的方法有两种: 垂直扩展:通过增加单台服务器的配置,例如使用更强悍的 CPU.更大的内存.更大容量的磁 ...
- CentOS7+Docker+MangoDB下部署简单的MongoDB分片集群
简单的在Docker上快速部署MongoDB分片集群 前言 文中使用的环境如下 OS:CentOS Linux release 7.5.1804 (Core) Docker:Docker versio ...
- Windows 搭建MongoDB分片集群(二)
在本篇博客中我们主要讲描述分片集群的搭建过程.配置分片集群主要有两个步骤,第一启动所有需要的mongod和mongos进程.第二步就是启动一个mongos与集群通信.下面我们一步步来描述集群的搭建过程 ...
- Windows 搭建MongoDB分片集群(一)
一.角色说明 要构建一个MongoDB分片集群,需要三个角色: shard server 即存储实际数据得分片,每个shard 可以是一个Mongod实例,也可以是一组mongod实例构成得Repl ...
随机推荐
- PHP+jQuery 注册模块的改进之三:使用 Smarty3
Smarty3.1X( 最新版本 3.1.19) 比起Smarty2.x修改了不少特性.我把这个模块使用Smarty3.1.18 ( 下载地址http://www.smarty.net/files/S ...
- 使用PHP获取网站Favicon的方法
使用PHP获取网站Favicon的方法 Jan022014 作者:Jerry Bendy 发布:2014-01-02 23:18 分类:PHP 阅读:4,357 views 20条评论 ...
- link them together by means of pointers
Computer Science An Overview _J. Glenn Brookshear _11th Edition An alternative to storing a heteroge ...
- linux下常用的命令
一. tomcat tail -f ../logs/catalina.out 最新更新的日志(tomcat) cat ../logs/catalina ...
- 批处理快速创建wifi
为什么要用cmd这种古老的东西创建wifi呢,电脑管家.360安全卫士都有这种插件,一键开启关闭,多方便啊! 开始用的也是电脑管家的免费wifi插件,但是我越来越不能忍它极慢的启动关闭过程,每一次看着 ...
- jdk1.7
http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe?AuthParam=1450748157_ ...
- error: jump to label ‘XXXX’ [-fpermissive]
http://www.cnblogs.com/foohack/p/4090124.html 下面的类似的源码在MSVC上能正确编译通过.但是gcc/g++上就会错: 1. if(expr)2. got ...
- 查看linux库文件32位还是64位
查看linux库文件32位还是64位 分类: linux2014-09-25 09:46 238人阅读 评论(0) 收藏 举报 objdump -a *.a objdump -a *.so
- 用正则验证字符串格式,形如:A)XXX B)XXXX C)XXX
今天遇到个小功能,要验证某个英文选项是否正确,例如:A)accumulate B)circling C)communities D)competition E)domestic F)financi ...
- php curl多线程抓取网页
PHP 利用 Curl Functions 可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,受限于php语言本身不支持多线程,所以开发爬虫程序效率并不高,这时候往往需 要借助Cu ...