[英]Mongo Shell couldn't connect to the local server
I'm starting MongoDB using the following command: 我正在使用以下命令启动MongoDB:
sumeet@sumeet-acer:~$ sudo service mongod start
I get a reply as: 我得到的答复是:
mongod start/running, process 7209
sumeet@sumeet-acer:~$
But when I try to enter MongoDB shell by typing mongo
I get the following error: 但是,当我尝试通过键入mongo
进入MongoDB shell时,出现以下错误:
sumeet@sumeet-acer:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Fri Jun 12 14:01:59 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
By default, mongod
and mongos
use the 27017 port . 默认情况下, mongod
和mongos
使用27017 port 。 Without any option, the client will try to connect to a server running on localhost and listening at that port. 如果没有任何选择,客户端将尝试连接到在localhost上运行并在该端口上侦听的服务器。
A few general advices here: 这里有一些一般建议:
mongod
server is really running ( ps -edf | grep mongod
); 检查mongod
服务器是否真的在运行( ps -edf | grep mongod
); nmap localhost -p0-65535
or netstat | grep 27017
); 检查它是否使用默认端口(在配置文件1中查找,或使用nmap localhost -p0-65535
或netstat | grep 27017
); mongod
is not running, check in the log 2 for clues about what goes wrong. 如果mongod
不在运行,请在日志2中检查出哪里出错的线索。 /etc/mongodb.conf
(on Debian-like systems at least)
1 /etc/mongodb.conf
(至少在类似Debian的系统上)
/var/log/mongodb
(on Debian-like systems at least)
2 /var/log/mongodb
(至少在类似Debian的系统上)
The default IP and Port for MongoDB is 127.0.0.1 & 27017. MongoDB的默认IP和端口是127.0.0.1和27017。
If you are using config file for specifying settings than re-verify IP & Port mentioned in it. 如果您正在使用配置文件指定设置,然后重新验证其中提到的IP和端口。
If you are going with default option than mongod should function as expected. 如果要使用默认选项,则mongod应该可以按预期运行。
try mongo 127.0.0.1:27017 尝试mongo 127.0.0.1:27017
this worked for me For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock 对于在Ubuntu 12.10上运行的MongoDB 2.2.2而言,它在/var/lib/mongodb/mongod.lock中
and after that running the repair command 然后运行修复命令
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
courtesy: https://stackoverflow.com/a/13700262/4907105 礼貌: https : //stackoverflow.com/a/13700262/4907105
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.