Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1126134
  • 博文数量: 185
  • 博客积分: 1857
  • 博客等级: 上尉
  • 技术积分: 2651
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-14 22:55
  • 认证徽章:
个人简介

吾生有涯,而知无涯,适当止学.循序渐进,步步提升 Talk is cheap, show me the code.

文章分类

全部博文(185)

文章存档

2018年(2)

2017年(24)

2016年(31)

2015年(15)

2014年(8)

2013年(12)

2012年(93)

分类: NOSQL

2017-12-22 12:09:01

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. .................





阅读(175) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册