mongodb 无法在 Ubuntu 中启动副本集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28843496/
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 20:19:26  来源:igfitidea点击:

Can't initiate replica set in Ubuntu

mongodbubuntugoogle-cloud-platformmongodb-replica-set

提问by Italo Maia

Whenever I type: rs.initiate(), I get the following error message:

每当我输入: 时rs.initiate(),我都会收到以下错误消息:

{
    "info2" : "no configuration explicitly specified -- making one",
    "me" : "VMHOSTNAME:27017",
    "ok" : 0,
    "errmsg" : "No host described in new configuration 1 for replica set rs0 maps to this node",
    "code" : 93
}

I'm running under google-cloud-engine with latest MongoDB.

我正在使用最新的 MongoDB 在 google-cloud-engine 下运行。

Any suggestions on how to solve this?

有关如何解决此问题的任何建议?

回答by LeBird

You could try passing a parameter to the .initiate()command.

您可以尝试将参数传递给.initiate()命令。

Like so:

像这样:

rs.initiate({_id:"yourReplSetName", members: [{"_id":1, "host":"yourHost:yourPort"}]})

This did the trick for me.

这对我有用。

回答by DanielKhan

Your VMHOSTNAME must be an alias for 127.0.0.1 in your /etc/hosts file to make it work.

您的 VMHOSTNAME 必须是 /etc/hosts 文件中 127.0.0.1 的别名才能使其工作。

See here https://jira.mongodb.org/browse/SERVER-16157

请参阅此处https://jira.mongodb.org/browse/SERVER-16157

回答by Steffan Perry

The problem might be in your mongo config. Look for the following line and comment it out:

问题可能出在您的 mongo 配置中。查找以下行并将其注释掉:

#bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

回答by yImI

If you find the VMHOSTNAME in the /etc/hostnames file and the referenced mongo instance is running then its possibly a port number error. In my case it was. Shards tipically started at port 27018.

如果您在 /etc/hostnames 文件中找到 VMHOSTNAME 并且引用的 mongo 实例正在运行,则可能是端口号错误。就我而言,它是。分片通常从端口 27018 开始。

回答by megalucio

Yeah, exactly, or you can change your hostname to something that is already in your /etc/hosts pointing to 127.0.0.1 such as localhost.

是的,确切地说,或者您可以将您的主机名更改为指向 127.0.0.1 的 /etc/hosts 中已有的内容,例如 localhost。

With a mac you can do this by typing sudo scutil –-set HostName localhost.

使用 Mac,您可以通过键入sudo scutil –-set HostName localhost.