无法连接到 mongodb errno:61 连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23418134/
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
Cannot connect to mongodb errno:61 Connection refused
提问by Michael
I recently installed mongodb-2.6.0 with Homebrew.
After successfully installed, I tried to connect using the mongo
command. I am receiving the following errors which do not allow me to connect:
我最近用Homebrew安装了 mongodb-2.6.0 。成功安装后,我尝试使用该mongo
命令进行连接。我收到以下不允许我连接的错误:
Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
回答by Hrishi
It can happen when the mongodb service is not running on the mac. To start it, I tried
当 mongodb 服务未在 mac 上运行时,可能会发生这种情况。要开始它,我试过
brew services start mongodb
and it worked.
它奏效了。
Edit: According to the discussion on this PR on homebrew: https://github.com/Homebrew/homebrew/issues/30628
编辑:根据关于 homebrew 这个 PR 的讨论:https: //github.com/Homebrew/homebrew/issues/30628
brew services
is deprecated, I looked around on SO and found these answers now answer the question: What is the correct way to start a mongod service on linux / OS X?
brew services
已弃用,我环顾四周,发现这些答案现在回答了这个问题:在 linux/OS X 上启动 mongod 服务的正确方法是什么?
回答by Ali Raza Bhayani
I encountered the exact same issue and here is a clear step by step process to avoid this error.
我遇到了完全相同的问题,这里有一个明确的分步过程,以避免出现此错误。
Step 1- Installation ( Don't follow this step if you have already installed MongoDB ):
第 1 步- 安装(如果您已经安装了 MongoDB,请不要执行此步骤):
brew update
brew install mongodb
Step 2- Run Mongo Daemon:
第 2 步- 运行 Mongo 守护进程:
mkdir -p /data/db
sudo mongod
Step 3- Run Mongo Shell Interface:
第 3 步- 运行 Mongo Shell 界面:
mongo
In this sequence, I was able to run the mongo
command without any error. I have also detailed the error trace and its solution on this blog.
在这个序列中,我能够毫无错误地运行mongo
命令。我还在此博客上详细介绍了错误跟踪及其解决方案。
回答by jh3y
To solve your issue you need to follow the instructions which are then given to you by brew after you use "brew install mongodb".
要解决您的问题,您需要按照使用“brew install mongodb”后 brew 给您的说明进行操作。
To have launchd start mongodb at login:
要在登录时启动 mongodb:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
然后现在加载mongodb:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
或者,如果您不想要/不需要launchctl,您可以运行:
mongod --config /usr/local/etc/mongod.conf
You may be able to just run that last command, but it didn't work for me and I needed to run the second command. To save me in the future. I just ran the first command too. Hope that helps!
您也许可以只运行最后一个命令,但它对我不起作用,我需要运行第二个命令。将来救我。我也刚运行了第一个命令。希望有帮助!
EDITHrishi's method of using brew services mongodb start
worked good for me. I think they should include this in the mongo docs.
编辑Hrishi 的使用方法brew services mongodb start
对我很有用。我认为他们应该将其包含在 mongo 文档中。
回答by Eric Hou
In another tab, you can start the mongo shell with
在另一个选项卡中,您可以使用以下命令启动 mongo shell
mongod
蒙哥
Then return to the previous tab and try again. If you're having trouble setting up your mongoshell, check out this link on the mongo shell: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/or this link on installing mongodb: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
然后返回上一个选项卡并重试。如果您遇到问题设置您的mongoshell,检查出蒙戈外壳此链接:http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/或上安装MongoDB的链接: HTTP:/ /docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
回答by Bogdan T.
I was having the same issue when calling mongod
from the command line.
mongod
从命令行调用时我遇到了同样的问题。
I resolved this by calling instead sudo mongod
.
我通过调用来解决这个问题sudo mongod
。
回答by Nick Benes
I had the same error but a different root cause. Thought I'd post the solution here in case anyone else runs into the problem. I got this error after my Mac improperly shut down while I was running mongorestore -d foo dump/foo/
.
我有同样的错误,但根本原因不同。以为我会在这里发布解决方案,以防其他人遇到问题。我的 Mac 在运行时不正常关闭后出现此错误mongorestore -d foo dump/foo/
。
tl;dr: I fixed the problem by removing the damaged foo.ns
file along with foo.0
, foo.1
,... from my data folder /usr/local/var/mongodb/
. Then I restarted the mongo server with brew services restart mongodb
and I was back to normal.
tl; dr:我通过从我的数据文件夹中删除损坏的foo.ns
文件以及foo.0
, foo.1
,...解决了这个问题/usr/local/var/mongodb/
。然后我重新启动了 mongo 服务器,brew services restart mongodb
我又恢复了正常。
Details: I kept getting the error even after trying to start or restart the mongodb service via brew or launchctl. Eventually I ran
mongod --dbpath /usr/local/var/mongodb
and saw that the service was not actually starting, and the start sequence included the following error:
[initandlisten] bad .ns file: /usr/local/var/mongodb/foo.ns
[initandlisten] User Assertion: 10079:bad .ns file length, cannot open database
I got rid of the bad .ns
file and the rest of the data files, and the next time I started the service I was good to go.
详细信息:即使在尝试通过 brew 或 launchctl 启动或重新启动 mongodb 服务后,我仍然收到错误消息。最终我跑起来
mongod --dbpath /usr/local/var/mongodb
,看到服务并没有真正启动,启动序列包含以下错误:
[initandlisten] bad .ns file: /usr/local/var/mongodb/foo.ns
[initandlisten] User Assertion: 10079:bad .ns file length, cannot open database
我摆脱了坏.ns
文件和其余数据文件,下次启动服务时我很高兴.
回答by ranjeetcao
for me on osx, I had to kill old running instance, then restarting worked.
对于我在 osx 上,我不得不杀死旧的运行实例,然后重新启动工作。
$>ps -aef | grep mongo
502 8047 1 0 11:52AM ?? 0:00.23 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf
$>sudo kill 8047
$>sudo mongod
回答by Chad von Nau
I got this error after I upgraded to mongo 3.6 with homebrew.
使用自制软件升级到 mongo 3.6 后出现此错误。
The log /usr/local/var/log/mongodb/mongo.log
contained the message shutting down with code:62
. This error code means that the existing database is too old to run with the current version of mongo.
日志/usr/local/var/log/mongodb/mongo.log
包含消息shutting down with code:62
。此错误代码表示现有数据库太旧,无法使用当前版本的 mongo 运行。
I found 2 solutions in another SO question:
我在另一个SO 问题中找到了 2 个解决方案 :
- Delete your database folder (
/usr/local/var/mongodb
) - Or follow the upgrade procedure
- 删除您的数据库文件夹 (
/usr/local/var/mongodb
) - 或者按照升级程序
I chose to upgrade. In my case, that meant I had to downgrade to 3.4, run a command in the mongo console, then upgrade again. Mongo requires you to upgrade one major version at a time, so depending on how far back you were, there could be additional steps. The docs will guide you.
我选择升级。就我而言,这意味着我必须降级到 3.4,在 mongo 控制台中运行命令,然后再次升级。Mongo 要求您一次升级一个主要版本,因此根据您过去的时间,可能会有额外的步骤。文档将指导您。
The brew switch
*and brew services restart
commands made swapping between versions relatively painless.
在brew switch
*和brew services restart
命令进行版本相对无痛之间交换。
回答by Jonathan.Wagner
I had the same issue and in looking in the log file I saw this:
我有同样的问题,在查看日志文件时我看到了这个:
{2019-03-09T11:57:32.136-0500 I STORAGE [initandlisten]
exception in initAndListen: NonExistentPath:
Data directory /usr/local/var/mongodb not found., terminating}
so I created the directory /usr/local/var/mongodb
issued the brew services restart mongodb command I was able to open the mongo console.
所以我创建了/usr/local/var/mongodb
发出 brew services restart mongodb 命令的目录,我能够打开 mongo 控制台。
回答by Healthy Tech Guy
For anyone who is here looking for the answer for this after your mac has updated to OS Catalina
对于在您的 Mac 更新到 OS Catalina 后在这里寻找答案的任何人
run
跑
brew services start mongodb-community
find more info here: https://medium.com/@semmons245/arghhhh-thanks-to-the-catalina-os-update-this-now-needs-changing-987f416ebcbe
在这里找到更多信息:https: //medium.com/@semmons245/arghhhh-thanks-to-the-catalina-os-update-this-now-needs-changed-987f416ebcbe