Keva161
Keva161

Reputation: 2693

Mongodb won't start

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.

Upvotes: 23

Views: 23687

Answers (7)

Caner
Caner

Reputation: 1498

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

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

Upvotes: 0

Siddhartha Khanooja
Siddhartha Khanooja

Reputation: 67

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

brew services stop mongodb

and then running mongod.

Upvotes: 1

affhendrawan
affhendrawan

Reputation: 311

this solution work for me. I'm using mongodb version 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 tutorial from mkyong is really helpful.

Upvotes: 1

Sacha Nacar
Sacha Nacar

Reputation: 2308

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

Upvotes: 80

jrule
jrule

Reputation: 333

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.

Upvotes: 4

davidmc24
davidmc24

Reputation: 2282

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.

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.

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

Upvotes: 0

Kyle
Kyle

Reputation: 22258

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

Upvotes: 3

Related Questions