无法连接到 MongoDB errno:61

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

Cannot connect to MongoDB errno:61

macosmongodbosx-mavericks

提问by Michael

I installed MongoDB using macports and tried running the mongocommand in order to start the mongo shell. I received the following errors:

我使用 macports 安装了 MongoDB 并尝试运行该mongo命令以启动 mongo shell。我收到以下错误:

warning: 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

I then ran mongodand received the following error:

然后我运行mongod并收到以下错误:

$ [initandlisten] MongoDB starting : pid=11984 port=27017 dbpath=/data/db 64-bit host=Nikitas-MacBook-Air.local
$ [initandlisten] 
$ [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
$ [initandlisten] db version v2.6.0
$ [initandlisten] git version: nogitversion
$ [initandlisten] build info: Darwin tennine-slave.macports.org 13.1.0 Darwin Kernel Version 
13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_55
$ [initandlisten] allocator: tcmalloc
$ [initandlisten] options: {}
$ [initandlisten] exception in initAndListen: 10296 
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
$ [initandlisten] dbexit: 
$ [initandlisten] shutdown: going to close listening sockets...
$ [initandlisten] shutdown: going to flush diaglog...
$ [initandlisten] shutdown: going to close sockets...
$ [initandlisten] shutdown: waiting for fs preallocator...
$ [initandlisten] shutdown: lock for final commit...
$ [initandlisten] shutdown: final commit...
$ [initandlisten] shutdown: closing all files...
$ [initandlisten] closeAllFiles() finished
$ [initandlisten] dbexit: really exiting now

Where do I create the /data/dbdirectory, at root? Would the second error be the reason for the errno:61when I run mongo?

我在哪里创建/data/db目录,在根?第二个错误是errno:61我运行时的原因mongo吗?

回答by Ali Raza Bhayani

I encountered similar problem. I have detailed the error trace and solution on this blogThis is step by step process I did to solve this issue:

我遇到了类似的问题。我在此博客上详细介绍了错误跟踪和解决方案这是我为解决此问题所做的分步过程:

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.

在这个序列中,我能够运行 mongo 命令而没有任何错误。

回答by DaveStSomeWhere

Yes, you would create /data/dbat root. The MongoDB Documentationsuggests the following command for creation on OS X mkdir -p /data/db.

是的,您将/data/db在根目录下创建。在MongoDB的文档提出了在OS X创建以下命令mkdir -p /data/db

Regarding your second question, also yes. Since the Mongo Daemon failed to start and isn't listening you get the connection error.

关于你的第二个问题,也是。由于 Mongo 守护程序无法启动且未在侦听,因此您会收到连接错误。

MongoDB defaults to /data/dbfor the data directory. You can override the default using the --dbpathoption on the mongodcommand (also on the doc link above).

MongoDB 默认/data/db为数据目录。您可以使用命令--dbpath上的选项覆盖默认值mongod(也在上面的文档链接上)。

回答by lutaoact

** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

you can add one line into your /etc/bashrc, the warning will disappear.

您可以在 /etc/bashrc 中添加一行,警告将消失。

ulimit -S -n 1024

use chown -R {user} /data/dbto change the owner of /data/dbfrom root to yourself. Then you can start mongo shell just by mongo, no need to use sudo mongo.

用于chown -R {user} /data/db将所有者/data/db从 root更改为您自己。然后你就可以直接启动mongo shell了mongo,不需要使用sudo mongo.