从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分片集群还原的更多相关文章

  1. MongoDB分片集群原理、搭建及测试详解

    随着技术的发展,目前数据库系统对于海量数据的存储和高效访问海量数据要求越来越高,MongoDB分片机制就是为了解决海量数据的存储和高效海量数据访问而生. MongoDB分片集群由mongos路由进程( ...

  2. mongodb分片集群

    第一章 1.mongodb 分片集群解释和目的 一组Mongodb复制集,就是一组mongod进程,这些进程维护同一个数据集合.复制集提供了数据冗余和高等级的可靠性,这是生产部署的基础. 第二章 1. ...

  3. TiDB和MongoDB分片集群架构比较

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 最近阅读了TiDB源码的说明文档,跟MongoDB的分片集群做了下简单对比. 首先展示TiDB的整体架构 M ...

  4. 搭建MongoDB分片集群

    在部门服务器搭建MongoDB分片集群,记录整个操作过程,朋友们也可以参考. 计划如下: 用5台机器搭建,IP分别为:192.168.58.5.192.168.58.6.192.168.58.8.19 ...

  5. 网易云MongoDB分片集群(Sharding)服务已上线

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MongoDB sharding cluster(分片集群)是MongoDB提供的数据在线水平扩展方案,包括 ...

  6. MongoDB 分片集群实战

    背景 在如今的互联网环境下,海量数据已随处可见并且还在不断增长,对于如何存储处理海量数据,比较常见的方法有两种: 垂直扩展:通过增加单台服务器的配置,例如使用更强悍的 CPU.更大的内存.更大容量的磁 ...

  7. CentOS7+Docker+MangoDB下部署简单的MongoDB分片集群

    简单的在Docker上快速部署MongoDB分片集群 前言 文中使用的环境如下 OS:CentOS Linux release 7.5.1804 (Core) Docker:Docker versio ...

  8. Windows 搭建MongoDB分片集群(二)

    在本篇博客中我们主要讲描述分片集群的搭建过程.配置分片集群主要有两个步骤,第一启动所有需要的mongod和mongos进程.第二步就是启动一个mongos与集群通信.下面我们一步步来描述集群的搭建过程 ...

  9. Windows 搭建MongoDB分片集群(一)

    一.角色说明 要构建一个MongoDB分片集群,需要三个角色: shard server  即存储实际数据得分片,每个shard 可以是一个Mongod实例,也可以是一组mongod实例构成得Repl ...

随机推荐

  1. 5.PHP内核探索:多进程/线程的SAPI生命周期

    多进程的SAPI生命周期 通常PHP是编译为apache的一个模块来处理PHP请求.Apache一般会采用多进程模式, Apache启动后会fork出多个子进程,每个进程的内存空间独立,每个子进程都会 ...

  2. ubuntu Nodejs和npm的安装

     cnpm install -g XXX errors :  npm i --registry=https://registry.npm.taobao.org     标签: nodejsnpm 20 ...

  3. Memcached Java Client API详解

    针对Memcached官方网站提供的java_memcached-release_2.0.1版本进行阅读分析,Memcached Java客户端lib库主要提供的调用类是SockIOPool和MemC ...

  4. 【Android测试】【第三节】ADB——源码浅谈

    ◆版权声明:本文出自carter_dream的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4651724.html 前言 由于本人精力 ...

  5. angularJS自定义指令模板替换

    <html> <head> <meta charset="utf-8"/> <title></title> </h ...

  6. js实现表格中不同单元格内容的替换(不同浏览器的节点属性兼容问题)

      ------->   效果:点击右下角单元格,左下角单元格内容被替换成和左上角相同,如上图所示. 实现方式:分别获取各个节点,并将左边节点的内容修改成左上方节点的内容. 代码: 注意的地方: ...

  7. Mac终端命令行提示符格式更改方法

    内容提要: 主要是通过~/.bash_profile文件更改环境变量PS1,修改命令行提示符的显示格式,并展示不同颜色. 本文介绍了默认设置的缺陷,以及需要用到的基础知识,最后介绍了更改命令行提示符格 ...

  8. NuGet的几个小技巧

    因为是转载文章 在此标明出处,以前有文章是转的没标明的请谅解,因为有些已经无法找到出处,或者与其它原因. 如有冒犯请联系本人,或删除,或标明出处. 因为好的文章,以前只想收藏,但连接有时候会失效,所以 ...

  9. magento

     打开 magento/app/code/core/Mage/Core/Model/Session/Abstract/varien.php//if (isset($cookieParams['doma ...

  10. Maven-002-eclipse 插件安装及实例

    因为平常编码的时候,习惯了使用 eclipse 进行编码,因而需要将 eclipse 安装 maven 的插件,安装步骤如下所示: 一.安装 选择菜单: help -> Install New  ...