sanket@sanket:~$ sudo mongod
sudo: unable to resolve host sanket
[sudo] password for sanket: 
mongod --help for help and startup options
Sun Oct  5 09:58:48.970 [initandlisten] MongoDB starting : pid=2548 port=27017 dbpath=/data/db/ 64-bit host=sanket
Sun Oct  5 09:58:48.970 [initandlisten] db version v2.4.9
Sun Oct  5 09:58:48.970 [initandlisten] git version: nogitversion
Sun Oct  5 09:58:48.970 [initandlisten] build info: Linux orlo 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 BOOST_LIB_VERSION=1_54
Sun Oct  5 09:58:48.970 [initandlisten] allocator: tcmalloc
Sun Oct  5 09:58:48.970 [initandlisten] options: {}
Sun Oct  5 09:58:49.101 [initandlisten] journal dir=/data/db/journal
Sun Oct  5 09:58:49.102 [initandlisten] recover : no journal files present, no recovery needed
Sun Oct  5 09:58:49.237 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Sun Oct  5 09:58:49.237 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:28017
Sun Oct  5 09:58:49.237 [initandlisten] ERROR:   addr already in use
Sun Oct  5 09:58:49.237 [websvr] ERROR:   addr already in use
Sun Oct  5 09:58:49.237 [initandlisten] now exiting
Sun Oct  5 09:58:49.237 dbexit: 
Sun Oct  5 09:58:49.237 [initandlisten] shutdown: going to close listening sockets...
Sun Oct  5 09:58:49.237 [initandlisten] shutdown: going to flush diaglog...
Sun Oct  5 09:58:49.237 [initandlisten] shutdown: going to close sockets...
Sun Oct  5 09:58:49.237 [initandlisten] shutdown: waiting for fs preallocator...
Sun Oct  5 09:58:49.237 [initandlisten] shutdown: lock for final commit...
Sun Oct  5 09:58:49.237 [initandlisten] shutdown: final commit...
Sun Oct  5 09:58:49.328 [initandlisten] shutdown: closing all files...
Sun Oct  5 09:58:49.328 [initandlisten] closeAllFiles() finished
Sun Oct  5 09:58:49.328 [initandlisten] journalCleanup...
Sun Oct  5 09:58:49.328 [initandlisten] removeJournalFiles
Sun Oct  5 09:58:49.390 [initandlisten] shutdown: removing fs lock...
Sun Oct  5 09:58:49.390 dbexit: really exiting now
sanket@sanket:~$ 
  • Hmm... so, /data/db is owned by useer mongodb - seems right. But inside it, /data/db/journal is owned by root. Feels wrong to me. – Volker Siegel Oct 2 '14 at 9:02
  • how to change it??it's not allowing to change me the permissions from terminal or without command – Sanket Shirode Oct 2 '14 at 9:05
  • Yeah... the sudo: unable to resolve host sanket-PC error message is pretty spooky. That seems to be a separate problem. (but both could have the same cause) I added a little to the answer. – Volker Siegel Oct 2 '14 at 9:08
  • Something about the sudo: unable to resolve host issue - Related: askubuntu.com/questions/59458/… – Volker Siegel Oct 2 '14 at 9:11
  • Looks like you need to fix that sudo thing first - read the link above, it has a good answer. – Volker Siegel Oct 2 '14 at 9:17

Try this :

ps wuax | grep mongo

You should see something that looks like this

Savio           10592   0.5 0.4 2719784 35624   ?? S     7:34pm   0:09.98 mongod 
Savio           10911   0.0 0.0 2423368   184 s000 R+   8:24pm   0:00.00 grep mongo

or find word mongod.

and then

sudo kill 10592

after that start mongod again. for me its work, for error addr alredy use.

  • Works for me. One positive point added – Manwal Mar 22 '15 at 17:35

The server seems to be started as the wrong user, and can not access it's data files.

How did you start it?
Did you run it from the shell as your own user, or as a service?

Take a look at the owner of the data directories - that's the user it needs to run as.

The command

ls -ld /data /data/db /data/db/journal

would show the user (using three directories because I do not know which will be readable.)


Hmm... so, /data/db is owned by useer mongodb - seems right.
But inside it, /data/db/journal is owned by root. Feels wrong to me.

Try a sudo chown -R mongodb:mongodb /data/db/journal, then /data/db/journal with all files in it is owned by the mongodb user.

But there is a independent problem involved, that you need to fix before:
sudo does not work and shows the error sudo: unable to resolve host sanket-PC, which means you have currently no root access. See Error message when I run sudo: unable to resolve host (none).


You made an edit replacing the whole question text - without saying what changed, so the question makes sense.

Looking at the log, there is an interesting error:
The database tries to start, and finds that the network port it hast to use to lissten for client connections is already in use:

Sun Oct  5 09:58:49.237 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Sun Oct  5 09:58:49.237 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:28017
Sun Oct  5 09:58:49.237 [initandlisten] ERROR:   addr already in use
Sun Oct  5 09:58:49.237 [websvr] ERROR:   addr already in use

The port is choosen such that there normally is nobody using it for anything else; That means it's most probably mongod that is using the port - meaning there is an instance already running.
Try pgrep -fa mongod to show running mongod processes.

(Independant of this, it's unclear whether the original issue is fixed. It could not cause the original error here because there were no journal files.)

  • i ran it from terminal. sanket@sanket-PC:~$ ls -ld /data drwxr-xr-x 3 root root 4096 Sep 28 23:04 /data sanket@sanket-PC:~$ ls -ld /data/db drwxrwxrwx 3 mongodb mongodb 4096 Sep 30 22:34 /data/db sanket@sanket-PC:~$ ls -ld /data/db/journal drwxr-xr-x 2 root root 4096 Sep 30 22:45 /data/db/journal sanket@sanket-PC:~$ sudo chmod 777 /data/db/journal sudo: unable to resolve host sanket-PC [sudo] password for sanket: sanket@sanket-PC:~$ sudo chmod 777 /data sudo: unable to resolve host sanket-PC sanket@sanket-PC:~$ sudo chmod 777 /dat – Sanket Shirode Oct 2 '14 at 8:50
  • You can edit your question and apend it; Comments may get lost (and hard to read, in this case) – Volker Siegel Oct 2 '14 at 8:53
  • owner is root for most of the directories.How to change it .I am the administrator.the sudo mongod is also not working – Sanket Shirode Oct 2 '14 at 9:00

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.