简体   繁体   English

无法连接到服务器127.0.0.1 shell / mongo.js

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

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 谢谢

  • Manually remove the lockfile: sudo rm /var/lib/mongodb/mongod.lock 手动删除锁定文件: sudo rm /var/lib/mongodb/mongod.lock
  • Run the repair script: sudo -u mongodb mongod -f /etc/mongodb.conf --repair 运行修复脚本: sudo -u mongodb mongod -f /etc/mongodb.conf --repair

Please note the following: 请注意以下事项:

  • You must run this command as the mongodb user. 您必须以mongodb用户身份运行此命令。 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. 如果您以root身份运行,则root将在/ var / lib / mongodb /中拥有运行mongodb守护程序所必需的文件,因此,当该守护程序尝试以mongodb用户身份稍后运行时,它将没有启动权限。 。 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. 在这种情况下,您会收到以下错误消息:无法为lockfilepath创建/打开锁定文件:/var/lib/mongodb/mongod.lock errno:13权限被拒绝,正在终止。
  • On Ubuntu, you must specify the configuration file /etc/mongodb.conf using the -f flag. 在Ubuntu上,必须使用-f标志指定配置文件/etc/mongodb.conf。 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. 否则,它将在错误的位置查找数据文件,并且您将看到以下错误:dbpath(/ data / db /)不存在,正在终止。
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。

Trying running $mongod 尝试运行$ mongod

If you get en error such as 如果出现en错误,例如

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 **看到类似的问题- 收到错误消息“错误:无法连接到服务器127.0.0.1 shell / mongo.js”,并尝试在Mac OS X Lion上运行mongodb

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. 这实际上不是错误……这里发生的是Mongo依靠守护程序来运行本地数据库服务器,因此为了在外壳中“启动” mongo服务器 ,您必须启动mongo服务第一。

For Fedora Linux (wich is the Distro I use) You have to run these commands: 对于Fedora Linux (我使用的是Distro),您必须运行以下命令:

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 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 :) 如果这样做,现在只需在外壳程序中键入mongo即可启动服务器,但这已经足够了,问题在于您必须先启动SERVICE,然后再启动SERVER :)

PS 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 ;) PS我发布的命令可能也可以在其他Linux发行版上使用,而不仅是在fedora中...如果不是,您可能不必根据所使用的发行版来调整一些单词 ;)

I got the same problem when I tried to install mongo. 尝试安装mongo时遇到相同的问题。 I got Error as, 我有错误,

Error 错误

"Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84"

Solution: 解:

First install mongod by using: 首先使用以下命令安装mongod:

sudo apt-get install mongodb-server

Then type 然后输入

mongod --dbpath /mongo/db

Then 然后

sudo rm /var/lib/mongodb/mongod.lock

Then 然后

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

Thank You 谢谢

您需要删除ubuntu上的锁文件mongod.lock/var/lib/mongodb/mongod.lock ,然后需要service mongodb start在ubuntu上运行mongod.exeservice mongodb start ,然后再在ubuntu上运行mongo.exemongo

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

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 然后打开另一个终端窗口并打开外壳

Users-MacBook-Pro:csv1 Admin$ mongo

Either your mongod is not running (check using "ps" command) or it is listening on some outside IP address and not on localhost. 您的mongod不在运行(使用“ ps”命令检查),或者在某个外部IP地址上侦听,而不是在本地主机上侦听。 So first check the process list if 'mongod' is running. 因此,首先检查进程列表是否正在运行“ mongod”。 If yes, check with "netstat -nap" for the related port. 如果是,请使用“ 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的方式)。

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...

在Ubuntu上,尝试以下操作:

sudo invoke-rc.d mongodb start

It could be combination of $PATH and Permission issue. 可能是$ PATH和Permission问题的组合。

Try following steps given below: 请尝试以下步骤:

Update your $PATH variable to point to your MongoDB bin file. 更新$ PATH变量以指向MongoDB bin文件。 In my case brew install MongoDB to this folder: 在我的情况下,将MongoDB安装到此文件夹:

/usr/local/Cellar/mongodb/2.4.6/

In order to update your $PATH variable, do following: 为了更新您的$ PATH变量,请执行以下操作:

$ sudo vi /etc/paths

Then, press 'i' to insert text in Vi and append the your MongoDB path to the end of the 'paths' file and restart the terminal. 然后,按“ i”在Vi中插入文本,并将您的MongoDB路径附加到“路径”文件的末尾,然后重新启动终端。

/usr/local/Cellar/mongodb/2.4.6/bin

Use 'Esc : w q' to save and exit from Vi editor. 使用'Esc:w q'保存并退出Vi编辑器。

Use echo to display your path variable: 使用echo显示路径变量:

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/Cellar/mongodb/2.4.6/bin

Now try to check the Mongo version, if you get following, then you are on the right track! 现在尝试检查Mongo版本,如果您得到关注,那么您就走对了!

$ mongo --version
MongoDB shell version: 2.4.6

Now we need to create the database directory. 现在我们需要创建数据库目录。 I used the default '/data/db' location suggested in MongoDB docs. 我使用了MongoDB文档中建议的默认“ / data / db”位置。 I also created a log directory to avoid any permission issues while Mongo tries to create any logs. 我还创建了一个日志目录,以避免在Mongo尝试创建任何日志时出现任何权限问题。 Change ownership and that will do the job. 更改所有权即可完成工作。

$ sudo mkdir /data/db
$ sudo mkdir /data/log
$ whoami
username
$ chown -R username /data

Now, we will create a default config file for MongoDB to be provided for the first time we run 'mongod' command. 现在,我们将为MongoDB创建一个默认的配置文件,以便在我们首次运行“ mongod”命令时提供。 Now, I will also like to point out that 'mongod' will start a service, which will listen for incoming data connections. 现在,我还要指出,“ mongod”将启动一个服务,该服务将侦听传入的数据连接。 This is similar having '$service mysqld start' executed.Let's go ahead and create the config file. 这与执行'$ service mysqld start'类似。让我们继续创建配置文件。 Please keep in mind that I have created very basic config file. 请记住,我已经创建了非常基本的配置文件。 However, you can add many other variables to configure MongoDB. 但是,您可以添加许多其他变量来配置MongoDB。 This is the first time I am playing with MongoDB, so I just know as much as I read on MongoDB docs!I created 'mongodb.conf'. 这是我第一次玩MongoDB,所以我对MongoDB文档的了解非常了解!我创建了“ mongodb.conf”。

$ sudo vi /etc/mongodb.conf

Add following: 添加以下内容:

fork = true
port = 27017
quiet = true
dbpath = /data/db
logpath = /data/log/mongod.log
logappend = true
journal = true

Please note that the default port for MongoDB server is 27017. Use your own path for dbpath and logpath you created in Step – 5. Don't forget to close and save the conf file. 请注意,MongoDB服务器的默认端口为27017。对于在步骤– 5中创建的dbpath和logpath使用您自己的路径。不要忘记关闭并保存conf文件。

Now we are all set to start our MongoDB service. 现在我们已经准备好启动我们的MongoDB服务。 Open two instances of Terminal.In Terminal 1, type in: 打开Terminal的两个实例。在Terminal 1中,输入:

$ sudo mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3516
all output going to: /data/log/mongod.log
child process started successfully, parent exiting

If you get above message, then know that you have successfully started your Mongod service. 如果您收到上述消息,请知道您已经成功启动了Mongod服务。

Now, to connect to it, in Terminal 2 type following: 现在,要连接到它,请在2号终端中输入以下内容:

$mongo test
MongoDB shell version: 2.4.6
connecting to: test
Server has startup warnings:
Tue Sep 3 16:55:43.527 [initandlisten]
Tue Sep 3 16:55:43.527 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>

Ignore the warnings, but you are successfully connected to the 'test' database! 忽略警告,但您已成功连接到“测试”数据库! Cool! 凉!

That's all. 就这样。 I applied this solution, when I tried to install copy of MongoDB on my Mac for the first time. 第一次尝试在Mac上安装MongoDB副本时,我应用了此解决方案。 See if this help you too. 看看这是否对您也有帮助。

For detailed post you can go here - http://arcanebytes.com/2013/09/03/mongodb-installation-on-mac-os-x/#comment-1036112094 . 有关详细的帖子,请转到此处-http://arcanebytes.com/2013/09/03/mongodb-installation-on-mac-os-x/#comment-1036112094

I hope it helps! 希望对您有所帮助!

Cheers, Chinmay 干杯,下巴

I solved this problem on ubuntu 12.04 by following steps: 我通过以下步骤在ubuntu 12.04上解决了此问题:
1) sudo rm /var/log/mongodb 1)须藤rm / var / log / mongodb
2) sudo rm /var/lib/mongodb 2)须藤rm / var / lib / mongodb
3) I removed mongo and then installed it again 3)我删除了mongo,然后再次安装
4) sudo service mongodb restart 4)sudo服务mongodb重新启动

and All is Well 一切都很好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mongo:无法连接到服务器127.0.0.1:27017 src / mongo / shell / mongo.js:145 - Mongo: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 Errr 'mongo.js:L112 错误:无法连接到服务器 127.0.0.1:27017 在 src/mongo/shell/mongo.js:L112' - Errr 'mongo.js:L112 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112' 错误:无法连接到服务器127.0.0.1:27017 — mongodb - Error: couldn't connect to server 127.0.0.1:27017 — mongodb 适用于Mac的Sequel Pro-MySQL说:无法连接到“ 127.0.0.1”上的MySQL服务器(4) - Sequel Pro for Mac - MySQL said: Can't connect to MySQL server on '127.0.0.1' (4) SQLSTATE [HY000] [2003]无法连接到“ 127.0.0.1”上的MySQL服务器(13) - SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13) 2003:无法连接到'127.0.0.1:3306'上的MySQL服务器(99无法分配请求的地址) - 2003: Can't connect to MySQL server on '127.0.0.1:3306' (99 Cannot assign requested address) 错误 2003 (HY000):无法连接到“127.0.0.1:3306”上的 MySQL 服务器 (111) - ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111) Kubernetes:无法验证 API 服务器的身份:tcp 拨号:连接:协议不可用 - Kubernetes: couldn't validate the identity of the API Server: tcp dial : connect : protocol not available WSDL curl错误7:无法连接到主机 - Wsdl curl error 7: couldn't connect to host 无法从Internet连接到我的家庭Node js服务器 - Can't connect to my home Node js server from Internet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM