MongoDB修复config配置节点

生产环境的一套MongoDB发生故障,其中一个config节点的磁盘损坏。
修复流程如下:

  1. # 登录到config库,查看config的节点状态
  2. # 可以看到_id为2的节点状态是不可访问的
  3. [root@mongos-mq ~]# /opt/mongodb-linux-x86_64-3.2.10/bin/mongo --port 10000
  4. MongoDB shell version: 3.2.10
  5. connecting to: 127.0.0.1:10000/test
  6. config_rs:PRIMARY> use admin
  7. switched to db admin
  8. config_rs:PRIMARY> db.auth("root", "xxx")
  9. 1
  10. config_rs:PRIMARY> rs.status()
  11. {
  12.     "set" : "config_rs",
  13.     "date" : ISODate("2018-05-30T04:53:21.081Z"),
  14.     "myState" : 1,
  15.     "term" : NumberLong(1),
  16.     "configsvr" : true,
  17.     "heartbeatIntervalMillis" : NumberLong(2000),
  18.     "members" : [
  19.         {
  20.             "_id" : 0,
  21.             "name" : "192.168.210.208:10000",
  22.             "health" : 1,
  23.             "state" : 1,
  24.             "stateStr" : "PRIMARY",
  25.             "uptime" : 1112804,
  26.             "optime" : {
  27.                 "ts" : Timestamp(1527656000, 1),
  28.                 "t" : NumberLong(1)
  29.             },
  30.             "optimeDate" : ISODate("2018-05-30T04:53:20Z"),
  31.             "electionTime" : Timestamp(1526543249, 2),
  32.             "electionDate" : ISODate("2018-05-17T07:47:29Z"),
  33.             "configVersion" : 3,
  34.             "self" : true
  35.         },
  36.         {
  37.             "_id" : 1,
  38.             "name" : "192.168.210.209:10000",
  39.             "health" : 1,
  40.             "state" : 2,
  41.             "stateStr" : "SECONDARY",
  42.             "uptime" : 1111358,
  43.             "optime" : {
  44.                 "ts" : Timestamp(1527656000, 1),
  45.                 "t" : NumberLong(1)
  46.             },
  47.             "optimeDate" : ISODate("2018-05-30T04:53:20Z"),
  48.             "lastHeartbeat" : ISODate("2018-05-30T04:53:20.836Z"),
  49.             "lastHeartbeatRecv" : ISODate("2018-05-30T04:53:19.329Z"),
  50.             "pingMs" : NumberLong(0),
  51.             "syncingTo" : "192.168.210.208:10000",
  52.             "configVersion" : 3
  53.         },
  54.         {
  55.             "_id" : 2,
  56.             "name" : "192.168.210.207:10000",
  57.             "health" : 0,
  58.             "state" : 8,
  59.             "stateStr" : "(not reachable/healthy)",
  60.             "uptime" : 0,
  61.             "optime" : {
  62.                 "ts" : Timestamp(0, 0),
  63.                 "t" : NumberLong(-1)
  64.             },
  65.             "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
  66.             "lastHeartbeat" : ISODate("2018-05-30T04:53:20.850Z"),
  67.             "lastHeartbeatRecv" : ISODate("2018-05-26T09:07:27.318Z"),
  68.             "pingMs" : NumberLong(0),
  69.             "lastHeartbeatMessage" : "Connection refused",
  70.             "configVersion" : -1
  71.         }
  72.     ],
  73.     "ok" : 1
  74. }

  75. # 在故障节点上面重新安装MongoDB,创建数据文件目录
  76. [root@tomcat-207 opt]# tar xfz mongodb-linux-x86_64-3.2.10.tgz
  77. [root@tomcat-207 opt]# mkdir -p /data/mongodb_data/config_rs1_10000

  78. # 配置参数文件
  79. [root@tomcat-207 opt]# cat /etc/mongodb/config_rs1_10000.conf
  80. systemLog:
  81.     destination: file
  82.     path: /data/mongodb_data/config_rs1_10000/mongod.log
  83. processManagement:
  84.     fork: true
  85. net:
  86.     bindIp: 0.0.0.0
  87.     port: 10000
  88. security:
  89.     keyFile: /data/mongodb_data/keyfile
  90. storage:
  91.     dbPath: /data/mongodb_data/config_rs1_10000
  92.     directoryPerDB: true
  93. operationProfiling:
  94.     slowOpThresholdMs: 100
  95.     mode: slowOp
  96. replication:
  97.     replSetName: config_rs
  98. sharding:
  99.     clusterRole: configsvr

  100. # 从其他config节点拷贝过来keyfile文件
  101. [root@mongos-mq opt]# scp /data/mongodb_data/keyfile root@192.168.210.207:/data/mongodb_data/

  102. # 启动Mongo
  103. [root@mongos-mq opt]# /opt/mongodb-linux-x86_64-3.2.10/bin/mongod -f /etc/mongodb/config_rs1_10000.conf
  104. about to fork child process, waiting until server is ready for connections.
  105. forked process: 3744
  106. child process started successfully, parent exiting

  107. # 查看config节点状态
  108. # 所有的config节点都恢复正常
  109. config_rs:PRIMARY> rs.status()
  110. {
  111.     "set" : "config_rs",
  112.     "date" : ISODate("2018-05-30T05:29:40.103Z"),
  113.     "myState" : 1,
  114.     "term" : NumberLong(1),
  115.     "configsvr" : true,
  116.     "heartbeatIntervalMillis" : NumberLong(2000),
  117.     "members" : [
  118.         {
  119.             "_id" : 0,
  120.             "name" : "192.168.210.208:10000",
  121.             "health" : 1,
  122.             "state" : 1,
  123.             "stateStr" : "PRIMARY",
  124.             "uptime" : 1114983,
  125.             "optime" : {
  126.                 "ts" : Timestamp(1527658178, 4),
  127.                 "t" : NumberLong(1)
  128.             },
  129.             "optimeDate" : ISODate("2018-05-30T05:29:38Z"),
  130.             "electionTime" : Timestamp(1526543249, 2),
  131.             "electionDate" : ISODate("2018-05-17T07:47:29Z"),
  132.             "configVersion" : 3,
  133.             "self" : true
  134.         },
  135.         {
  136.             "_id" : 1,
  137.             "name" : "192.168.210.209:10000",
  138.             "health" : 1,
  139.             "state" : 2,
  140.             "stateStr" : "SECONDARY",
  141.             "uptime" : 1113537,
  142.             "optime" : {
  143.                 "ts" : Timestamp(1527658178, 4),
  144.                 "t" : NumberLong(1)
  145.             },
  146.             "optimeDate" : ISODate("2018-05-30T05:29:38Z"),
  147.             "lastHeartbeat" : ISODate("2018-05-30T05:29:39.535Z"),
  148.             "lastHeartbeatRecv" : ISODate("2018-05-30T05:29:39.941Z"),
  149.             "pingMs" : NumberLong(0),
  150.             "syncingTo" : "192.168.210.208:10000",
  151.             "configVersion" : 3
  152.         },
  153.         {
  154.             "_id" : 2,
  155.             "name" : "192.168.210.207:10000",
  156.             "health" : 1,
  157.             "state" : 2,
  158.             "stateStr" : "SECONDARY",
  159.             "uptime" : 1588,
  160.             "optime" : {
  161.                 "ts" : Timestamp(1527658178, 4),
  162.                 "t" : NumberLong(1)
  163.             },
  164.             "optimeDate" : ISODate("2018-05-30T05:29:38Z"),
  165.             "lastHeartbeat" : ISODate("2018-05-30T05:29:39.535Z"),
  166.             "lastHeartbeatRecv" : ISODate("2018-05-30T05:29:39.691Z"),
  167.             "pingMs" : NumberLong(0),
  168.             "syncingTo" : "192.168.210.209:10000",
  169.             "configVersion" : 3
  170.         }
  171.     ],
  172.     "ok" : 1
  173. }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-2155380/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26506993/viewspace-2155380/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值