Mongodb wont start: addr already in use - mongodb

when I try to start my database, mongodb is logging the following messages:
2014-08-12T08:42:17.522-0300 [initandlisten] journal dir=/www/mongodb/data/journal
2014-08-12T08:42:17.523-0300 [initandlisten] recover : no journal files present, no recovery needed
2014-08-12T08:42:17.564-0300 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2014-08-12T08:42:17.564-0300 [initandlisten] ERROR: addr already in use
2014-08-12T08:42:17.567-0300 [initandlisten] now exiting
2014-08-12T08:42:17.567-0300 [initandlisten] dbexit:
2014-08-12T08:42:17.567-0300 [initandlisten] shutdown: going to close listening sockets...
And it wont start.
But then I run the next command nothing is returned:
sudo netstat -ltnp | grep 27017
The server was manually shutdown (db.shutdownServer()) and it is a part of a replica set.
I noticed that the mongod.lock is created in the process, but removing it doesnt solve the problem.
So i guess the error message isnt quite right.
I'm using MongoDB shell version: 2.6.1
Anyone knows what could be the problem?

I had same issue.
In my config file in bindIp I had 2 ports specified, and for some reason mongo tried to run both of them simultaneously.
Leave only one and make sure it is in etc/hosts.

Related

Connect failed to mongodb shell

I have installed mongo, run the shell success in couple of time, then I try to add:
security:
authorization: disabled
because I want to add user Admin to admin db. After that, I can not access the mongo shell, this error show up when run command mongo
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017
2018-02-09T09:34:48.769+0700 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-02-09T09:34:48.769+0700 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
And here is few last lines of the log file after disable authorization, even when enable it again, thing doesn't work /var/log/mongodb/mongod.log
2018-02-09T09:33:00.843+0700 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-02-09T09:33:00.843+0700 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-02-09T09:33:00.843+0700 I CONTROL [initandlisten]
2018-02-09T09:33:00.847+0700 F CONTROL [initandlisten] ** IMPORTANT: UPGRADE PROBLEM: The data files need to be fully upgraded to version 3.4 before attempting an upgrade to 3.6; see http://dochub.mongodb.org/core/3.6-upgrade-fcv for more details.
2018-02-09T09:33:00.847+0700 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2018-02-09T09:33:00.847+0700 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2018-02-09T09:33:00.847+0700 I REPL [initandlisten] shutdown: removing all drop-pending collections...
2018-02-09T09:33:00.847+0700 I REPL [initandlisten] shutdown: removing checkpointTimestamp collection...
2018-02-09T09:33:00.848+0700 I STORAGE [initandlisten] shutdown: waiting for fs preallocator...
2018-02-09T09:33:00.848+0700 I STORAGE [initandlisten] shutdown: final commit...
2018-02-09T09:33:00.849+0700 I JOURNAL [initandlisten] journalCleanup...
2018-02-09T09:33:00.849+0700 I JOURNAL [initandlisten] removeJournalFiles
2018-02-09T09:33:00.876+0700 I JOURNAL [initandlisten] old journal file /var/lib/mongodb/journal/j._0 will be reused as /var/lib/mongodb/journal/prealloc.0
2018-02-09T09:33:00.899+0700 I JOURNAL [initandlisten] Terminating durability thread ...
2018-02-09T09:33:00.950+0700 I JOURNAL [journal writer] Journal writer thread stopped
2018-02-09T09:33:00.950+0700 I JOURNAL [durability] Durability thread stopped
2018-02-09T09:33:00.950+0700 I STORAGE [initandlisten] shutdown: closing all files...
2018-02-09T09:33:00.953+0700 I STORAGE [initandlisten] closeAllFiles() finished
2018-02-09T09:33:00.953+0700 I STORAGE [initandlisten] shutdown: removing fs lock...
2018-02-09T09:33:00.953+0700 I CONTROL [initandlisten] now exiting
2018-02-09T09:33:00.953+0700 I CONTROL [initandlisten] shutting down with code:62
I tried to run sudo service mongod restart but doesn't work.
So can you give me some advices for this problem, thanks
Is seems that mongod can't start because your system has updated mongodb from version < 3.4 to 3.6 as it stated in the log: The data files need to be fully upgraded to version 3.4 before attempting an upgrade to 3.6
You need to downgrade mongodb to 3.4, then sudo service mongod start to trigger the db migration to 3.4.
I just try to run this command and it works for me brew services start mongodb
Cheers.

Having trouble installing and using mongodb. on my macosx and a readonly /data/db

I want to install Mongodb for my next online web course but the thing is I'm having so much issues. I have been installing and uninstall mongodb so many times I think it's conflicting with temp ... Can someone guide me to the process please, really would appreciate it.
The error when running mongodb:
017-07-02T10:31:41.547-0400 I STORAGE [initandlisten] exception in
initAndListen: 20 Attempted to create a lock file on a read-only
directory: /data/db, terminating 2017-07-02T10:31:41.547-0400 I
NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-07-02T10:31:41.547-0400 I NETWORK [initandlisten] shutdown: going
to flush diaglog... 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] now exiting 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] shutting down with code:100 –
I tried installing it on homebrew , nothing happen, I tried installing it manually still having troubles.. I know my basic like cd,ls,rm,pwd,touch, when using the terminal, If theres process that i can wipe everything associate with mangodb in my Macbook and install it again i have no problem.
found out that /data/db is readonly
MongoDB is already installed but you have some issue launching it.
017-07-02T10:31:41.547-0400 I STORAGE [initandlisten] exception in
initAndListen: 20 Attempted to create a lock file on a read-only
directory: /data/db, terminating 2017-07-02T10:31:41.547-0400 I
NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-07-02T10:31:41.547-0400 I NETWORK [initandlisten] shutdown: going
to flush diaglog... 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] now exiting 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] shutting down with code:100 –
Change the permission of /data/db
sudo chown -R `id -un` /data/db
Now you should start the daemon without problem:mongod
then connect with your mongo client by typing. mongo
ok.. then got this. 2017-07-02T10:50:39.069-0400 I CONTROL
[initandlisten] options: { repair: true, storage: { dbPath: "/data/db"
} } 2017-07-02T10:50:39.069-0400 W - [initandlisten] Detected unclean
shutdown - /data/db/mongod.lock is not empty.
2017-07-02T10:50:39.069-0400 E NETWORK [initandlisten] Failed to
unlink socket file /tmp/mongodb-27017.sock Permission denied
2017-07-02T10:50:39.069-0400 I - [initandlisten] Fatal Assertion 28578
at src/mongo/util/net/listen.cpp 195 2017-07-02T10:50:39.070-0400 I -
[initandlisten] ***aborting after fassert() failure
your /tmp is maybe not readable, try:
chmod 1777 /tmp

Why can't I start mongodb server?

I try to start mongodb server, but it exists immediatly. Is it because it tried to use a port already in use? How shall I run it correctly? Thanks.
I am on Ubuntu 14.04, and installed mongodb following the guideline in mongodb website.
$ mongod
2016-08-04T11:06:39.947-0400 I CONTROL [initandlisten] MongoDB starting : pid=15947 port=27017 dbpath=/data/db 64-bit host=ocean
2016-08-04T11:06:39.947-0400 I CONTROL [initandlisten] db version v3.2.8
2016-08-04T11:06:39.951-0400 I CONTROL [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
2016-08-04T11:06:39.952-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-08-04T11:06:39.952-0400 I CONTROL [initandlisten] allocator: tcmalloc
2016-08-04T11:06:39.952-0400 I CONTROL [initandlisten] modules: none
2016-08-04T11:06:39.952-0400 I CONTROL [initandlisten] build environment:
2016-08-04T11:06:39.952-0400 I CONTROL [initandlisten] distmod: ubuntu1404
2016-08-04T11:06:39.952-0400 I CONTROL [initandlisten] distarch: x86_64
2016-08-04T11:06:39.953-0400 I CONTROL [initandlisten] target_arch: x86_64
2016-08-04T11:06:39.953-0400 I CONTROL [initandlisten] options: {}
2016-08-04T11:06:40.015-0400 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-08-04T11:06:40.016-0400 E NETWORK [initandlisten] addr already in use
2016-08-04T11:06:40.016-0400 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-08-04T11:06:40.016-0400 I CONTROL [initandlisten] dbexit: rc: 48
It tells you that Address already in use for socket: 0.0.0.0:27017.
Try on another port with mongod --port 27018.
To kill process that uses port 27017 on ubuntu you can use lsof -i :27017 to find PID of that process and then kill -9 <PID>.
The error is shown pretty clearly here:
listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
This is saying that the socket is already bound by something else - that is, there is another service already running on port 27017; most likely, an instance of your mongo server already ( only one process can bind to a port at a time )
Use this
ps aux | grep mongod
To find any mongod processes that are already running. Use kill <pid> to end the process.
If you want to start a second instance of mongo, then you need to have it bind to a new port, you can do this using
mongod --port 27015
Note, that if you start a second instance, you will also need to provide a second data directory - you should not have two running instances using the same database files.

Mongodb service not running

I'm working on this automatic drink dispenser and ran into an issue when I downloaded the Mongo 3.0.7 I tried to run it but I keep getting this error:
I got the idea from this website. http://yujiangtham.com/2014/05/30/build-your-very-own-drink-mixing-robot-part-2/
2016-02-02T15:56:42.585-0500 E NETWORK [initandlisten] listen():
bind() failed errno:48 Address already in use for socket:
0.0.0.0:27017
2016-02-02T15:56:42.585-0500 E NETWORK [initandlisten] addr already
in use 2016-02-02T15:56:42.593-0500 W - [initandlisten]
Detected unclean shutdown - /data/db/mongod.lock is not empty.
2016-02-02T15:56:42.593-0500 I STORAGE [initandlisten] exception in
initAndListen: 98 Unable to lock file: /data/db/mongod.lock errno:35
Resource temporarily unavailable. Is a mongod instance already
running?, terminating
2016-02-02T15:56:42.593-0500 I CONTROL [initandlisten] dbexit: rc:
100
I need help on how to run this. The website I'm using as a reference is
http://yujiangtham.com/2014/05/30/build-your-very-own-drink-mixing-robot-part-2/
It is stating that Mongo is already running. If you are certain it is not, then the lock file still exists from a previous unclean shutdown.
ps aux | grep mongo
if that returns nothing, it will mean the lock file still exists. looking at your error, the file is /data/db/mongod.lock
rm /data/db/mongod.lock
Should get rid of it so you'll be able to start the mongo service running again.
Try running pkill mongod to kill the process

Mongodb not working properly : Socket already in use?

I am taking the mongodb university class and having problems getting mongod to work properly. I have been trying for hours to try to get it to work properly, but I keep getting the same error.
When I try to run mongod I am getting this error:
erics-mbp:~ emlandst$ mongod --dbpath data
2015-08-16T18:55:24.186-0400 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2015-08-16T18:55:24.186-0400 E NETWORK [initandlisten] addr already in use
2015-08-16T18:55:24.186-0400 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory data not found., terminating
2015-08-16T18:55:24.186-0400 I CONTROL [initandlisten] dbexit: rc: 100
If I am correct the server is set to run on port 27017 by default and for some reason it is being blocked. I tried the ps waux | grep mongo and then I killed the instance, but still i get the same error.
I am trying to just delete everything so I can start all over, but I have no idea how to do that. I'm sure it is simple I just don't have a lot of experience. Thank you