unable to start mongodb local server
Asked Answered
B

25

169

I am new to mongodb .. when i tried running mongodb local server with mongod command it failed to run and threw this error..

/usr/lib/mongodb/mongod --help for help and startup options
Sat Jun 25 09:38:51 MongoDB starting : pid=1782 port=27017 dbpath=/data/db/ 32-bit 

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
**       see http://blog.mongodb.org/post/137788967/32-bit-limitations

Sat Jun 25 09:38:51 db version v1.6.3, pdfile version 4.5
Sat Jun 25 09:38:51 git version: nogitversion
Sat Jun 25 09:38:51 sys info: Linux vernadsky 2.6.24-27-server #1 SMP Fri Mar 12 01:45:06 UTC 2010 i686 BOOST_LIB_VERSION=1_42
Sat Jun 25 09:38:51 [initandlisten] *** warning: spider monkey build without utf8 support.  consider rebuilding with utf8 support
Sat Jun 25 09:38:51 [initandlisten] waiting for connections on port 27017
Sat Jun 25 09:38:51 [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Sat Jun 25 09:38:51 [initandlisten]   addr already in use
Sat Jun 25 09:38:51 [initandlisten] now exiting
Sat Jun 25 09:38:51 dbexit: 

Sat Jun 25 09:38:51 [initandlisten] shutdown: going to close listening sockets...
Sat Jun 25 09:38:51 [initandlisten] shutdown: going to flush oplog...
Sat Jun 25 09:38:51 [initandlisten] shutdown: going to close sockets...
Sat Jun 25 09:38:51 [initandlisten] shutdown: waiting for fs preallocator...
Sat Jun 25 09:38:51 [initandlisten] shutdown: closing all files...
Sat Jun 25 09:38:51     closeAllFiles() finished

Sat Jun 25 09:38:51 [initandlisten] shutdown: removing fs lock...
Sat Jun 25 09:38:51 dbexit: really exiting now

I tried deleting mongod.lock file... I ran mongod --repair.. I also changed permissions to mongod.lock file.

but nothing seems to work.. it keeps showing the same error.. what should i do.?

I also have installed git version 1.7.4.1 but it shows nogitversion in error..

Blameless answered 25/6, 2011 at 13:44 Comment(1)
I had the same problem and this solution worked for me #5799049Desiree
C
177

Try:

sudo service mongod stop
sudo mongod

To stop current active mongodb service, allowing you to then start a new one

Chuddar answered 31/1, 2013 at 12:3 Comment(8)
i also got the service message but decided to ignore it and try restarting again with "sudo mongod" and after it finally workedNunnery
Shouldn't this be mongod (not mongodb)? Based on docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/…Soinski
sudo service mongodb stop worked for me on Ubuntu 14.10.Numeral
There is no service command on OS X. If you have mongo installed via homebrew you can use brew services. (via unix.stackexchange.com/questions/155715/…)Wateriness
To see a solution on Mac OSX for stopping the mongod service, see this answer: https://mcmap.net/q/138075/-mongodb-won-39-t-startExtraditable
@HarshaMV ` brew services stop <formula> `Vanillic
For mac homebrew use @HarshaMV comment "brew services stop mongodb". Thanks HarshaInterradial
On Mac without Homebrew: 1) Open Activity Monitor and find 'mongod' under Process Name in the CPU pane. 2) Stop the 'mongod' process. 3) Restart the Mongo service in the Terminal with 'mongod'Resolutive
P
153

Don't kill the process using the -9 signal as it would cause damage: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal

Use sudo killall -15 mongod instead

Papert answered 8/8, 2012 at 7:56 Comment(3)
This does not answer the original question.Within
killall mongod does the same thing also. the -15 tells killall to send a SIGTERM signal, which it does by default.Randers
Actually doing a killall actually worked for me instead of trying to stop the service. So, even though it does not answer the questions. That was usefulCandidate
E
60

Andreas Jung:

"Sat Jun 25 09:38:51 [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017

is self-speaking.

Another instance of mongod is already running and allocating the MongoDB default port which is 27017.

Either kill the other process or use a different port."

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):

kill 31936
Elroyels answered 2/10, 2014 at 0:21 Comment(0)
E
29

Sat Jun 25 09:38:51 [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017

is self-speaking.

Another instance of mongod is already running and allocating the MongoDB default port which is 27017.

Either kill the other process or use a different port.

Escobedo answered 25/6, 2011 at 14:5 Comment(2)
Found this on getting started page...**When mongodb** is installed via aptitude it is already running (so in the example you do not need to start it). Then just type: $ mongo.. since i personally dint start mongod and i was following the quickstart tutorial .. i dint knew it was already running...Blameless
@Sakti: Yea, it is already running for me! I guess i did via aptitude. Thx!Willams
H
29

Find out from netstat which process is running mongodb port (27017)

command:

sudo netstat -tulpn | grep :27017

Output will be:

tcp        0      0 0.0.0.0:27017           0.0.0.0:* 
LISTEN      6432/mongod

In my case "6432" is the pid, it may be different in your case. Then kill that process using following command:

sudo kill <pid>

Thats it!

Horizon answered 29/5, 2014 at 8:13 Comment(0)
R
25

Use:

sudo killall mongod

It will stop the server.

Then restart mongod by:

sudo service mongod restart

it should work.

Rasp answered 17/6, 2016 at 19:6 Comment(0)
H
23

You already have a process running. You can kill it with the command :

killall mongod
Hunnish answered 15/8, 2015 at 0:1 Comment(0)
A
15

You want to do killall -15 mongod because it is still running: Address already in use for socket: 0.0.0.0:27017.

Then you can run mongod again.

Atrium answered 3/2, 2017 at 19:2 Comment(3)
Why not simply killall mongod?Return
No matching processes belonging to you were foundChapa
Then mongod must not be a process running. Maybe the address is being used by a different processAtrium
R
7

Try a different port if you can't find any current running processes or killing them doesn't work. For example, try 27018 because the default is 27017.

mongod  --port 27018

I found this out with the command, mongod --help

Reichard answered 6/12, 2015 at 23:26 Comment(0)
M
7

I suggest use instead:

$sudo service mongodb stop

That could work.

Maryland answered 13/1, 2018 at 18:22 Comment(0)
C
6

Try either killall -15 mongod/ killall mongod Even after this if this doesnt work then remove the db storage folder by typing the following commands sudo rm -rf /data/db sudo mkdir /data/db sudo chmod 777 /data/db

Cyndi answered 27/4, 2016 at 6:28 Comment(0)
E
5

OS X. Activity Monitor, look for mongod, cross it . then run again mongod. problem Solved.

Edge answered 27/6, 2016 at 17:17 Comment(1)
OP does not specify the OS but the log files clearly denote Linux.Episcopacy
R
4

Open the terminal and type:

mkdir -p /data/db

Then enter:

mongod
Reinert answered 10/10, 2015 at 20:32 Comment(0)
L
4

MongoDB unable to start is mainly due to unclean shutdown. To remedy, delete the mongod.lock file. This file is located in the data folder.

Find out where your data folder is by looking in the mongodb.conf or mongod.conf file. (Conf file under /etc on Linux systems.)

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb

For example using the above configuration, the file is at /var/lib/mongodb/mongod.lock. Simply remove it and restart mongodb.

Luckless answered 18/2, 2016 at 9:52 Comment(1)
This has happened to me more than once, especially on cloud servers that have been "hard reset" when unresponsive. It is an easy fix and should be a top answer.Gratianna
J
3

I had the same problem were I tried to open a new instance of mongod and it said it was already running.

I checked the docs and it said to type

mongo
use admin
db.shutdownServer()
Jerkwater answered 14/7, 2015 at 5:28 Comment(0)
D
2

I've faced the same issue. Though the mongodb service is not running, the log showed address already in use message.

 $netstat -tulpn | grep :27017 

returns nothing

On further analysis found that the issue was due to lock file. The service is running fine, after deleting the lock file and restarting it.

$grep "dbpath" /etc/mongodb.conf

dbpath =/var/lib/mongodb

$ls /var/lib/mongodb/mongod.lock

$service mongod start
Declination answered 10/4, 2015 at 5:57 Comment(0)
E
2

Check for logs at /var/log/mongodb/mongod.log and try to deduce the error. In my case it was

Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted

Deleted /tmp/mongodb-27017.sock and it worked.

Erna answered 20/11, 2015 at 10:54 Comment(0)
N
1

try

/usr/lib/mongodb/mongod.exe --dbpath c:data\db

--dbpath (should be followed by the path of your db)

Nosepiece answered 24/3, 2014 at 11:52 Comment(0)
M
1

It may be possible that the server is already running. Please check it by the command mongo is working or not.

Maas answered 12/1, 2015 at 9:55 Comment(0)
P
1

To resolve the issue in Windows, the below steps work for me:

For example mongoDB version 3.6 is installed, and the install path of MongoDB is "D:\Program Files\MongoDB".

Create folder D:\mongodb\logs, then create file mongodb.log inside this folder.

Run cmd.exe as administrator,

D:\Program Files\MongoDB\Server\3.6\bin>taskkill /F /IM mongod.exe
D:\Program Files\MongoDB\Server\3.6\bin>mongod.exe --logpath D:\mongodb\logs\mongodb.log --logappend --dbpath D:\mongodb\data --directoryperdb --serviceName MongoDB --remove
D:\Program Files\MongoDB\Server\3.6\bin>mongod --logpath "D:\mongodb\logs\mongodb.log" --logappend --dbpath "D:\mongodb\data" --directoryperdb --serviceName "MongoDB" --serviceDisplayName "MongoDB" --install

Remove these two files mongod.lock and storage.bson under the folder "D:\mongodb\data".

Then type net start MongoDB in the cmd using administrator privilege, the issue will be solved.

Pointenoire answered 30/6, 2018 at 14:34 Comment(0)
I
0

It shows error listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017 i.e. 27017 address is already in used by some other service. please check this by "netstat -apt| grep "27017"" command

Icj answered 5/2, 2014 at 6:23 Comment(0)
A
0

(If your're using linux,) if

mongod --shutdown --config=path/to/your/configFile.conf 

or

mongod --repair --config=path/to/your/configFile.conf 

didn't fix the issue, logout and re-login. That solved my problem.

Or you can kill the process manually from terminal, I guess.

Abet answered 30/5, 2014 at 16:4 Comment(0)
R
0

It looks like the same error is showed in logs when you're missing LC_ALL environment setting. It's confusing, but you may execute mongo client to see that it's a problem.

Ramification answered 28/11, 2014 at 13:9 Comment(0)
H
0

if you are running mongo for first time you might wanna set the path first

mongod --dbpath <path to the directory>
Holsworth answered 11/6, 2015 at 18:25 Comment(0)
H
0

Killing process did not solve my issue. My mac had crashed and on restart some of lock files (mongod.lock, WiredTiger.lock) were present in mongo dbPath. I moved these files to different folder (I did not delete to avoid more issues) and then it worked. On successul star, I deleted the moved lock files.

Hamil answered 13/7, 2018 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.