【问题标题】:Adding a replica in MongoDB throws an error在 MongoDB 中添加副本会引发错误
【发布时间】:2015-08-09 09:28:35
【问题描述】:

我正在尝试使用 rs.add("developer-ViratualBox:30103") 将节点添加到副本集,但收到以下错误消息:

{
"ok" : 0,
"errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: developer-VirtualBox:30101; the following nodes did not respond affirmatively: developer-ViratualBox:30103 failed with Failed attempt to connect to developer-ViratualBox:30103; couldn't initialize connection to host developer-ViratualBox, address is invalid",
"code" : 74
}

节点已经在运行,我使用mongo shell 连接到它。可能是什么问题?

【问题讨论】:

  • 问题解决了吗?
  • 是的。请看我的回答

标签: mongodb replication database-replication


【解决方案1】:

你应该使用 docker network 来解决这个问题。

【讨论】:

  • 你的回答太笼统了。请添加一些解释和示例。
  • 此实例不是 docker 网络的一部分,也不是 docker 容器上的一部分
【解决方案2】:

在创建rsconf 文件时,请输入<localhost:port> 而不是<hostname:port>。 然后reconfig(rsconf)。

例子:

rs0:PRIMARY>     
rsconf = {
             _id: "rs0",
             members: [
                 {
                     _id: 0,
                     host: "**localhost**:port for primary rs"
                 }]
         }

rs0:PRIMARY> rs.initiate(rsconf)
    {
        "info" : "try querying local.system.replset to see current configuration",
        "ok" : 0,
        "errmsg" : "already initialized",
        "code" : 23
    }

如果您遇到上述错误,请使用以下命令:

rs0:PRIMARY> rs.reconfig(rsconf)

添加辅助节点:rs.add("localhost:port for secondary rs")

希望它会起作用。

【讨论】:

  • 很遗憾没有。节点不在同一台机器上。
【解决方案3】:

另一个可能的问题是您尝试添加到副本集中的机器未配置为使用复制运行。 将此条目添加到您尝试添加的机器上的 mongod.conf 并重新启动该服务对我有用:

replication:
  replSetName: evoReplicaSet

【讨论】:

    【解决方案4】:

    在启动辅助 mongod 进程时,使用 --replSet 选项尝试从主 mongod shell 运行 rs.add("localhost:27002")。

    【讨论】:

      【解决方案5】:

      缺少的一点是我试图添加的实例没有在定义的端口上启动 mongod 实例。因此,给定的连接参数不正确,从而导致通信问题。

      【讨论】:

      • 这真的很有帮助。顺便说一句,我正在本地主机上设置 mongo 集群。你有这个的文档文件吗?可以分享一下吗?
      • 您是否在本地主机上托管了一个而在其他地方托管了一个?我似乎无法让它工作。
      • @mirana 不,所有实例都在本地主机上
      【解决方案6】:

      实际错误是couldn't initialize connection to host developer-ViratualBox, address is invalid,只是主节点无法连接到辅助节点。检查连接、防火墙,并检查与 mongo shell 的连接是否可以访问该端口。

      【讨论】:

        【解决方案7】:

        您只能在连接到主要时添加成员。要知道哪个成员是主成员,请登录副本集的任何成员并发出 db.isMaster() 命令。

        然后,使用 rs.add() 将新成员添加到副本集中。例如,要在主机 mongodb3.example.net 上添加成员,请发出以下命令:

        rs.add("developer-ViratualBox:30103")
        

        【讨论】:

        • 我在连接到主服务器时收到此错误,尝试添加辅助服务器
        猜你喜欢
        • 1970-01-01
        • 2018-11-26
        • 2021-11-16
        • 2011-04-20
        • 1970-01-01
        • 2017-05-31
        • 1970-01-01
        • 2016-08-14
        • 2016-04-12
        相关资源
        最近更新 更多