CentOS 5.x Linux with MongoDB 2.0.1 (tried main and legacy-static)
MongoDB is running:
root 31664 1.5 1.4 81848 11148 ? Sl 18:40 0:00 ./mongod -f mongo.conf -vvvvv --fork
Using a simple shell connect to get to the server fails:
[root@xxxx bin]# ./mongo
MongoDB shell version: 2.0.1
connecting to: test
Mon Oct 31 18:41:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
The web interface on port 28017 loads fine, as does using the MongoDB shell from a remote Linux host. Can also telnet to localhost:27017, which means no ports are blocked. There is no SELinux running on this machine as well. I have also tried explicitly specifying localhost:2017/db
to no avail.
$ ./mongo remote-ip:27017
MongoDB shell version: 2.0.1
connecting to: remote-ip:27017/test
> show dbs
local 0.03125GB
>
Logs are completely mum on the subject:
.....
Mon Oct 31 18:40:34 [initandlisten] fd limit hard:1024 soft:1024 max conn: 819
Mon Oct 31 18:40:34 [initandlisten] waiting for connections on port 27017
Mon Oct 31 18:40:34 BackgroundJob starting: snapshot
Mon Oct 31 18:40:34 BackgroundJob starting: ClientCursorMonitor
Mon Oct 31 18:40:34 BackgroundJob starting: PeriodicTask::Runner
Mon Oct 31 18:40:34 [websvr] fd limit hard:1024 soft:1024 max conn: 819
Mon Oct 31 18:40:34 [websvr] admin web console waiting for connections on port 28017
Stracing the mongo shell client shows only one problematic call:
[pid 31708] connect(4, {sa_family=AF_INET, sin_port=htons(27017), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EBADF (Bad file descriptor)
Filesystem is clean, no ulimit restrictions (running as root for testing). I can see from the strace that the mongo
client is trying to connect via TCP (AF_INET
), but since it is local and MongoDB creates a file socket, is there a way to tell the client to connect through that instead? Or better yet, why would the client be throwing a EBADF?
EDIT: My basic Mongo conf:
dbpath=/root/mongodb-linux-i686-2.0.1/data
logpath=/root/mongodb-linux-i686-2.0.1/logs/mongo.log
slowms=15
rest=1
You may want to check your config to see if the bind_ip is set
If it is then this permits only local logins. Comment this out and restart mongo, this may help.
On Ubuntu:
Wed Jan 27 10:21:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84 exception: connect failed
Solution
look for if mongodb is running by following command:
If mongo is not running you get:
You are seeing that the mongo daemon is not there.
Then start it through configuration file(with root priev):
you can see the other details:
Open a new terminal to see the result of mongod --config /etc/mongodb.conf & then type mongo. It should be running or grep
NOW
you get the mongoDB shell
This is not the end of story. I will post the repair method so that it starts automatically every time, most development machine shutdowns every day and the VM must have mongo started automatically at next boot.
Not so much an answer but more of an FYI:I've just hit this and found this question as a result of searching. Here is the details of my experience:
Shell error
Mongo logs reveal
This perhaps indicates the other answer (JaKi) was experiencing the same thing, where some connections were purged and access made possible again for the shell (other clients)
This is actually not an error... What happens here is that Mongo relies on a daemon in order to run the local database server, so in order to "fire up" the mongo server in your shell, you have to start the mongo service first.
For Fedora Linux (wich is the Distro I use) You have to run these commands:
And there you have it! the server is going to run. Now, If you want Mongo service to Start when the system boots then you have to run:
And that's all! If you do that, now in the shell you just have to type mongo in order to start the server but that's pretty much it, the problem is you have to start the SERVICE first and then the SERVER :)
P.S. The commands I posted might work on other linux distros as well, not just in fedora... In case not maybe you have to tweak some words depending on the distro you're using ;)
I had a similar problem, well actually the same (mongo process is running but can't connect to it). What I did was went to my database path and removed mongod.lock, and then gave it another try (restarted mongo). After that it worked.
Hope it works for you too. mongodb repair on ubuntu
Delete
/var/lib/mongodb/mongod.lock
, then issuesudo service mongodb start
, thenmongo
.