MongoDB正在运行,但无法使用Shell连接 [英] MongoDB running but can't connect using shell
问题描述
带有MongoDB 2.0.1的CentOS 5.x Linux(尝试了主版本和旧版静态版本)
CentOS 5.x Linux with MongoDB 2.0.1 (tried main and legacy-static)
MongoDB正在运行:
MongoDB is running:
root 31664 1.5 1.4 81848 11148 ? Sl 18:40 0:00 ./mongod -f mongo.conf -vvvvv --fork
使用简单的shell连接来访问服务器失败:
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
端口28017上的Web界面可以很好地加载,就像使用远程Linux主机上的MongoDB shell一样.也可以通过telnet到localhost:27017,这意味着没有端口被阻止.该计算机上也没有运行SELinux.我也尝试过明确地指定localhost:2017/db
无济于事.
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
放置mongo shell客户端仅显示一个有问题的调用:
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)
文件系统干净,没有ulimit限制(以root身份运行以进行测试).从strace可以看到,mongo
客户端正在尝试通过TCP(AF_INET
)连接,但是由于它是本地的,并且MongoDB创建了文件套接字,是否有办法告诉客户端通过它进行连接?还是更好,为什么客户会抛出EBADF?
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?
我的基本Mongo conf:
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
推荐答案
我认为此版本的mongoDb客户端缺少一些默认配置.尝试运行:
I think there is some default config what is missing in this version of mongoDb client. Try to run:
mongo 127.0.0.1:27017
这很奇怪,但是后来我感觉到问题消失了:)(所以简单的命令"mongo"没有任何参数对我又开始起作用了)
It's strange, but then I've experienced the issue went away :) (so the simple command 'mongo' w/o any params started to work again for me)
[Ubuntu Linux 11.10 x64 / MongoDB 2.0.1]
这篇关于MongoDB正在运行,但无法使用Shell连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!