MongoDB修復config配置節點

feelpurple發表於2018-05-31
生產環境的一套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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章