Mongod [initandlisten] dbexit: rc: 48 - mongodb

When I run mongod I recieved this error. How can I solve this? Thanks.
enter image description here

Try to stop current active mongodb service and run it again
$ sudo service mongod stop
$ mongod
You may encounter the problem of Failed to stop mongod.service: Unit mongod.service not loaded, this error says that your mongod is not running. Check this answer
If you use Mac
$ sudo killall mongod
If it did not work, try to find out which process is running on port (27017) and kill it
$ sudo netstat -tulpn | grep :27017
Kill the process
$ sudo kill <pid>
Or just try on another port with mongod --port 27027

Related

MongoDB in Linux Mint 19

I am trying to use mongoDB in Linux mint 19. But I am getting below error.
What is the solution ?
You're starting the mongo shell client, which by default tries to connect to a mongod server running on localhost and listening on port 27017. However, there is no server listening there so the mongo shell notes that and exits.
You'll need to investigate why there was no mongod server listening there:
The MongoDB Server package isn't installed
You're specifying a non-default port in e.g. /etc/mongod.conf
The mongod process/service is not running
...
First verify that the Server package is installed:
sudo dpkg -l | grep -i ".*mongodb.*server"
Then check the status of the mongod service and go from there. That will tell you if it's running, what port it's listening on, what config file is used, etc.
sudo systemctl status mongod
If it's not running then try to start it:
sudo systemctl start mongod
If it's still not running then look at the log messages:
sudo journalctl -u mongod.service

SocketException: Address already in use MONGODB

i found this error when trying to run mongodb. I install it via homebrew. Please assist
Agungs-MacBook-Pro:~ agungmahaputra$ mongod
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] MongoDB starting : pid=5189 port=27017 dbpath=/data/db 64-bit host=Agungs-MacBook-Pro.local
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] db version v3.6.0
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] allocator: system
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] modules: none
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] build environment:
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] distarch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] target_arch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] options: {}
2017-12-26T15:31:15.911+0700 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] now exiting
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] shutting down with code:48
Agungs-MacBook-Pro:~ agungmahaputra$
You can kill the previous mongod instance and start the new one.
To kill the previous mongod instance, first search for a list of tasks running on your machine by typing,
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
Now start your mongod instance by typing,
mongod
You can see MongoDB running successfully.
You already have a process running in the port 27017 which is used by mongodb. So either you need to stop the process in that port or try with different port number.
Try mongod --port 27018
You can change the port number of your choice.
EDIT:
You can also just stop all the running instances of mongo server using
sudo killall mongod as mentioned by #Dassi Orleando in the comments.
And run mongod
Summary other(#Tony Roczz, #Balasubramani M) answer to here:
Root Cause
error: Failed to set up listener: SocketException: Address already in use
means:
previously have run mongodb
probably use default port 27017
Solution
(most case) kill and restart mongod
kill mongod
two method:
use killall
killall mongod
kill by PID
find mongod PID
method 1: ps aux | grep mongod
output can see like this: limao 425 ... /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
method 2: lsof -iTCP -sTCP:LISTEN -n -P
output can see like this: mongod 425 limao .. TCP 127.0.0.1:27017 (LISTEN)
kill by PID: kill -9 425
re-start mongod
most case: mongod
some special case
brew services start mongodb-community
for install community version in Mac by: brew install mongodb-community
(for some people) run with another port
run with another port: mongod --port 27018
only for those want to run multiple mongod server same time
Additional Note
which port the running mongodb is using?
 lsof -iTCP -sTCP:LISTEN -n -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 425 limao 10u IPv4 0xab744305e75263cf 0t0 TCP 127.0.0.1:27017 (LISTEN)
can see 27017 is current running mongodb port.
how to check / make sure mongod is running
check mongod status:
ps aux | grep mongod
output can see mongod service
brew services list
if installed by brew and start by brew
if you're using mongodb version 4.*
in default settings, there should be a "db" folder "/data/db" having the necessary permission.
to check it the MongoDB service started
brew services list
if not then run
brew services start mongodb
run mongo instead of mongod
I solved it pasting the command below into the command line in order to close mongo's server.
sudo pkill -f mongod
"sudo" (Super User Do) runs the command admin permissions, so it will ask you for your user password
First, shutdown the running server using:
mongod --shutdown
Then run:
sudo mongod
After running this commands below:
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
And restarting mongod, it still fails with the same error "SocketException: Address already in use MONGODB".
Server was restarted yesterday and then this happened.
Just this single command
sudo pkill -f mongod
Make Sure the error is of the port , if using macos catalina there is a reported issue for ~/data/db which also causes this.
If your mongod process is already down, just remove the .sock file in /tmp:
My mongod is already down, so does not appears in:
lsof -iTCP -sTCP:LISTEN -n -P
The error was:
[root#ol7db19c1 ~]# mongod -f /etc/csrs_2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6721
ERROR: child process failed, exited with error number 48
To see additional information in this output, start without the "--fork" option.
In the log file (/var/mongodb/db/csrs2.log):
2020-07-05T16:03:59.354-0300 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
So, find for the socket locking:
ls -ltra /tmp|grep .sock
And just remove it (do it with caution in production environment):
rm -f mongodb-26002.sock
G-luck!
This may sound obvious but you should check if mongodb is already running.
So instead of first starting the the DB by running:
sudo mongod
Try directly running:
mongo

MongoDB Failing to Start - ***

I have configured mongodb with yu on linux.
enabled systemctl enable mongod.service as well, when ever exit do ctrl+c,
systemctl status mongod.service status is failed
mongod --port 27017 says connecting.. but status is still failed.
netstat show port 27017 is listening
any suggestions?
db version 3.2.4, in rc.d/init.d not able to find mondo script, for chkconfig mongod on

Failed to restart mongod.service: Unit mongod.service not found

While restart mongodb server using below command. its showing error like : Failed to restart mongod.service: Unit mongod.service not found.
sudo service mongod restart
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
You can try
sudo systemctl unmask mongodb
and re-run
sudo service mongod start

Postgres.app port in use

I am trying to start the server and getting an error
Port 5432 is already in use
I have brew uninstall postgress
which postgres
gives me nothing.
Activity monitor has 14 postgres processes which I cannot kill.
Force quit kill the process and restarts it with another pid.
The same with
sudo kill -9 PID
it kills the process and restarts it with another PID.
If you are running into this problem on OSX, do the following:
Find out what is running on that port:
$ lsof -n -i4TCP:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python2.7 28687 afdasdfasd 3u IPv4 0x2f18e1284963d3e3 0t0 TCP 127.0.0.1:54970->127.0.0.1:postgresql (CLOSE_WAIT)
Kill it
$ kill -9 28687
Restart postgresapp
Have you checked for a launch daemon? It controls the Postgres process when Postgres is installed with Homebrew, and it automatically restarts Postgres after it is killed. Try
sudo launchctl list
or
sudo launchctl list | fgrep postg
to find the name of the daemon. You can stop the daemon with sudo launchctl stop <name> where name depends on the result of the first command.
Askubuntu provided an answer that worked for me:
sudo pkill -u postgres
Source: Nicely stop all postgres processes
$ brew services stop postgresql
This will kill all processes and let you start the server.
You can get the list of ports using:
sudo launchctl list
Then enter the application name, and using this command to get the port nunber:
sudo launchctl list | fgrep postg
In my case, the port is 83. Now use:
kill 83
then
sudo kill 5432
Run those commands
To check what is running on port 5432 - $ sudo lsof -i :5432
To kill Postgres - $ sudo pkill -u postgres
Use this:
brew services stop postgresql
Good luck!