mongodb 无法启动

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

Mongodb won't start

macosmongodb

提问by Keva161

I installed MongoDB using the Mac Homebrew command but when I run mongod

我使用 Mac Homebrew 命令安装了 MongoDB,但是当我运行时 mongod

It's not recognized my my terminal :/

它无法识别我的终端:/

If I type in export PATH=$PATH:/usr/local/mongodb/binthen run mongodit starts up but quickly exits

如果我输入export PATH=$PATH:/usr/local/mongodb/bin然后运行mongod它会启动但很快退出

mongod --help for help and startup options
Sun Jan 20 18:59:25 [initandlisten] MongoDB starting : pid=59800 port=27017 dbpath=/data/db/ 64-bit host=Kevin-Tucks-MacBook-Pro.local
Sun Jan 20 18:59:25 [initandlisten] db version v2.0.4, pdfile version 4.5
Sun Jan 20 18:59:25 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf
Sun Jan 20 18:59:25 [initandlisten] build info: Darwin erh2.10gen.cc 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40
Sun Jan 20 18:59:25 [initandlisten] options: {}
Sun Jan 20 18:59:25 [initandlisten] journal dir=/data/db/journal
Sun Jan 20 18:59:25 [initandlisten] recover : no journal files present, no recovery needed
Sun Jan 20 18:59:25 [initandlisten] preallocateIsFaster=true 2.38
Sun Jan 20 18:59:25 [websvr] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:28017
Sun Jan 20 18:59:25 [websvr] ERROR:   addr already in use
Sun Jan 20 18:59:25 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
Sun Jan 20 18:59:25 [initandlisten] ERROR:   addr already in use
Sun Jan 20 18:59:25 [initandlisten] now exiting
Sun Jan 20 18:59:25 dbexit: 
Sun Jan 20 18:59:25 [initandlisten] shutdown: going to close listening sockets...
Sun Jan 20 18:59:25 [initandlisten] shutdown: going to flush diaglog...
Sun Jan 20 18:59:25 [initandlisten] shutdown: going to close sockets...
Sun Jan 20 18:59:25 [initandlisten] shutdown: waiting for fs preallocator...
Sun Jan 20 18:59:25 [initandlisten] shutdown: lock for final commit...
Sun Jan 20 18:59:25 [initandlisten] shutdown: final commit...
Sun Jan 20 18:59:25 [initandlisten] shutdown: closing all files...
Sun Jan 20 18:59:25 [initandlisten] closeAllFiles() finished
Sun Jan 20 18:59:25 [initandlisten] journalCleanup...
Sun Jan 20 18:59:25 [initandlisten] removeJournalFiles
Sun Jan 20 18:59:25 [initandlisten] shutdown: removing fs lock...
Sun Jan 20 18:59:25 dbexit: really exiting now

I've tried restarting my shell but if I try to run mongodagain, it comes back as unrecognised and requires me to retype in export PATH=$PATH:/usr/local/mongodb/bin.

我试过重新启动我的 shell,但如果我mongod再次尝试运行,它会以无法识别的状态返回,并要求我重新输入export PATH=$PATH:/usr/local/mongodb/bin.

回答by Sacha Nacar

Kyle: "It looks like mongo is already running or another process is using port 27017"

凯尔:“看起来 mongo 已经在运行,或者另一个进程正在使用端口 27017”

In this case, type the following command

在这种情况下,键入以下命令

ps wuax | grep mongo

You should see something that looks like this

你应该看到像这样的东西

User           31936   0.5 0.4 2719784 35624   ?? S     7:34pm   0:09.98 mongod
User           31945   0.0 0.0 2423368   184 s000 R+   8:24pm   0:00.00 grep mongo

Now enter the kill command for the mongod instance (31936 in this case):

现在输入 mongod 实例的 kill 命令(在本例中为 31936):

kill 31936

回答by jrule

I just installed brew on osx (10.9.3), mongod (2.6.1) and had the same problem. Def not running a second copy.

我刚刚在 osx (10.9.3)、mongod (2.6.1) 上安装了 brew 并且遇到了同样的问题。Def 不运行第二个副本。

$ lsof -i | grep 2701 

shows no open port.

显示没有开放端口。

I found the following helped.

我发现以下帮助。

The default config file brew writes (/usr/local/etc/mongod.conf) contains the line:

brew 写入的默认配置文件 (/usr/local/etc/mongod.conf) 包含以下行:

bind_ip = 127.0.0.1,<my-machine>.local

If you edit this file and change the line to either of the following:

如果您编辑此文件并将该行更改为以下任一内容:

bind_ip = 127.0.0.1
or
bind_ip = <my-machine>.local

Then restart the service with the command below, it should startup as expected.

然后使用下面的命令重新启动服务,它应该按预期启动。

$ brew services restart mongodb

You can check for success or failure by tailing the logfile in another window while starting

您可以通过在启动时在另一个窗口中拖尾日志文件来检查成功或失败

$ tail -f /usr/local/var/log/mongodb/mongo.log 

It appears it is trying to open both of the addresses listed here and they both resolve to 127.0.0.1 so we always get a failure when it tries to open the second port and then shuts the whole thing down.

似乎它正在尝试打开此处列出的两个地址,并且它们都解析为 127.0.0.1,因此当它尝试打开第二个端口然后关闭整个端口时,我们总是会失败。

回答by Kyle

Sun Jan 20 18:59:25 [websvr] ERROR: addr already in use Sun Jan 20 18:59:25 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017 Sun Jan 20 18:59:25 [initandlisten] ERROR: addr already in use

Sun Jan 20 18:59:25 [websvr] 错误:addr 已在使用 Sun Jan 20 18:59:25 [initandlisten] 错误:listen():bind() 失败 errno:48 地址已用于套接字:0.0。 0.0:27017 Sun Jan 20 18:59:25 [initandlisten] 错误:地址已在使用中

It looks like mongo is already running or another process is using port 27017

看起来 mongo 已经在运行或另一个进程正在使用端口 27017

回答by affhendrawan

this solution work for me. I'm using mongodb version 3.2

这个解决方案对我有用。我正在使用 mongodb 3.2 版

i set path to,

我设置了路径,

/usr/local/bin

and i make mongodb data directory to /data/db and set permission to myown account. This tutorialfrom mkyong is really helpful.

我将 mongodb 数据目录设置为 /data/db 并为我自己的帐户设置权限。mkyong 的这个教程真的很有帮助。

回答by Siddhartha Khanooja

For any of the people who land up here, this was resolved (at least on my end) by stopping the already running mongodbservice:

对于登陆这里的任何人,通过停止已经运行的mongodb服务解决了这个问题(至少在我这边):

brew services stop mongodb

brew services stop mongodb

and then running mongod.

然后运行mongod

回答by Caner ?akmak

It won't permit killing when you configured autostart so remove the lock file and repair it (mac osx).

当您配置自动启动时,它不允许杀死,因此删除锁定文件并修复它(mac osx)。

 cd /data/db
 rm mongod.lock
 sudo mongod --repair

回答by davidmc24

For mongod not being in your PATH, it looks like the logic to support that was tweaked a couple of times since the version you're on. If you upgrade, that issue might well be fixed automatically.

对于 mongod 不在您的 PATH 中,看起来支持的逻辑自您使用的版本以来已经调整了几次。如果您升级,该问题很可能会自动修复。

As others have already said, the error it's giving indicates that another process is already using the configured port. One possibility is that in the past, you ran the command that Homebrew presented to you to install MongoDB as a LaunchAgent. If that's the case, this command should undo that, allowing you to launch it from the command-line.

正如其他人已经说过的,它给出的错误表明另一个进程已经在使用配置的端口。一种可能性是,在过去,您运行 Homebrew 提供给您的命令将 MongoDB 安装为 LaunchAgent。如果是这种情况,此命令应撤消该操作,允许您从命令行启动它。

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist