Monday, October 8, 2012

couldn't connect to server 127.0.0.1 shell/mongo.js

Hello,

So I've decided to learn a new database application in an effort to further pad my resume.  And with most things in Linux at the very beginning I get stuck; but it only took 2 minutes for me to fix the issue.

First my setup:

Lenovo Thinkpad
Linux Distro : Fuduntu
Kernel: 3.4.11-1.fu2012.x86_64

k,

So when you try to enter the MongoDB shell you're immediately hit with the error:

>mongo
MongoDB shell version: 2.2.0
connecting to: test
Monday Oct 8 2012 18:56:59 Error: couldn't connect to server 127.0.0.1:27017 /src/mongo/shell/ mongo.js:91
exception: connection failed

Ok, there's a couple things you should try to do:

1: Try to start mongo

If this doesn't work and you get the error below try step 2:
>/etc/init.d/mongo start
/etc/init.d/mongod: line 69 ulimit: open files: cannot modify limit: Operation not permitted
Starting mongod: runuser:  using restricted shell /bin/false
runuser: cannot set groups: operation not permitted

2:  > sudo rm /var/lib/mongo/mongod.lock
then
>  sudo -u mongod mongod -f /etc/mongod.conf --repair

You may get the following error:

can't open [ /var/log/mongo/mongod.log] for log file: errno:2 No such file or directory

I checked and the directory and file didn't exist so I created both

> mkdir /var/log/mongo
>touch /var/log/mongo/mongod.log

then change ownership of the log file to the mongod user
>chown mongod.mongod /var/log/mongo/mongod.log

then run the mongo repair again:

> sudo -u mongod mongod -f /etc/mongod.conf --repair

If it worked correctly you'll get the following:

forked process: 6956
all output going to: /var/log/mongo/mongod.log
child process started sucessfully, parent exiting

When you check MongoDB's status it should be running now:

> /etc/init.d/mongod status

mongod (pid 67584) is running ...

Then run the Mongo shell

> mongo
MongoDB shell version 2.2.0
connecting to test
>

I hope this helps someone!

4 comments:

  1. I followed along until the chown command, because I don't have a mongod user or group.

    ReplyDelete
  2. Post the error you're getting please.

    ReplyDelete
  3. The same problem occures:

    knaumova@knaumova:/etc$ chown mongod.mongod /var/log/mongo/mongod.log
    chown: invalid user: `mongod.mongod'

    ReplyDelete
  4. this worked for me:
    first>youridhere@ubuntu:/var/lib/mongodb$ sudo service mongodb start
    then >youridhere@ubuntu:/var/lib/mongodb$ sudo rm mongod.lock*

    ReplyDelete