MongoDB:连接127.0.1:27017失败,原因:errno:61连接被拒绝

时间:2021-10-07 12:36:19

My problem is similar to other inputs and suggestions on this site, but none has helped me. After installing MongoDB, has not started because the database is not running.

我的问题和这个网站上的其他输入和建议类似,但是没有一个对我有帮助。安装MongoDB之后,由于数据库没有运行,尚未启动。

First try to run mongo and I answered this:

首先试着运行mongo,我回答:

Mac-Pro-de-User: ~ user $ mongo 
MongoDB shell version: 2.6.4 
connecting to: test 
2014-10-28T10: 47: 08713-0700 warning: Failed to connect to 127.0.0.1:27017, reason: errno: 61 Connection refused 
2014-10-28T10: 47: 08713-0700 Error: could not connect to server 127.0.0.1:27017 (127.0.0.1) Attempt connection failed at src / mongo / shell / mongo.js: 146 
exception: connect failed 

Then try to check the mongod and I answered this:

然后试着检查mongod,我回答:

Mac-Pro-de-User: ~ user $ mongod 
mongod --help for help and startup options 
2014-10-28T10: 59: 34485-0700 [initandlisten] MongoDB starting: pid = 926 port = 27017 dbpath = / data / db host = 64-bit Mac-Pro-de-Ernesto.local 
2014-10-28T10: 59: 34485-0700 [initandlisten] 
2014-10-28T10: 59: 34485-0700 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, Should be at Least 1000 
2014-10-28T10: 59: 34485-0700 [initandlisten] db version v2.6.4 
2014-10-28T10: 59: 34485-0700 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910 
2014-10-28T10: 59: 34485-0700 [initandlisten] Build info: Darwin bs-osx108-4 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root: xnu-2050.48.12 ~ 1 / x86_64 RELEASE_X86_64 BOOST_LIB_VERSION = 1_49 
2014-10-28T10: 59: 34485-0700 [initandlisten] allocator: system 
2014-10-28T10: 59: 34485-0700 [initandlisten] options: {} 
2014-10-28T10: 59: 34486-0700 [initandlisten] journal dir = / data / db / journal 
2014-10-28T10: 59: 34486-0700 [initandlisten] recover: no journal files present, no recovery needed 
2014-10-28T10: 59: 34500-0700 [FileAllocator] allocating new datafile /data/db/local.ns, filling zeroes With ... 
2014-10-28T10: 59: 34500-0700 [FileAllocator] creating directory / data / db / _tmp 
2014-10-28T10: 59: 34512-0700 [FileAllocator] done allocating datafile /data/db/local.ns, size: 16MB, took 0.011 secs 
2014-10-28T10: 59: 34726-0700 [FileAllocator] allocating new datafile /data/db/local.0, filling zeroes With ... 
2014-10-28T10: 59: 35398-0700 [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0.671 secs 
2014-10-28T10: 59: 35695-0700 [initandlisten] build index on: local.startup_log properties: {v: 1, key: {_id: 1}, name: "_id_" ns "local.startup_log"} 
2014-10-28T10: 59: 35695-0700 [initandlisten] index added to empty collection 
2014-10-28T10: 59: 35695-0700 [initandlisten] Local command $ cmd command. Create {create: "startup_log" size: 10485760, capped: true} ntoreturn: 1 KeyUpdates: 0 numYields: 0 reslen: 37 1194ms 
2014-10-28T10: 59: 35695-0700 [initandlisten] waiting for connections on port 27017 
2014-10-28T11: 00: 34516-0700 [clientcursormon] mem (MB) res: 33 virt: 2653 
2014-10-28T11: 00: 34516-0700 [clientcursormon] mapped (incl journal view): 160 
2014-10-28T11: 00: 34516-0700 [clientcursormon] connections: 0 

Then try again to connect and spend some time, and again says the same:

然后再试着联系,花点时间,再说一遍:

2014-10-28T11: 05: 34589-0700 [clientcursormon] mem (MB) res: 33 virt: 2653 
2014-10-28T11: 05: 34589-0700 [clientcursormon] mapped (incl journal view): 160 
2014-10-28T11: 05: 34589-0700 [clientcursormon] connections: 0

And so on. If you can help would greatly appreciate it.

等等。如果你能帮忙,我将不胜感激。

PS: There is already the / data / db with 777 permissions, and I'm using OSX Mavericks 10.9.5

PS:已经有/ data / db具有777权限,我正在使用OSX Mavericks 10.9.5

4 个解决方案

#1


19  

Are you running all of these commands in the same terminal as separate actions as your timestamps suggest? (if not, I would expect to see overlap between the failures and logs in order to diagnose properly).

您是否在相同的终端中运行所有这些命令,就像您的时间戳所建议的那样单独操作?(如果没有,我希望看到故障和日志之间有重叠,以便正确诊断)。

If so, then what you are doing is as follows:

如果是这样,那么您正在做的是:

  1. Starting a shell, attempting to connect to a non-running database (connection refused)
  2. 启动一个shell,尝试连接到一个不运行的数据库(连接被拒绝)
  3. Starting the database, seeing 0 connections in the logs
  4. 启动数据库,在日志中看到0个连接
  5. Stopping the database (Ctrl-C or similar), starting a shell, fails to connect again because database has been shut down
  6. 停止数据库(Ctrl-C或类似的),启动shell,由于数据库已经关闭,因此无法再次连接
  7. Starting the database, seeing 0 connections in logs
  8. 启动数据库,查看日志中的0个连接
  9. repeat
  10. 重复

The database needs to be running concurrently with the shell so you can connect to it. Hence you should start the mongod process in one terminal, leave it running, and then open a new terminal (or tab) and run the mongo command to connect to the still running database. The other option is to run mongod as a daemon, which will allow you to run the mongo command in the same terminal once it returns.

数据库需要与shell同时运行,以便您可以连接到它。因此,您应该在一个终端中启动mongod进程,让它继续运行,然后打开一个新的终端(或制表符),并运行mongo命令连接到仍在运行的数据库。另一种选择是将mongod作为守护进程运行,这将允许您在mongo返回时在同一终端中运行该命令。

Note: you should never have a folder with 777 permissions, it is not required and is a significant security risk.

注意:您不应该有一个具有777权限的文件夹,它不是必需的,并且是一个严重的安全风险。

#2


1  

Just try this command.

试试这个命令。

sudo chown mongodb /tmp/mongodb-27017.sock

sudo乔恩mongodb / tmp / mongodb - 27017.的袜子

And

sudo service mongod restart

sudo mongod重启服务

#3


1  

Fixed!

固定!

The reason was the dbpath variable in /etc/mongodb.conf. Previously, I was using mongodb 1.8, where the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with --config /etc/mongodb.conf option.

原因是/etc/mongodb.conf中的dbpath变量。之前,我使用的是mongodb 1.8,其中dbpath的默认值是/data/db。新出现的作业mongodb(与mongodb-10gen包一起提供)使用-config /etc/mongodb调用mongod。配置选项。

As a solution, I only had to change the owner of the /data/db directory recursively.

作为一种解决方案,我只需递归地更改/data/db目录的所有者。

Like this: Go to "/data" location in the terminal and then type

如下所示:到终端的“/data”位置,然后输入

sudo chown -R <username>:foldername

sudo乔恩- r <用户名> :foldername

For example:

例如:

sudo chown -R raja db/

sudo chown -R raja db/

#4


0  

Hello just check if you created the /data/db path and if you did then give 755 permission with chmod.

你好,请检查您是否创建了/data/db路径,如果创建了,请向chmod授予755权限。

#1


19  

Are you running all of these commands in the same terminal as separate actions as your timestamps suggest? (if not, I would expect to see overlap between the failures and logs in order to diagnose properly).

您是否在相同的终端中运行所有这些命令,就像您的时间戳所建议的那样单独操作?(如果没有,我希望看到故障和日志之间有重叠,以便正确诊断)。

If so, then what you are doing is as follows:

如果是这样,那么您正在做的是:

  1. Starting a shell, attempting to connect to a non-running database (connection refused)
  2. 启动一个shell,尝试连接到一个不运行的数据库(连接被拒绝)
  3. Starting the database, seeing 0 connections in the logs
  4. 启动数据库,在日志中看到0个连接
  5. Stopping the database (Ctrl-C or similar), starting a shell, fails to connect again because database has been shut down
  6. 停止数据库(Ctrl-C或类似的),启动shell,由于数据库已经关闭,因此无法再次连接
  7. Starting the database, seeing 0 connections in logs
  8. 启动数据库,查看日志中的0个连接
  9. repeat
  10. 重复

The database needs to be running concurrently with the shell so you can connect to it. Hence you should start the mongod process in one terminal, leave it running, and then open a new terminal (or tab) and run the mongo command to connect to the still running database. The other option is to run mongod as a daemon, which will allow you to run the mongo command in the same terminal once it returns.

数据库需要与shell同时运行,以便您可以连接到它。因此,您应该在一个终端中启动mongod进程,让它继续运行,然后打开一个新的终端(或制表符),并运行mongo命令连接到仍在运行的数据库。另一种选择是将mongod作为守护进程运行,这将允许您在mongo返回时在同一终端中运行该命令。

Note: you should never have a folder with 777 permissions, it is not required and is a significant security risk.

注意:您不应该有一个具有777权限的文件夹,它不是必需的,并且是一个严重的安全风险。

#2


1  

Just try this command.

试试这个命令。

sudo chown mongodb /tmp/mongodb-27017.sock

sudo乔恩mongodb / tmp / mongodb - 27017.的袜子

And

sudo service mongod restart

sudo mongod重启服务

#3


1  

Fixed!

固定!

The reason was the dbpath variable in /etc/mongodb.conf. Previously, I was using mongodb 1.8, where the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with --config /etc/mongodb.conf option.

原因是/etc/mongodb.conf中的dbpath变量。之前,我使用的是mongodb 1.8,其中dbpath的默认值是/data/db。新出现的作业mongodb(与mongodb-10gen包一起提供)使用-config /etc/mongodb调用mongod。配置选项。

As a solution, I only had to change the owner of the /data/db directory recursively.

作为一种解决方案,我只需递归地更改/data/db目录的所有者。

Like this: Go to "/data" location in the terminal and then type

如下所示:到终端的“/data”位置,然后输入

sudo chown -R <username>:foldername

sudo乔恩- r <用户名> :foldername

For example:

例如:

sudo chown -R raja db/

sudo chown -R raja db/

#4


0  

Hello just check if you created the /data/db path and if you did then give 755 permission with chmod.

你好,请检查您是否创建了/data/db路径,如果创建了,请向chmod授予755权限。