database 将成员添加到 MongoDb 上的副本集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8963903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:26:46  来源:igfitidea点击:

Adding members to Replica Set on MongoDb

mongodbmaster-slavedatabase

提问by sicr

I am trying to create a replica set with MongoDb, the servers hostnames are:

我正在尝试使用 MongoDb 创建副本集,服务器主机名是:

hostname hostname-1 hostname-2

主机名 主机名-1 主机名-2

Each of these has all the relevant hostnames detailed in their /etc/hosts file (They;re all running Ubuntu 10.04 64-bit)

每个都在其 /etc/hosts 文件中详细说明了所有相关的主机名(它们都运行 Ubuntu 10.04 64 位)

When I do an rs.initiate on one node everything seems to start well. Running rs.status(); shows:

当我在一个节点上执行 rs.initiate 时,一切似乎都开始良好。运行 rs.status(); 显示:

{
    "set" : "vega",
    "date" : ISODate("2012-01-22T19:15:55Z"),
    "myState" : 1,
    "members" : [
        {
            "_id" : 0,
            "name" : "hostname:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "optime" : {
                "t" : 1327254848000,
                "i" : 1
            },
            "optimeDate" : ISODate("2012-01-22T17:54:08Z"),
            "self" : true
        }
    ],
    "ok" : 1
}

The problem comes when I try to add a new member to the replica set. I use the command rs.add(hostname-1); and I get the following error:

当我尝试向副本集添加新成员时出现问题。我使用命令 rs.add(hostname-1); 我收到以下错误:

{
    "assertion" : "need most members up to reconfigure, not ok : vega-1:27017",
    "assertionCode" : 13144,
    "errmsg" : "db assertion failure",
    "ok" : 0
}

I've tried numerous combinations of using the hostname, IP address, both with and without the port number and I always get the same problem. The hostname is resolving, i've tried ping hostname-1 and it works fine.

我已经尝试了多种使用主机名、IP 地址的组合,无论有没有端口号,我总是遇到同样的问题。主机名正在解析,我试过 ping hostname-1 并且它工作正常。

Does anybody have any ideas as to what could be causing this issue?

有没有人对可能导致此问题的原因有任何想法?

Unfortunately in the Mongo documentation there are no examples of setting up a replica set in the real world scenario, only using three instances on the same machine which is clearly useless.

不幸的是,在 Mongo 文档中没有在现实世界场景中设置副本集的示例,仅在同一台机器上使用三个实例,这显然是无用的。

Thanks in advance for any help!

在此先感谢您的帮助!

回答by Reigner S. Yrastorza

Remove this in your configuration:

在您的配置中删除它:

bind_ip = 127.0.0.1

That option is currently incompatible with mongodb replica sets.

该选项目前与 mongodb 副本集不兼容。

回答by phatduckk

That error happens when you're adding nodes that aren't "up" (yet). It sounds like either "hostname-1" is unreachable (not in /etc/hosts, no DNS) or it is reachable but isn't running mongodb with the replSetconfiguration parameter set

当您添加尚未“启动”(尚未启动)的节点时,就会发生该错误。这听起来像是“hostname-1”无法访问(不在 /etc/hosts 中,没有 DNS),或者它可以访问但未使用replSet配置参数集运行 mongodb

回答by user241

{
    "errmsg" : "exception: need most members up to reconfigure, not ok : server2:27017",
    "code" : 13144,
    "ok" : 0
}

I encountered the above error in Mongo 2.4.9. My mistake here is that I didn't specify replSetin the mongo config of the new replica member. rs.add("server2:27017")worked well after.

我在 Mongo 2.4.9 中遇到了上述错误。我的错误是我没有replSet在新副本成员的 mongo 配置中指定。rs.add("server2:27017")之后工作得很好。

回答by Gates VP

Unfortunately in the Mongo documentation there are no examples of setting up a replica set in the real world scenario, only using three instances on the same machine which is clearly useless.

不幸的是,在 Mongo 文档中没有在现实世界场景中设置副本集的示例,仅在同一台机器上使用三个实例,这显然是无用的。

Agreed, it's pretty poor. That example should be completely removed from the docs.

同意,确实很穷。该示例应该从文档中完全删除。

There is another way to start a replica set and that is by using the rs.configure()command. You can also specify all three nodes at once and then issue the rs.inititiate().

还有另一种启动副本集的方法,那就是使用rs.configure()命令。您还可以一次指定所有三个节点,然后发出rs.inititiate().

See herefor an example of specifying all nodes before initiating.

有关在启动之前指定所有节点的示例,请参见此处

See herefor more details on the various commands.

有关各种命令的更多详细信息,请参见此处

回答by user3375540

You may need to check the mongod is running on the second node before you add the second node to node1. If it is running rs.add() and then check rs.status().

在将第二个节点添加到 node1 之前,您可能需要检查 mongod 是否在第二个节点上运行。如果它正在运行 rs.add(),然后检查 rs.status()。