I try to connect to mongodb based on the instructions provided here,I get this error instead:
vamsiampolu1@takenote:~/workspace (master) $ ./mongod
2014-11-17T09:00:10.101+0000 ** WARNING: --rest is specified without --httpinterface,
2014-11-17T09:00:10.101+0000 ** enabling http interface
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
2014-11-17T09:00:10.106+0000 [initandlisten] MongoDB starting : pid=2274 port=27017 dbpath=data 64-bit host=vamsiampolu1-takenote-1084968
2014-11-17T09:00:10.106+0000 [initandlisten] db version v2.6.5
2014-11-17T09:00:10.106+0000 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-17T09:00:10.106+0000 [initandlisten] build info: Linux build8.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-11-17T09:00:10.106+0000 [initandlisten] allocator: tcmalloc
2014-11-17T09:00:10.107+0000 [initandlisten] options: { net: { bindIp: "0.0.0.0", http: { RESTInterfaceEnabled: true, enabled: true } }, storage: { dbPath: "data", journal: { enabled: false } } }
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
2014-11-17T09:00:10.107+0000 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
2014-11-17T09:00:10.107+0000 [initandlisten] dbexit:
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: going to close listening sockets...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: going to flush diaglog...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: going to close sockets...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: waiting for fs preallocator...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: closing all files...
2014-11-17T09:00:10.107+0000 [initandlisten] closeAllFiles() finished
2014-11-17T09:00:10.107+0000 [initandlisten] dbexit: really exiting now
I have tried with the mongod --repair
flag.I have also tried to execute this script,which is what I do in case I shut my local machine down without closing mongod
properly:
#!/bin/sh
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
It says that the file /var/lib/mongodb/mongod.lock
was not found.I have tried to start mongodb
as a service:
sudo service mongod start
wherein,it asks me to use mongod start
which also fails with the same message.I have read about net.http.enabled
which should be left switched off because it could increase network exposure.
I used a Ubuntu 12.04
based vagrant
box once,so I tried with:
mongodb start
which tells me that mongodb
is not a valid command.
I have also tried mongo
which tells me that:
vamsiampolu1@takenote:~/workspace (master) $ mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-17T11:51:44.752+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-17T11:51:44.753+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
I believed that I might have mistakenly closed the terminal window running mongod
and thus am unable to start it.But it wont let me do what I usually do and continue working.
I have also tried to run this to find if mongod
was already running:
vamsiampolu1@takenote:~/workspace (master) $ ps ax | grep mongod
2504 pts/2 S+ 0:00 grep --color=auto mongod
I tried to stop it from running using the following:
stop mongod
Then I ran that again to find if mongod was still running:
vamsiampolu1@takenote:~/workspace (master) $ ps ax | grep mongod
2524 pts/2 S+ 0:00 grep --color=auto mongod
When I tried to run this:
vamsiampolu1@takenote:~/workspace (master) $ mongod --shutdown
There doesn't seem to be a server running with dbpath: /data/db
When I tried to set the dbpath
manually:
vamsiampolu1@takenote:~/workspace (master) $ ./mongod --dbpath /data/db
Error parsing command line: Multiple occurrences of option "--dbpath"
It looks to me like you have done a lot of things criss cross without really understanding what you are doing.
But basic understanding is necessary. So, here is a step by step guide to sanitize the environment and hopefully repair the database, annotated. You do have a backup, don't you?
Decide wether you want to use mongod as your own user vamsiampolu1
or root or a dedicated user. Contrary to popular belief, the sudo
command is not the Linux/UNIX equivalent of "I really want you to execute this command!" and a foot stomp. The sudo without the -u
parameter executes it's parameters with root privileges – the effective user id of the process will be root's. Files and directories will be created for the user and group root (except the process in questions drops root privileges). Usually, it is best to have a dedicated user for any daemon, so you should use mongodb as this is the user created by the ubuntu and 10gen packages.
Now we need to make sure that there is no mongod running:
vamsiampolu1@takenote:~ $ sudo killall mongod
(We want to kill all mongod processes, and since the only user capable of killing processes which might belong to a different user than himself is root, we tell the system to execute this command with root privileges)
We make sure that all the files and directories belong to the proper user
vamsiampolu1@takenote:~ $ sudo chown mongodb.mongodb -r /var/lib/mongodb
(We want to change the owner and the group of all directories below /var/lib/mongodb recursively to user mongodb and group mongodb and we need the according privileges to do so)
We remove the lockfile as user mongodb
vamsiampolu1@takenote:~ $ sudo -u mongodb rm /var/lib/mongodb/mongod.lock
Next, we will run the repair command as user mongodb
vamsiampolu1@takenote:~ $ sudo -u mongodb mongod -f /etc/mongod.conf --repair
Note that the -u mongodb
is crucial for your system to work properly after the repair.
This might take a while. Watch the log file carefully with
vamsiampolu1@takenote:~ $ tail -n 100 -f /var/log/mongodb/mongod.log
If it says [initandlisten] dbexit: really exiting now
, then …
Start mongod with
vamsiampolu1@takenote:~ $ sudo -u mongodb mongod -f /etc/mongod.conf
It should work now. If not please add the part of the log file from the last occurrence of
[initandlisten] repairDatabase local
all the way to the end to your question.