Why can't I start mongodb server? - mongodb

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.

Related

MongoDB shut down in the middle of the night, can't get back up

I pushed some changes to the server tonight, which tested great on my local machine. When I went to test on the live server, it wasn't letting me connect, so I noticed mongodb stopped running. Exit code was 14. Now it's exit code 48. Here is my repair log:
2019-06-21T02:30:28.216-0400 W ASIO [initandlisten] No TransportLayer configured during NetworkInterface startup
2019-06-21T02:30:28.217-0400 I STORAGE [initandlisten] finished checking dbs
2019-06-21T02:30:28.217-0400 I STORAGE [initandlisten] WiredTigerKVEngine shutting down
2019-06-21T02:30:28.217-0400 I STORAGE [initandlisten] Shutting down session sweeper thread
2019-06-21T02:30:28.218-0400 I STORAGE [initandlisten] Finished shutting down session sweeper thread
2019-06-21T02:30:28.257-0400 I STORAGE [initandlisten] shutdown: removing fs lock...
2019-06-21T02:30:28.257-0400 I CONTROL [initandlisten] now exiting
2019-06-21T02:30:28.257-0400 I CONTROL [initandlisten] shutting down with code:0
root#pottstownrumble:~# mongod
2019-06-21T02:30:35.258-0400 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] MongoDB starting : pid=13525 port=27017 dbpath=/data/db 64-bit host=pottstownrumble
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] db version v4.0.10
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] allocator: tcmalloc
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] modules: none
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] build environment:
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] distmod: ubuntu1604
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] distarch: x86_64
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] target_arch: x86_64
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] options: {}
2019-06-21T02:30:35.262-0400 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] now exiting
2019-06-21T02:30:35.262-0400 I CONTROL [initandlisten] shutting down with code:48
Please, someone help me understand why it says something else is listening there . I'm exhausted and our big event is in 5 hours.
It looks like something is occupying port 27017. You need to find that process and kill it.
To find it use
sudo lsof -i -P -n | grep 27017 | grep LISTEN
The second column contains PID of this process.
You could also use ps to see more details about it.
Then use sudo kill <process-id> to kill it.
e.g.
mjaniec#amjay:~$ sudo lsof -i -P -n | grep 27017 | grep LISTEN
mongod 14903 mongodb 11u IPv4 25111697 0t0 TCP 127.0.0.1:27017 (LISTEN)
mjaniec#amjay:~$ sudo kill -9 14903
mjaniec#amjay:~$ sudo lsof -i -P -n | grep 27017 | grep LISTEN
mjaniec#amjay:~$
You can use netstat to see whats using the port:
netstat -pnltu | grep -i "80"
https://linoxide.com/linux-how-to/check-service-running-linux-port/

I am trying to start mongoDB server using the command mongod. However I get the following error

This is the error that I get on issuing mongod in the terminal
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] MongoDB
starting : pid=7402 port=27017 dbpath=/data/db 64-bit
host=bhagyashree-MS-7994
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] db version
v3.2.14
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] git version:
92f6668a768ebf294bd4f494c50f48459198e6a3
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] OpenSSL
version: OpenSSL 1.0.2g 1 Mar 2016
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] allocator:
tcmalloc
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] modules: none
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] build
environment:
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] distmod:
ubuntu1604
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] distarch:
x86_64
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten]
target_arch: x86_64
2017-06-25T14:53:50.591+0530 I CONTROL [initandlisten] options: {}
2017-06-25T14:53:50.609+0530 E NETWORK [initandlisten] listen():
bind() failed errno:98 Address already in use for socket:
0.0.0.0:27017
2017-06-25T14:53:50.609+0530 E NETWORK [initandlisten] addr already
in use
2017-06-25T14:53:50.609+0530 E STORAGE [initandlisten] Failed to set
up sockets during startup.
2017-06-25T14:53:50.609+0530 I CONTROL [initandlisten] dbexit: rc:
48
And on issuing a sudo netstat -plnt I get the following output,
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address
State PID/Program name
tcp 0 0 127.0.1.1:53 0.0.0.0:*
LISTEN 1920/dnsmasq
tcp 0 0 127.0.0.1:6942 0.0.0.0:*
LISTEN 3725/java
tcp 0 0 127.0.0.1:27017 0.0.0.0:*
LISTEN 7272/mongod
tcp 0 0 127.0.0.1:63342 0.0.0.0:*
LISTEN
3725/java
Thank you in advance!! I appreciate all the help!!
The error clearly tells the problem. You are trying to start a process that is already running or assign it to a port which is occupied. There are few ways to solve this.
1. Stop the service and start it again
sudo service mongod stop
sudo mongod
2. Quick fix ( may not be the best according to their documentations)
killall mongod
3. Deal with the process
Fins out which process is running the mongodb port
sudo netstat -tulpn | grep :27017
Next, kill the process that is using it by the command
sudo kill PID
(PID - Process id)
Now, you can start it again. It should be up and running!

MongoDB: Failed to set up sockets during startup

I have Windows 8.1 Enterprise 64 bit machine. I have installed mongodb msi for windows with SSL support. I created all the perquisites required for environment setup. Now using command prompt I navigated to the bin directory present into the mongodb installation folder and executed the following command:
mongod.exe --dbpath "c:\data"
And I see the following response:
C:\mongodb\bin>mongod.exe --dbpath "c:\data"
2016-05-27T17:09:43.362+0530 I CONTROL [initandlisten] MongoDB starting : pid=2
108 port=27017 dbpath=C:\data\db\ 64-bit host=TestServer
2016-05-27T17:09:43.363+0530 I CONTROL [initandlisten] targetMinOS: Windows 7/W
indows Server 2008 R2
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] db version v3.2.6
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] git version: 05552b562c7
a0b3143a729aaa0838e558dc49b25
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL
1.0.1p-fips 9 Jul 2015
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] modules: none
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] build environment:
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] distmod: 2008plus-ss
l
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] distarch: x86_64
2016-05-27T17:09:43.365+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-05-27T17:09:43.365+0530 I CONTROL [initandlisten] options: {}
2016-05-27T17:09:43.365+0530 E NETWORK [initandlisten] listen(): bind() failed
errno:10048 Only one usage of each socket address (protocol/network address/port
) is normally permitted. for socket: 0.0.0.0:27017
2016-05-27T17:09:43.366+0530 E STORAGE [initandlisten] Failed to set up sockets
during startup.
2016-05-27T17:09:43.366+0530 I CONTROL [initandlisten] dbexit: rc: 48
Can anyone please help me to how to fix this issue.
run
netstat -a -n | find "27017"
and chek if port 27017 is already used
F:\data\bin> netstat -a -n | find "27017"
TCP 0.0.0.0:27017 0.0.0.0:0 LISTENING
or run taskmgr and find and kill all mongod processes

Mongod not starting

I cannot run mongod in my ubuntu machine. I read some blogs and stackoverflow threads suggesting to change the ownership of the /var/lib/mongodb and /var/log/mongodb folders by,
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/log/mongodb
but I still cant run mongod and getting the following error message.
vinayak#vinayak-Lenovo-G500:~$ mongod
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] MongoDB starting : pid=3211 port=27017 dbpath=/data/db 64-bit host=vinayak-Lenovo-G500
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] db version v3.2.3
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] modules: none
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] build environment:
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] distmod: ubuntu1404
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] distarch: x86_64
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] options: {}
2016-03-04T09:31:29.968+0530 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-03-04T09:31:29.968+0530 E NETWORK [initandlisten] addr already in use
2016-03-04T09:31:29.968+0530 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-03-04T09:31:29.968+0530 I CONTROL [initandlisten] dbexit: rc: 48
vinayak#vinayak-Lenovo-G500:~$
..and I don't think so, my mongodb is corrupted as it is fresh install and I haven't tweaked anything in it.
Please suggest any solution. Thank you.
By your stack trace Error " Address already in use for socket: 0.0.0.0:27017"
You can try running on a different port
e.g
mongod --port 12345
Write following thing in the terminal and it would definitely work(it have worked for me in macbook).
sudo killall -15 mongod

Failed to set up sockets during startup. dbexit: rc: 48 error in mongodb

I updated mongo to version 3.2 now I am getting this error. Earlier I was not getting error. Only after updating mongo I am getting this error. I even tried to stop and start the mongod service again but still it is showing the same error.
rahul ~ $ mongod
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] MongoDB starting : pid=6630 port=27017 dbpath=/data/db 64-bit host=rahulcomp24-HP-ENVY-15-Notebook-PC
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] db version v3.2.0
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] modules: none
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] build environment:
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] distmod: ubuntu1404
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] distarch: x86_64
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-01-10T23:39:51.696+0530 I CONTROL [initandlisten] options: {}
2016-01-10T23:39:51.717+0530 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-01-10T23:39:51.717+0530 E NETWORK [initandlisten] addr already in use
2016-01-10T23:39:51.717+0530 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-01-10T23:39:51.717+0530 I CONTROL [initandlisten] dbexit: rc: 48
`
rahul ~ $ mongo
MongoDB shell version: 3.2.0
connecting to: test
Server has startup warnings:
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten]
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten]
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-01-10T23:38:16.095+0530 I CONTROL [initandlisten]
Find the process running on port 27017:
C:\Users\hughes> netstat -aon | findstr 27017
TCP 0.0.0.0:27017 0.0.0.0:0 LISTENING 3344
The last column shows the PID (3344). Find the process name for that PID:
C:\Users\hughes> tasklist /fi "pid eq 3344"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
VirtualBox.exe 3344 Console 1 101,908 K
For me it turned out that VirtualBox's port forwarding was the issue.
check if db in running, run:
ps aux | grep mongo
locate the db (ex. here is 77071) and kill it, run:
kill -9 77071
so the mongod output tells
listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017"
which means some process is already using the same socet. For instance, if I try to run mongod when its already running, I get exactly this output. Are you sure that this is not your case? I would guess so, as the mongo shell seems to connect successfully...