[ACCEPTED]-couldn't connect to server 127.0.0.1 shell/mongo.js-ubuntu
- Manually remove the lockfile:
sudo rm /var/lib/mongodb/mongod.lock
- Run the repair script:
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
Please note the following:
- You must run this command as the mongodb user. If you run it as root, then root will own files in /var/lib/mongodb/ that are necessary to run the mongodb daemon and therefore when the daemon trys to run later as the mongodb user, it won't have permissions to start. In that case you'll get this error: Unable to create / open lock file for lockfilepath: /var/lib/mongodb/mongod.lock errno:13 Permission denied, terminating.
- On Ubuntu, you must specify the configuration file /etc/mongodb.conf using the -f flag. Otherwise it will look for the data files in the wrong place and you will see the following error: dbpath (/data/db/) does not exist, terminating.
0
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
Here is all, sometimes, it takes a little 2 while to start mongo after performing these 1 operations.
Trying running $mongod
If you get en error 8 such as
MongoDB shell version: 2.0.5
connecting to: test
Fri Jun 1 11:20:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
hisham-agil:~ hisham$ mongod
mongod --help for help and startup options
Fri Jun 1 11:24:47 [initandlisten] MongoDB starting : pid=53452 port=27017 dbpath=/data/db/ 64-bit host=hisham-agil.local
Fri Jun 1 11:24:47 [initandlisten] db version v2.0.5, pdfile version 4.5
Fri Jun 1 11:24:47 [initandlisten] git version: nogitversion
Fri Jun 1 11:24:47 [initandlisten] build info: Darwin gamma.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:48:32 PST 2012; root:xnu-1699.24.23~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Fri Jun 1 11:24:47 [initandlisten] options: {}
Fri Jun 1 11:24:47 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Fri Jun 1 11:24:47 dbexit:
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close listening sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to flush diaglog...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: waiting for fs preallocator...
Fri Jun 1 11:24:47 [initandlisten] shutdown: lock for final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: closing all files...
Fri Jun 1 11:24:47 [initandlisten] closeAllFiles() finished
Fri Jun 1 11:24:47 dbexit: really exiting now
Then you've run into a basic startup 7 error that is pretty common.
By default mongod 6 will try to use /data/db for its database 5 files, which in this case, does not exist.
You 4 can't start
mongo
until you handle
mongod.
Try creating 3 those directories and make sure they are 2 writable by the same user that is running 1 the mongod process.
**See similar question-- Getting an error, "Error: couldn't connect to server 127.0.0.1 shell/mongo.js" & when trying to run mongodb on mac osx lion
This is actually not an error... What happens 17 here is that Mongo relies on a daemon in order 16 to run the local database server, so in 15 order to "fire up" the mongo server in your shell, you 14 have to start the mongo service first.
For Fedora Linux (wich is the 13 Distro I use) You have to run these commands:
1 sudo service mongod start
2 mongo
And 12 there you have it! the server is going to 11 run. Now, If you want Mongo service to Start 10 when the system boots then you have to run:
sudo chkconfig --levels 235 mongod on
And 9 that's all! If you do that, now in the shell 8 you just have to type mongo in order to start 7 the server but that's pretty much it, the 6 problem is you have to start the SERVICE 5 first and then the SERVER :)
P.S. The commands 4 I posted might work on other linux distros 3 as well, not just in fedora... In case not 2 maybe you have to tweak some words depending on the distro 1 you're using ;)
I got the same problem when I tried to install 2 mongo. I got Error as,
Error
"Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84"
Solution:
First install mongod 1 by using:
sudo apt-get install mongodb-server
Then type
mongod --dbpath /mongo/db
Then
sudo rm /var/lib/mongodb/mongod.lock
Then
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
Thank You
You need to delete the lockfile mongod.lock
or /var/lib/mongodb/mongod.lock
on 2 ubuntu, then you need to run mongod.exe
or service mongodb start
on ubuntu 1 first, then run mongo.exe
or mongo
on ubuntu.
Either your mongod is not running (check 9 using "ps" command) or it is listening on 8 some outside IP address and not on localhost. So 7 first check the process list if 'mongod' is 6 running. If yes, check with "netstat -nap" for 5 the related port.
Of course you can start 4 mongod on the console manually or even look 3 into the mongod logfile (if there is one 2 configured...depending on how you installed 1 mongod).
First you have to make sure that all the 7 files and directories in your /var/lib/mongodb/ folder 6 (or whichever folder dbpath points to) belong 5 to the mongodb user and mongodb group.
cd /var/lib/mongodb/
sudo chown mongodb filename.*
sudo chgrp mongodb filename.*
sudo chown -R mongodb directory
sudo chgrp -R mongodb directory
(Replace 4 filename and directory with their respective 3 names)
Then you can remove the lock, repair 2 the database and restart the daemon as other 1 people already mentioned:
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
First start your mongo server by
Users-MacBook-Pro:csv1 Admin$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
Then open 1 another terminal window and open shell
Users-MacBook-Pro:csv1 Admin$ mongo
Also check that your root partition has 2 enough space to start mongod.
df -h /
You'll see 1 smth like this on mongod launch:
Mon Aug 12 17:02:59.159 [initandlisten] recover : no journal files present, no recovery needed
Mon Aug 12 17:02:59.159 [initandlisten]
Mon Aug 12 17:02:59.159 [initandlisten] ERROR: Insufficient free space for journal files
Mon Aug 12 17:02:59.159 [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
Mon Aug 12 17:02:59.159 [initandlisten]
Mon Aug 12 17:02:59.159 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
Mon Aug 12 17:02:59.159 dbexit:
Mon Aug 12 17:02:59.159 [initandlisten] shutdown: going to close listening sockets...
On Ubuntu, try this:
sudo invoke-rc.d mongodb start
0
It could be combination of $PATH and Permission 47 issue.
Try following steps given below:
Update 46 your $PATH variable to point to your MongoDB 45 bin file. In my case brew install MongoDB 44 to this folder:
/usr/local/Cellar/mongodb/2.4.6/
In order to update your $PATH 43 variable, do following:
$ sudo vi /etc/paths
Then, press ‘i’ to 42 insert text in Vi and append the your MongoDB 41 path to the end of the ‘paths’ file and 40 restart the terminal.
/usr/local/Cellar/mongodb/2.4.6/bin
Use ‘Esc : w q’ to 39 save and exit from Vi editor.
Use echo to 38 display your path variable:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/Cellar/mongodb/2.4.6/bin
Now try to check 37 the Mongo version, if you get following, then 36 you are on the right track!
$ mongo --version
MongoDB shell version: 2.4.6
Now we need to 35 create the database directory. I used the 34 default ‘/data/db’ location suggested in 33 MongoDB docs. I also created a log directory 32 to avoid any permission issues while Mongo 31 tries to create any logs. Change ownership 30 and that will do the job.
$ sudo mkdir /data/db
$ sudo mkdir /data/log
$ whoami
username
$ chown -R username /data
Now, we will create 29 a default config file for MongoDB to be 28 provided for the first time we run ‘mongod’ command. Now, I 27 will also like to point out that ‘mongod’ will 26 start a service, which will listen for incoming 25 data connections. This is similar having 24 ‘$service mysqld start’ executed.Let’s go 23 ahead and create the config file. Please 22 keep in mind that I have created very basic 21 config file. However, you can add many other 20 variables to configure MongoDB. This is 19 the first time I am playing with MongoDB, so 18 I just know as much as I read on MongoDB 17 docs!I created ‘mongodb.conf’.
$ sudo vi /etc/mongodb.conf
Add following:
fork = true
port = 27017
quiet = true
dbpath = /data/db
logpath = /data/log/mongod.log
logappend = true
journal = true
Please 16 note that the default port for MongoDB server 15 is 27017. Use your own path for dbpath and 14 logpath you created in Step – 5. Don’t forget 13 to close and save the conf file.
Now we are 12 all set to start our MongoDB service. Open 11 two instances of Terminal.In Terminal 1, type 10 in:
$ sudo mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3516
all output going to: /data/log/mongod.log
child process started successfully, parent exiting
If you get above message, then know that 9 you have successfully started your Mongod 8 service.
Now, to connect to it, in Terminal 7 2 type following:
$mongo test
MongoDB shell version: 2.4.6
connecting to: test
Server has startup warnings:
Tue Sep 3 16:55:43.527 [initandlisten]
Tue Sep 3 16:55:43.527 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
Ignore the warnings, but 6 you are successfully connected to the ‘test’ database! Cool!
That's 5 all. I applied this solution, when I tried 4 to install copy of MongoDB on my Mac for 3 the first time. See if this help you too.
For 2 detailed post you can go here - http://arcanebytes.com/2013/09/03/mongodb-installation-on-mac-os-x/#comment-1036112094.
I hope 1 it helps!
Cheers, Chinmay
I solved this problem on ubuntu 12.04 by 4 following steps:
1) sudo rm /var/log/mongodb
2) sudo 3 rm /var/lib/mongodb
3) I removed mongo and 2 then installed it again
4) sudo service 1 mongodb restart
and All is Well
For Ubuntu:
Just Open the terminal and enter 2 the below command. You just have to restart 1 your mongoDB.
sudo service mongodb restart
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.