MongoDB - shutting down with code 48

2020-06-02 15:12发布

问题:

I am trying to start MongoDB but the terminal returns the following error:

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.

回答1:

It seems like you have already a process running on the port where you want to start 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

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



回答2:

If you are using mac then you can simply kill the process running on port 27017 which is mongodb process in most cases.

Simply run the command.

npx kill-port 27017

After that you can run the mongod command as you normally do.

Or if you are using windows follow these steps

  • 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!

Enjoy!



回答3:

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

use admin

db.shutdownServer()


回答4:

This has worked for me

Initially i was facing various issues, like when i tried to start the server by using: sudo mongod

then i changed port for mongodb

sudo mongod --port 27018

Now mongod server is running tentatively

sudo mongod


回答5:

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.

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.



回答6:

Basically you just need to force quit the mongo, you can do this just by typing

sudo pkill -f mongod

and now you can start the server again with

mongod


回答7:

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.



回答8:

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.a Either you change the port of mongod by specifying port
number mongod --dbpath /System/Volumes/Data/data/db (path of db) —port 27018.

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.Starting mongo db brew services run mongodb-community

3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db(path)



标签: mongodb