Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb won't start

Tags:

macos

mongodb

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

It's not recognized my my terminal :/

If I type in export PATH=$PATH:/usr/local/mongodb/bin then run mongod it starts up but quickly exits

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 mongod again, it comes back as unrecognised and requires me to retype in export PATH=$PATH:/usr/local/mongodb/bin.

like image 411
Keva161 Avatar asked Jan 20 '13 19:01

Keva161


People also ask

Why MongoDB server is not starting?

We found that the reason for this error was the dbpath variable in /etc/mongodb. conf. Previously, 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.


Video Answer


3 Answers

Kyle: "It looks like mongo is already running or another process is using port 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):

kill 31936
like image 74
Sacha Nacar Avatar answered Oct 21 '22 12:10

Sacha Nacar


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

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

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.

like image 4
jrule Avatar answered Oct 21 '22 12:10

jrule


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

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

like image 3
Kyle Avatar answered Oct 21 '22 14:10

Kyle