【问题标题】:Validate Replica Set Data验证副本集数据
【发布时间】:2015-09-19 17:34:27
【问题描述】:

我是新来的,我希望我在正确的论坛上发布我的问题。我没有看到在哪里为 MongoDB 选择正确的论坛类别..

我有 2 个问题 -

我正在使用 Mongodb 2.6,并且正在将 2 个副本集 RS0 和 RS1 从数据中心迁移到 AWS。我在每个副本集上有 3 台服务器,总共有 6 台服务器。我用来将数据迁移到新服务器的选项是将副本集扩展到新硬件,然后让它们完全赶上,然后我才能从副本集中删除旧硬件上的节点。

问题 1> 在从源中删除旧副本集之前,如何验证两个副本集(源和目标)上的数据以确保数据 100% 同步?我可以使用哪些正确的命令来检查我正在迁移的所有数据库的所有集合的集合数量和数据计数?

问题 2> 如果我错了,请纠正我 - 我的理解是在使用 Replica 集时,我们必须在 RS 中保留奇数个成员。现在我每个 RS 有 3 个服务器,这很好,但是当我向我当前的 RS 添加一个新成员时,它将指向一个新服务器,我最终将有 4 个成员 - 这不会导致问题吗?我应该在我的 RS 中添加 2 个成员,以便我可以保留 5 个奇数成员吗?

提前非常感谢您!

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    问题 1:在任何副本集成员上使用 rs.status();您可以检查每个成员的状态和 optime 字段(与主要的比较): http://docs.mongodb.org/manual/reference/method/rs.status/

    问题2:您需要一个奇数的成员,因为只有一个成员可以选为主要,每个成员都可以投票给1个成员,所以在主要成员选举期间,拥有偶数成员可以引导偶数成员。两个或两个以上成员的票数相等。要拥有奇数个成员,您可以设置一个 arbitet 实例:http://docs.mongodb.org/master/tutorial/add-replica-set-arbiter/

    【讨论】:

      【解决方案2】:

      @Stefano 给了你答案。我想补充几点:

      问题 1:

      您可以使用rs.status查看副本集状态。这样主次分清了。

      {
          "set" : "replset",
          "date" : ISODate("2015-11-19T15:22:32.597Z"),
          "myState" : 1,
          "term": NumberLong(1),
          "heartbeatIntervalMillis" : NumberLong(2000),
          "members" : [
              {
                  "_id" : 0,
                  "name" : "m1.example.net:27017",
                  "health" : 1,
                  "state" : 1,
                  "stateStr" : "PRIMARY",
                  "uptime" : 269,
                  "optime" : {
                              "ts" : Timestamp(1447946550, 1),
                              "t" : NumberLong(1)
                           },
                  "optimeDate" : ISODate("2015-11-19T15:22:30Z"),
                  "infoMessage" : "could not find member to sync from",
                  "electionTime" : Timestamp(1447946549, 1),
                  "electionDate" : ISODate("2015-11-19T15:22:29Z"),
                  "configVersion" : 1,
                  "self" : true
              },
              {
                  "_id" : 1,
                  "name" : "m2.example.net:27017",
                  "health" : 1,
                  "state" : 2,
                  "stateStr" : "SECONDARY",
                  "uptime" : 13,
                           "optime" : {
                              "ts" : Timestamp(1447946539, 1),
                              "t" : NumberLong(-1)
                           },
                  "optimeDate" : ISODate("2015-11-19T15:22:19Z"),
                  "lastHeartbeat" : ISODate("2015-11-19T15:22:31.323Z"),
                  "lastHeartbeatRecv" : ISODate("2015-11-19T15:22:32.045Z"),
                  "pingMs" : NumberLong(0),
                  "configVersion" : 1
              },
              {
                  "_id" : 2,
                  "name" : "m3.example.net:27017",
                  "health" : 1,
                  "state" : 2,
                  "stateStr" : "SECONDARY",
                  "uptime" : 13,
                           "optime" : {
                              "ts" : Timestamp(1447946539, 1),
                              "t" : NumberLong(-1)
                           },
                  "optimeDate" : ISODate("2015-11-19T15:22:19Z"),
                  "lastHeartbeat" : ISODate("2015-11-19T15:22:31.325Z"),
                  "lastHeartbeatRecv" : ISODate("2015-11-19T15:22:31.971Z"),
                  "pingMs" : NumberLong(0),
                  "configVersion" : 1
              }
          ],
          "ok" : 1
      }
      

      了解slave延时火rs.printSlaveReplicationInfo()

      source: localhost.localdomain:27070
              syncedTo: Mon May 02 2016 12:34:36 GMT+0530 (IST)
              0 secs (0 hrs) behind the primary
      source: localhost.localdomain:27072
              syncedTo: Mon May 02 2016 12:34:36 GMT+0530 (IST)
              0 secs (0 hrs) behind the primary
      source: localhost.localdomain:27073
              syncedTo: Mon May 02 2016 12:34:36 GMT+0530 (IST)
              0 secs (0 hrs) behind the primary
      

      要在 oplog 中了解有关复制追赶的更多详细信息,请尝试rs.printReplicationInfo()

      configured oplog size:   700.0038909912109MB
      log length start to end: 261920secs (72.76hrs)
      oplog first event time:  Fri Apr 29 2016 11:49:16 GMT+0530 (IST)
      oplog last event time:   Mon May 02 2016 12:34:36 GMT+0530 (IST)
      now:                     Mon May 02 2016 12:49:37 GMT+0530 (IST)
      

      问题 2:

      奇数副本有助于在选举中进行高投票。因此,如果您有偶数副本集,您可以添加Arbiters。它们只是重量轻且不包含数据,它们也可以驻留在任何其他当前正在运行的服务器上。

      希望这会有所帮助!!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-12-11
        • 1970-01-01
        • 2021-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-23
        相关资源
        最近更新 更多