MongoDB - 使用代码 48 关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42072651/
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
MongoDB - shutting down with code 48
提问by ignite-me
I am trying to start MongoDB but the terminal returns the following error:
我正在尝试启动 MongoDB,但终端返回以下错误:
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] MongoDB starting : pid=25184 port=27017 dbpath=/data/db 64-bit host=Janiss-MacBook-Pro.local
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] db version v3.4.1
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] allocator: system
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] modules: none
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] build environment:
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] distarch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] options: {}
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] addr already in use
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] Failed to set up sockets during startup.
2017-02-06T16:26:27.038+0000 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-02-06T16:26:27.038+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-02-06T16:26:27.038+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-02-06T16:26:27.039+0000 I CONTROL [initandlisten] now exiting
2017-02-06T16:26:27.039+0000 I CONTROL [initandlisten] shutting down with code:48
I am using Laravel Valet if that matters.
如果这很重要,我正在使用 Laravel Valet。
回答by matyas
It seems like you have already a process running on the port where you want to start mongodb:
似乎您已经在要启动 mongodb 的端口上运行了一个进程:
listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] addr already in use
you could try to kill the process that runs on that port with this command:
sudo kill sudo lsof -t -i:27017
您可以尝试使用以下命令终止在该端口上运行的进程:sudo kill sudo lsof -t -i:27017
or define another port for mongodb if you have another program using that port.
to run mongodb on a port other than its default port (27017) use the --port 27018
argument when starting mongodb from the terminal
或者如果您有另一个程序使用该端口,则为 mongodb 定义另一个端口。
要在非默认端口 (27017) 的端口上运行 mongodb,请在--port 27018
从终端启动 mongodb 时使用该参数
回答by Vivek Maru
If you are using mac then you can simply kill the process running on port 27017
which is mongodb process in most cases.
如果您使用的是 mac,那么您可以简单地27017
终止在大多数情况下是 mongodb 进程的端口上运行的进程。
Simply run the command.
只需运行命令。
npx kill-port 27017
npx kill-port 27017
After that you can run the mongod
command as you normally do.
之后,您可以mongod
像往常一样运行该命令。
Or if you are using windows follow these steps
或者,如果您使用的是 Windows,请按照以下步骤操作
- Run command line as Admin
netstat -ano | findstr :27017
- you will get pid in the end that is the process id to kill
taskkill /PID <typeyourPIDhere> /F
- after successful termination of process you can run
mongod
as you usually do!
- 以管理员身份运行命令行
netstat -ano | findstr :27017
- 最后你会得到pid,这是要杀死的进程ID
taskkill /PID <typeyourPIDhere> /F
- 成功终止进程后,您可以
mongod
像往常一样运行!
Enjoy!
享受!
回答by MSi
For me the kill process did not work. Probably because my mongo instance was running on AWS. So, what I did was log onto a mongo shell. (This was possible as mongo instance is running) And switched to the admin DB thru 'use admin' and did 'db.shutdownServer()'. And that shut down the server cleanly
对我来说,kill 过程不起作用。可能是因为我的 mongo 实例在 AWS 上运行。所以,我所做的是登录到 mongo shell。(这在 mongo 实例正在运行时是可能的)并通过“使用管理员”切换到管理数据库并执行“db.shutdownServer()”。然后干净地关闭服务器
use admin
db.shutdownServer()
回答by Akash Jain
This has worked for me
这对我有用
Initially i was facing various issues, like when i tried to start the server by using:
sudo mongod
最初我面临着各种问题,比如当我尝试使用以下命令启动服务器时:sudo mongod
then i changed port for mongodb
然后我更改了 mongodb 的端口
sudo mongod --port 27018
Now mongod server is running tentatively
现在 mongod 服务器正在试运行
sudo mongod
回答by Maximilian Petkov
I had the same issue (MongoDB failed to start with exit code 48) after a reboot, as it could not bind to the given IP.
重新启动后,我遇到了同样的问题(MongoDB 无法以退出代码 48 启动),因为它无法绑定到给定的 IP。
It turned out, that the mongod systemctl unit file was configured to launch the mongod service after the network.target
. I changed this to network-online.target
and it seems to work.
事实证明,mongod systemctl 单元文件被配置为在network.target
. 我将其更改为network-online.target
,它似乎有效。
回答by Heitor Freitas
Basically you just need to force quit the mongo, you can do this just by typing
基本上你只需要强制退出mongo,你可以通过输入来做到这一点
sudo pkill -f mongod
and now you can start the server again with
现在你可以再次启动服务器
mongod
回答by Dishu bagga
1.And if the mongod show error (shutting down with code 48) that
means the port is being already use so you can do two things
1.如果 mongod 显示错误(使用代码 48 关闭),则
意味着该端口已被使用,因此您可以做两件事
1.a Either you change the port of mongod by specifying port
number
mongod --dbpath /System/Volumes/Data/data/db (path of db) —port 27018.
1.a 要么通过指定端口
号 mongod --dbpath /System/Volumes/Data/data/db (db 的路径) — 端口 27018来更改 mongod 的端口。
2.b Or You can kill the process at that port by finding
the process by
sudo lsof -i :27017
and then kill by command
kill -9
2.b 或者您可以通过 sudo lsof -i :27017 找到进程,然后通过命令
kill -9杀死该端口处的进程
2.Starting mongo db brew services run mongodb-community
2.启动mongo db brew服务运行mongodb-community
3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db(path)
3.输入mongod或mongod --dbpath /System/Volumes/Data/data/db(path)
回答by WasiF
How I solved my issue?
我是如何解决我的问题的?
I don't know the actual reason for this error and its solution but I deleted mongodb database folders C:\data\db
and restarted my PC.
我不知道此错误的实际原因及其解决方案,但我删除了 mongodb 数据库文件夹C:\data\db
并重新启动了我的 PC。