开发者社区> zhangshengdong> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

MongoDB副本集--Secondary节点恢复实例

简介: MongoDB副本集中有一台Secondary节点出现RECOVERING的状态 点击(此处)折叠或打开 arps:RECOVERING> rs.
+关注继续查看
MongoDB副本集中有一台Secondary节点出现RECOVERING的状态

点击(此处)折叠或打开

  1. arps:RECOVERING> rs.status()rs.status()
  2. {
  3.         "set" : "arps",
  4.         "date" : ISODate("2017-12-22T02:31:58.803Z"),
  5.         "myState" : 3,
  6.         "members" : [
  7.                 {
  8.                         "_id" : 0,
  9.                         "name" : "172.17.4.37:27017",
  10.                         "health" : 1,
  11.                         "state" : 2,
  12.                         "stateStr" : "SECONDARY",
  13.                         "uptime" : 7579839,
  14.                         "optime" : Timestamp(1513909913, 3),
  15.                         "optimeDate" : ISODate("2017-12-22T02:31:53Z"),
  16.                         "lastHeartbeat" : ISODate("2017-12-22T02:31:58.019Z"),
  17.                         "lastHeartbeatRecv" : ISODate("2017-12-22T02:31:57.750Z"),
  18.                         "pingMs" : 0,
  19.                         "syncingTo" : "172.17.4.38:27017",
  20.                         "configVersion" : 1
  21.                 },
  22.                 {
  23.                         "_id" : 1,
  24.                         "name" : "172.17.4.38:27017",
  25.                         "health" : 1,
  26.                         "state" : 1,
  27.                         "stateStr" : "PRIMARY",
  28.                         "uptime" : 7579913,
  29.                         "optime" : Timestamp(1513909913, 3),
  30.                         "optimeDate" : ISODate("2017-12-22T02:31:53Z"),
  31.                         "lastHeartbeat" : ISODate("2017-12-22T02:31:58.051Z"),
  32.                         "lastHeartbeatRecv" : ISODate("2017-12-22T02:31:58.018Z"),
  33.                         "pingMs" : 0,
  34.                         "electionTime" : Timestamp(1506330005, 1),
  35.                         "electionDate" : ISODate("2017-09-25T09:00:05Z"),
  36.                         "configVersion" : 1
  37.                 },
  38.                 {
  39.                         "_id" : 2,
  40.                         "name" : "172.17.4.39:27017",
  41.                         "health" : 1,
  42.                         "state" : 3,
  43.                         "stateStr" : "RECOVERING",//RECOVERING状态
  44.                         "uptime" : 7580364,
  45.                         "optime" : Timestamp(1473614444, 2),
  46.                         "optimeDate" : ISODate("2016-09-11T17:20:44Z"),
  47.                         "configVersion" : 1,
  48.                         "self" : true
  49.                 }
  50.         ],
  51.         "ok" : 1
  52. }

恢复思路:
1.关闭MongoDB故障节点的数据库服务,移除数据目录,启动MongoDB服务,开启自动同步机制,恢复secondary节点。
2.找到另外一个secondary数据节点的快照,关闭写操作。在数据不变化的情况下,获得一致性的备份快照,拷贝至故障节点中,启动MongoDB服务,应用oplog日志。恢复secondary节点。

由于环境数据量小,使用第一种方案。

1.mongodb数据库服务关闭

点击(此处)折叠或打开

  1. arps:RECOVERING> use admin
  2. switched to db admin
  3. arps:RECOVERING> db.shutdownServer()
2.删除或者移走数据目录

点击(此处)折叠或打开

  1. [root@mongodb data]# mv /opt/data/mongodb /opt/data/mongodb20171222
  2. [root@mongodb data]# mkdir /opt/data/mongodb
  3. [root@mongodb data]# mkdir /opt/data/mongodb/log
3.启动数据库服务且查看状态

点击(此处)折叠或打开

  1. [root@mongodb data]#/opt/software/mongodb-linux-x86_64-3.0.1/bin/mongod -f /opt/software/mongodb-linux-x86_64-3.0.1/bin/mongodb.conf
  2. arps:STARTUP2> rs.status()
  3. {
  4.         "set" : "arps",
  5.         "date" : ISODate("2017-12-22T02:46:52.288Z"),
  6.         "myState" : 5,
  7.         "syncingTo" : "172.17.4.38:27017",
  8.         "members" : [
  9.                 {
  10.                         "_id" : 0,
  11.                         "name" : "172.17.4.37:27017",
  12.                         "health" : 1,
  13.                         "state" : 2,
  14.                         "stateStr" : "SECONDARY",
  15.                         "uptime" : 25,
  16.                         "optime" : Timestamp(1513910813, 3),
  17.                         "optimeDate" : ISODate("2017-12-22T02:46:53Z"),
  18.                         "lastHeartbeat" : ISODate("2017-12-22T02:46:51.122Z"),
  19.                         "lastHeartbeatRecv" : ISODate("2017-12-22T02:46:51.114Z"),
  20.                         "pingMs" : 0,
  21.                         "syncingTo" : "172.17.4.38:27017",
  22.                         "configVersion" : 1
  23.                 },
  24.                 {
  25.                         "_id" : 1,
  26.                         "name" : "172.17.4.38:27017",
  27.                         "health" : 1,
  28.                         "state" : 1,
  29.                         "stateStr" : "PRIMARY",
  30.                         "uptime" : 25,
  31.                         "optime" : Timestamp(1513910813, 3),
  32.                         "optimeDate" : ISODate("2017-12-22T02:46:53Z"),
  33.                         "lastHeartbeat" : ISODate("2017-12-22T02:46:51.127Z"),
  34.                         "lastHeartbeatRecv" : ISODate("2017-12-22T02:46:51.303Z"),
  35.                         "pingMs" : 0,
  36.                         "electionTime" : Timestamp(1506330005, 1),
  37.                         "electionDate" : ISODate("2017-09-25T09:00:05Z"),
  38.                         "configVersion" : 1
  39.                 },
  40.                 {
  41.                         "_id" : 2,
  42.                         "name" : "172.17.4.39:27017",
  43.                         "health" : 1,
  44.                         "state" : 5,
  45.                         "stateStr" : "STARTUP2",//STARTUP2的状态为:新加入的节点做数据初始化
  46.                         "uptime" : 27,
  47.                         "optime" : Timestamp(0, 0),
  48.                         "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
  49.                         "syncingTo" : "172.17.4.38:27017",
  50.                         "configVersion" : 1,
  51.                         "self" : true
  52.                 }
  53.         ],
  54.         "ok" : 1
  55. }
关于副本集的状态,文献参考如下:https://docs.mongodb.com/v3.0/reference/replica-states/index.html

过了半个小时之后,数据恢复完成,状态日志如下:

点击(此处)折叠或打开

  1. .....................
  2. 2017-12-22T11:27:02.474+0800 I INDEX [rsSync] building index using bulk method
  3. 2017-12-22T11:27:02.475+0800 I INDEX [rsSync] build index done. scanned 75 total records. 0 secs
  4. 2017-12-22T11:27:02.477+0800 I REPL [rsSync] initial sync data copy, starting syncup
  5. 2017-12-22T11:27:02.798+0800 I REPL [rsSync] oplog sync 1 of 3
  6. 2017-12-22T11:27:03.145+0800 I REPL [ReplicationExecutor] syncing from: 172.17.4.38:27017
  7. 2017-12-22T11:27:03.288+0800 I REPL [rsSync] oplog sync 2 of 3
  8. 2017-12-22T11:27:03.289+0800 I REPL [rsSync] initial sync building indexes
  9. 2017-12-22T11:27:03.289+0800 I REPL [rsSync] initial sync cloning indexes for : demo
  10. 2017-12-22T11:27:03.300+0800 I REPL [SyncSourceFeedback] replset setting syncSourceFeedback to 172.17.4.38:27017
  11. 2017-12-22T11:27:03.390+0800 I STORAGE [rsSync] copying indexes for: { name: "ACT_AUTH_LOG", options: {} }
  12. 2017-12-22T11:27:03.391+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_DATA_LOG", options: {} }
  13. 2017-12-22T11:27:03.392+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_ERROR_LOG", options: {} }
  14. 2017-12-22T11:27:03.392+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_EXTERNAL_PACKET", options: {} }
  15. 2017-12-22T11:27:03.393+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_EXTERNAL_PACKET_LOG", options: {} }
  16. 2017-12-22T11:27:03.393+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_JPUSH_LOG", options: {} }
  17. 2017-12-22T11:27:03.394+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_MESSAGE_LOG", options: {} }
  18. 2017-12-22T11:27:03.395+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_REQUEST_LOG", options: {} }
  19. 2017-12-22T11:27:03.395+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_RETRY_MESSAGE", options: {} }
  20. 2017-12-22T11:27:03.395+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_RUN_LOG", options: { capped: true, size: 536870912 } }
  21. 2017-12-22T11:27:03.396+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_SMSEMAIL_LOG", options: {} }
  22. 2017-12-22T11:27:03.396+0800 I STORAGE [rsSync] copying indexes for: { name: "SYSTEM_TIMEOUT_LOG", options: {} }
  23. 2017-12-22T11:27:03.397+0800 I REPL [rsSync] oplog sync 3 of 3
  24. 2017-12-22T11:27:03.406+0800 I REPL [rsSync] initial sync finishing up
  25. 2017-12-22T11:27:03.406+0800 I REPL [rsSync] replSet set minValid=5a3c7b93:3
  26. 2017-12-22T11:27:03.429+0800 I REPL [rsSync] initial sync done
  27. 2017-12-22T11:27:03.474+0800 I REPL [ReplicationExecutor] transition to RECOVERING
  28. 2017-12-22T11:27:03.476+0800 I REPL [ReplicationExecutor] transition to SECONDARY
  29. ..................

节点恢复的状态,如下:

点击(此处)折叠或打开

  1. arps:SECONDARY> rs.status()
  2. ...............
  3.                 {
  4.                         "_id" : 2,
  5.                         "name" : "172.17.4.39:27017",
  6.                         "health" : 1,
  7.                         "state" : 2,
  8.                         "stateStr" : "SECONDARY",//恢复完成
  9.                         "uptime" : 2500,
  10.                         "optime" : Timestamp(1513913295, 3),
  11.                         "optimeDate" : ISODate("2017-12-22T03:28:15Z"),
  12.                         "syncingTo" : "172.17.4.38:27017",
  13.                         "configVersion" : 1,
  14.                         "self" : true
  15.                 }
  16. .................





版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
第28节 从库Seconds_Behind_Master延迟总结
从库Seconds_Behind_Master延迟总结 到这里本系列已经接近尾声了,是时候对常见引起主从延迟的情形进行一个总结了。我想如果我一开始就把这些情形拿出来也许大家对具体的原因不是那么清楚,但是经过本系列的学习,我相信当我说起这些情形的时候大家都很清楚它的原因了。
857 0
MongoDB副本集初探
副本集是一组服务器,其中有一个主节点(Primary),用于处理客户的请求;还有多个备份节点(Secondary),用于保存主节点的数据副本。如果主节点崩溃了,备份节点会自动将其中一个成员升级为新的主节点。
3687 0
mongodb副本集高可用架构
一、简介 Mongodb复制集由一组Mongod实例(进程)组成,包含一个Primary节点和多个Secondary节点。 Mongodb Driver(客户端)的所有数据都写入Primary,Secondary从Primary同步写入的数据,以保持复制集内所有成员存储相同的数据集,实现数据的高可用。
2610 0
MongoDB副本集--管理命令
这篇文档主要介绍MongoDB副本集的日常查看和管理的命令. 1)命令行的查看命令:db.serverCmdLineOpts() 点击(此处)折叠或打开 arps:SECONDARY> db.
945 0
mongodb 3.4 集群搭建:分片+副本集
mongodb是最常用的nodql数据库,在数据库排名中已经上升到了前六。这篇文章介绍如何搭建高可用的mongodb(分片+副本)集群。 在搭建集群之前,需要首先了解几个概念:路由,分片、副本集、配置服务器等。
1949 0
28个MongoDB 的问题
MongoDB是目前最好的面向文档的免费开源NoSQL数据库。如果你正准备参加MongoDB NoSQL数据库的技术面试,你最好看看下面的MongoDB NoSQL面试问答。这些MongoDB NoSQL面试问答涵盖了NoSQL数据库基本的概念,复制(Replication),分片(Sharding),事务和锁,跟踪分析工具(Profiler),Nuances和日志等特性。
1905 0
+关注
zhangshengdong
文为世范,行为士则
182
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载