node.js 无法连接到 127.0.0.1:27017,原因:errno:111 连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26211671/
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
Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
提问by Ashish Ranjan
while trying this mongo command in ubuntu I am getting this error.
在 ubuntu 中尝试此 mongo 命令时,出现此错误。
ritzysystem@ritzysystem-Satellite-L55-A:~$ mongo
MongoDB shell version: 2.6.1
connecting to: test
2014-10-06T12:59:35.802+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-10-06T12:59:35.802+0530 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
how can I rectify this is anyone had the same problem.
我该如何纠正这是任何人都有同样的问题。
采纳答案by Ashish Ranjan
thank you everyone I tried running mongo it was not running finally I found there was no space in my hard disc I emptied some of the space and finally re installed it the same installation procedure as followed to install as given in mongodb docs finally restarted the server and it is running.
谢谢大家 我试过运行 mongo 它最终没有运行 我发现我的硬盘中没有空间 我清空了一些空间,最后重新安装了与 mongodb 文档中给出的安装过程相同的安装程序 最后重新启动了服务器它正在运行。
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu
回答by Jagdish Barabari
Run the following command :
运行以下命令:
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
Connection refused to MongoDB errno 111
MacOS:
苹果系统:
rm /usr/local/var/mongodb/mongod.lock
sudo service mongod restart
回答by levon
I had the same problem on Mac OS Try to run sudo mongodand in a new terminal tab run mongo
我在 Mac OS 上遇到了同样的问题尝试运行sudo mongod并在新的终端选项卡中运行mongo
回答by Sourav Prem
In my case the error was due to missing /data/db folder which the mongodb uses to store your data. Please type this command $sudo mongodin your terminal. If the error message is something like :
在我的情况下,错误是由于缺少 mongodb 用于存储数据的 /data/db 文件夹。请$sudo mongod在您的终端中输入此命令。如果错误消息类似于:
missing data/db folder error
missing data/db folder error
Simply create the folder and you are good to go.
只需创建文件夹即可。
回答by Akash Adhikari
First, Start MongoDB:
首先, 启动MongoDB:
sudo service mongod start
Then, Run:
然后,运行:
mongo
回答by Yingbo Cui
I had the same problem on my Mac, and I installed mongodb via homebrew. I solve this problem by the homebrew servicescommand.
我在 Mac 上遇到了同样的问题,我通过自制软件安装了 mongodb。我通过自制服务命令解决了这个问题。
First start mongodb service:
首先启动mongodb服务:
$ brew services start mongodb
$ brew services start mongodb
Start mongodb terminal
启动mongodb终端
$ mongo
$ mongo
Stop mongodb service:
停止mongodb服务:
$ brew services stop mongodb
$ brew services stop mongodb
回答by Pablo Tapia
Probably you don't have space in your hard drive.
Check it by typing in the promt df -h
可能您的硬盘驱动器中没有空间。通过在prom中输入来检查它 df -h
Please note that mongo might fail even with 3gb available in the corresponding partition. For details, you might want to check the log: cat /var/log/mongodb/mongod.log
请注意,即使相应分区中有 3gb 可用,mongo 也可能会失败。有关详细信息,您可能需要查看日志:cat /var/log/mongodb/mongod.log
回答by GuoX
Make sure you have run the MongoDB's Service before you want to connect the console.
在连接控制台之前,请确保您已经运行了 MongoDB 的服务。
run and start the server:
运行并启动服务器:
$ sudo mongod
then:
然后:
$ mongo
...
>
回答by Iman Mohamadi
Do this:
做这个:
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
If you are on Ubuntu 16.04 which you can figure out by runnign this:
如果您使用的是 Ubuntu 16.04,您可以通过 runnign 找出它:
lsb_release -a
You need to Create a new file at /lib/systemd/system/mongod.servicewith the following contents:
您需要/lib/systemd/system/mongod.service使用以下内容创建一个新文件:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
回答by GoingMyWay
I think except for disk space issuse, you should check the log in /var/log/mongodbto know the details for why mongodb start failed.
我认为除了磁盘空间问题之外,您应该检查登录/var/log/mongodb以了解mongodb启动失败的详细信息。
cat /var/log/mongodb/mongod.log
2016-06-26T15:26:26.642+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] MongoDB starting : pid=8130 port=27017 dbpath=/var/lib/mongodb 64-bit host=hadoop-master
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] db version v3.2.7
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] allocator: tcmalloc
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] modules: none
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] build environment:
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] distmod: ubuntu1404
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] distarch: x86_64
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] target_arch: x86_64
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,192.168.3.10", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-06-26T15:26:26.678+0800 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-06-26T15:26:26.678+0800 I - [initandlisten] Fatal Assertion 28578
2016-06-26T15:26:26.678+0800 I - [initandlisten]
***aborting after fassert() failure
So, here I need to rm all the files in the /tmp. That works fine for me.
所以,在这里我需要 rm 中的所有文件/tmp。这对我来说很好用。

