Linux 无法连接到服务器 127.0.0.1 shell/mongo.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5726032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
couldn't connect to server 127.0.0.1 shell/mongo.js
提问by zjm1126
when i setup mongodb in my ubuntu , i try : ./mongo it show this error :
当我在 ubuntu 中设置 mongodb 时,我尝试:./mongo 它显示此错误:
couldn't connect to server 127.0.0.1 shell/mongo.js
so what can i do ,
那我能怎么办
thanks
谢谢
回答by Andreas Jung
Either your mongod is not running (check using "ps" command) or it is listening on some outside IP address and not on localhost. So first check the process list if 'mongod' is running. If yes, check with "netstat -nap" for the related port.
要么您的 mongod 未运行(使用“ps”命令检查),要么正在侦听某个外部 IP 地址而不是本地主机。因此,如果“mongod”正在运行,请首先检查进程列表。如果是,请检查相关端口的“netstat -nap”。
Of course you can start mongod on the console manually or even look into the mongod logfile (if there is one configured...depending on how you installed mongod).
当然,您可以在控制台上手动启动 mongod,甚至可以查看 mongod 日志文件(如果配置了……取决于您安装 mongod 的方式)。
回答by fady mohamed osman
- Manually remove the lockfile:
sudo rm /var/lib/mongodb/mongod.lock
- Run the repair script:
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
- 手动删除锁定文件:
sudo rm /var/lib/mongodb/mongod.lock
- 运行修复脚本:
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.
- 您必须以 mongodb 用户身份运行此命令。如果您以 root 身份运行它,那么 root 将拥有 /var/lib/mongodb/ 中运行 mongodb 守护进程所必需的文件,因此当守护进程稍后尝试以 mongodb 用户身份运行时,它将没有启动权限. 在这种情况下,您将收到此错误:无法为锁文件路径创建/打开锁文件:/var/lib/mongodb/mongod.lock errno:13 Permission denied,terminating。
- 在 Ubuntu 上,您必须使用 -f 标志指定配置文件 /etc/mongodb.conf。否则它将在错误的位置查找数据文件,您将看到以下错误:dbpath (/data/db/) 不存在,正在终止。
回答by Jmlevick
This is actually not an error... What happens here is that Mongo relies on a daemonin order to run the local database server, so in order to "fire up" the mongo serverin your shell, you have to start the mongo servicefirst.
这实际上不是错误......这里发生的事情是 Mongo 依赖一个守护进程来运行本地数据库服务器,所以为了在你的 shell 中“启动” mongo 服务器,你必须启动mongo 服务第一的。
For Fedora Linux(wich is the Distro I use) You have to run these commands:
对于Fedora Linux(这是我使用的发行版),您必须运行以下命令:
1 sudo service mongod start
2 mongo
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:
你有它!服务器将要运行。现在,如果您希望 Mongo 服务在系统启动时启动,那么您必须运行:
sudo chkconfig --levels 235 mongod on
And that's all! If you do that, now in the shell you just have to type mongoin 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 :)
就这样!如果你这样做,现在在 shell 中你只需要输入mongo来启动服务器,但差不多就是这样,问题是你必须先启动 SERVICE,然后是 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 wordsdepending on the distro you're using ;)
PS命令我张贴在其他Linux发行版可能工作为好,不只是在Fedora的......如果不是也许你不得不调整一些的话这取决于你使用的发行版;)
回答by user1391225
You need to delete the lockfile mongod.lock
or /var/lib/mongodb/mongod.lock
on ubuntu, then you need to run mongod.exe
or service mongodb start
on ubuntu first, then run mongo.exe
or mongo
on ubuntu.
需要在ubuntu上mongod.lock
或/var/lib/mongodb/mongod.lock
ubuntu上删除lockfile ,然后需要先在ubuntu上运行mongod.exe
or service mongodb start
,再在ubuntu上运行mongo.exe
or mongo
。
回答by boulder_ruby
Trying running $mongod
尝试运行 $mongod
If you get en error 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 error that is pretty common.
然后你遇到了一个很常见的基本启动错误。
By default mongod will try to use /data/db for its database files, which in this case, does not exist.
默认情况下,mongod 会尝试将 /data/db 用于其数据库文件,在这种情况下,该文件不存在。
You can't start
你无法开始
mongo
until you handle
直到你处理
mongod.
Try creating those directories and make sure they are writable by the same user that is running the mongod process.
尝试创建这些目录并确保它们可由运行 mongod 进程的同一用户写入。
**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
**请参阅类似问题--在尝试在 mac osx lion 上运行 mongodb 时出现错误,“错误:无法连接到服务器 127.0.0.1 shell/mongo.js”
回答by Rubyrider
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 while to start mongo after performing these operations.
这就是全部,有时,在执行这些操作后启动 mongo 需要一些时间。
回答by Victor
On Ubuntu, try this:
在 Ubuntu 上,试试这个:
sudo invoke-rc.d mongodb start
回答by Tom Desair
First you have to make sure that all the files and directories in your /var/lib/mongodb/ folder (or whichever folder dbpath points to) belong to the mongodb user and mongodb group.
首先,您必须确保 /var/lib/mongodb/ 文件夹(或 dbpath 指向的文件夹)中的所有文件和目录都属于 mongodb 用户和 mongodb 组。
cd /var/lib/mongodb/
sudo chown mongodb filename.*
sudo chgrp mongodb filename.*
sudo chown -R mongodb directory
sudo chgrp -R mongodb directory
(Replace filename and directory with their respective names)
(用它们各自的名称替换文件名和目录)
Then you can remove the lock, repair the database and restart the daemon as other people already mentioned:
然后你可以删除锁,修复数据库并重新启动守护进程,正如其他人已经提到的:
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
回答by DmitrySandalov
Also check that your root partition has enough space to start mongod.
还要检查您的根分区是否有足够的空间来启动 mongod。
df -h /
You'll see smth like this on mongod launch:
你会在 mongod 发布时看到这样的:
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...
回答by Tarun Gupta
First start your mongo server by
首先通过以下方式启动您的 mongo 服务器
Users-MacBook-Pro:csv1 Admin$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
Then open another terminal window and open shell
然后打开另一个终端窗口并打开shell
Users-MacBook-Pro:csv1 Admin$ mongo