简体   繁体   English

在Cloud 9上连接到mongodb时出错

[英]Error connecting to mongodb on Cloud 9

I try to connect to mongodb based on the instructions provided here ,I get this error instead: 我尝试根据此处提供的说明连接到mongodb,而是出现此错误:

    vamsiampolu1@takenote:~/workspace (master) $ ./mongod
2014-11-17T09:00:10.101+0000 ** WARNING: --rest is specified without --httpinterface,
2014-11-17T09:00:10.101+0000 **          enabling http interface
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
2014-11-17T09:00:10.106+0000 [initandlisten] MongoDB starting : pid=2274 port=27017 dbpath=data 64-bit host=vamsiampolu1-takenote-1084968
2014-11-17T09:00:10.106+0000 [initandlisten] db version v2.6.5
2014-11-17T09:00:10.106+0000 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-17T09:00:10.106+0000 [initandlisten] build info: Linux build8.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-11-17T09:00:10.106+0000 [initandlisten] allocator: tcmalloc
2014-11-17T09:00:10.107+0000 [initandlisten] options: { net: { bindIp: "0.0.0.0", http: { RESTInterfaceEnabled: true, enabled: true } }, storage: { dbPath: "data", journal: { enabled: false } } }
************** 
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
2014-11-17T09:00:10.107+0000 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
2014-11-17T09:00:10.107+0000 [initandlisten] dbexit: 
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: going to close listening sockets...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: going to flush diaglog...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: going to close sockets...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: waiting for fs preallocator...
2014-11-17T09:00:10.107+0000 [initandlisten] shutdown: closing all files...
2014-11-17T09:00:10.107+0000 [initandlisten] closeAllFiles() finished
2014-11-17T09:00:10.107+0000 [initandlisten] dbexit: really exiting now

EDIT: 编辑:

I have tried with the mongod --repair flag.I have also tried to execute this script,which is what I do in case I shut my local machine down without closing mongod properly: 我尝试了mongod --repair标志。我还尝试执行此脚本,以防万一我关闭本地计算机而未正确关闭mongod

   #!/bin/sh
  sudo rm /var/lib/mongodb/mongod.lock
  sudo -u mongodb mongod -f /etc/mongodb.conf --repair
  sudo service mongodb start

It says that the file /var/lib/mongodb/mongod.lock was not found.I have tried to start mongodb as a service: 它说找不到文件/var/lib/mongodb/mongod.lock我试图将mongodb作为服务启动:

  sudo service mongod start

wherein,it asks me to use mongod start which also fails with the same message.I have read about net.http.enabled which should be left switched off because it could increase network exposure. 其中,它要求我使用mongod start也将失败,并同样message.I看了一下net.http.enabled应留待关掉,因为它会增加网络的曝光。

I used a Ubuntu 12.04 based vagrant box once,so I tried with: 我曾经使用过基于Ubuntu 12.04vagrant盒子,所以尝试了以下方法:

 mongodb start

which tells me that mongodb is not a valid command. 这告诉我mongodb不是有效的命令。

I have also tried mongo which tells me that: 我也尝试过mongo ,它告诉我:

 vamsiampolu1@takenote:~/workspace (master) $ mongo
 MongoDB shell version: 2.6.5
 connecting to: test
 2014-11-17T11:51:44.752+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111     Connection refused
 2014-11-17T11:51:44.753+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1),   connection attempt failed at src/mongo/shell/mongo.js:146
 exception: connect failed

I believed that I might have mistakenly closed the terminal window running mongod and thus am unable to start it.But it wont let me do what I usually do and continue working. 我相信我可能错误地关闭了运行mongod的终端窗口,因此无法启动它。但是它无法让我做我通常做的事情并继续工作。

I have also tried to run this to find if mongod was already running: 我还尝试运行此命令以查找mongod是否已在运行:

  vamsiampolu1@takenote:~/workspace (master) $ ps ax | grep mongod
  2504 pts/2    S+     0:00 grep --color=auto mongod 

I tried to stop it from running using the following: 我尝试使用以下命令阻止其运行:

   stop mongod

Then I ran that again to find if mongod was still running: 然后我再次运行该命令以查看mongod是否仍在运行:

   vamsiampolu1@takenote:~/workspace (master) $ ps ax | grep mongod
   2524 pts/2    S+     0:00 grep --color=auto mongod

When I tried to run this: 当我尝试运行此命令时:

      vamsiampolu1@takenote:~/workspace (master) $ mongod --shutdown
      There doesn't seem to be a server running with dbpath: /data/db

When I tried to set the dbpath manually: 当我尝试手动设置dbpath

  vamsiampolu1@takenote:~/workspace (master) $ ./mongod --dbpath /data/db
  Error parsing command line:  Multiple occurrences of option "--dbpath"

It looks to me like you have done a lot of things criss cross without really understanding what you are doing. 在我看来,您做了很多纵横交错的工作,却没有真正了解自己在做什么。

But basic understanding is necessary . 但是基本的了解是必要的 So, here is a step by step guide to sanitize the environment and hopefully repair the database, annotated. 因此,这是一步一步的指南,用于清理环境并有望修复带注释的数据库。 You do have a backup, don't you? 有一个备份,不是吗?

  1. Decide wether you want to use mongod as your own user vamsiampolu1 or root or a dedicated user. 确定是否要将mongod用作您自己的用户vamsiampolu1或root或专用用户。 Contrary to popular belief, the sudo command is not the Linux/UNIX equivalent of "I really want you to execute this command!" 与普遍的看法相反, sudo命令与Linux / UNIX上的“我真的希望您执行此命令!”等效。 and a foot stomp. 和脚踩。 The sudo without the -u parameter executes it's parameters with root privileges – the effective user id of the process will be root's. 不带-u参数的sudo将以root特权执行其参数-进程的有效用户ID将是root的。 Files and directories will be created for the user and group root (except the process in questions drops root privileges). 将为用户和组root创建文件和目录(除非所涉及的过程删除了root特权)。 Usually, it is best to have a dedicated user for any daemon, so you should use mongodb as this is the user created by the ubuntu and 10gen packages. 通常,最好有一个专用于任何守护程序的用户,因此应使用mongodb,因为这是ubuntu和10gen软件包创建的用户。

  2. Now we need to make sure that there is no mongod running: 现在我们需要确保没有mongod在运行:

     vamsiampolu1@takenote:~ $ sudo killall mongod 

    (We want to kill all mongod processes, and since the only user capable of killing processes which might belong to a different user than himself is root, we tell the system to execute this command with root privileges) (我们想杀死所有mongod进程,并且由于唯一能够杀死可能与他本人不同的用户进程的用户是root,所以我们告诉系统以root特权执行此命令)

  3. We make sure that all the files and directories belong to the proper user 我们确保所有文件和目录都属于正确的用户

     vamsiampolu1@takenote:~ $ sudo chown mongodb.mongodb -r /var/lib/mongodb 

    (We want to change the owner and the group of all directories below /var/lib/mongodb recursively to user mongodb and group mongodb and we need the according privileges to do so) (我们要递归将/ var / lib / mongodb下所有目录的所有者和组更改为用户mongodb和组mongodb,我们需要相应的特权)

  4. We remove the lockfile as user mongodb 我们以用户mongodb的形式删除锁定文件

     vamsiampolu1@takenote:~ $ sudo -u mongodb rm /var/lib/mongodb/mongod.lock 
  5. Next, we will run the repair command as user mongodb 接下来,我们将以mongodb用户身份运行repair命令

     vamsiampolu1@takenote:~ $ sudo -u mongodb mongod -f /etc/mongod.conf --repair 

    Note that the -u mongodb is crucial for your system to work properly after the repair. 请注意, -u mongodb对于修复后系统正常运行至关重要。

    This might take a while. 这可能需要一段时间。 Watch the log file carefully with 仔细观察日志文件

      vamsiampolu1@takenote:~ $ tail -n 100 -f /var/log/mongodb/mongod.log 

    If it says [initandlisten] dbexit: really exiting now , then … 如果它说[initandlisten] dbexit: really exiting now ,那么……

  6. Start mongod with 从开始mongod

     vamsiampolu1@takenote:~ $ sudo -u mongodb mongod -f /etc/mongod.conf 

    It should work now. 现在应该可以工作了。 If not please add the part of the log file from the last occurrence of 如果不是,请从最近一次出现的日志文件中添加该部分

     [initandlisten] repairDatabase local 

    all the way to the end to your question. 一直到您的问题的结尾。

If you have setup mongodb according to this method, go to the data folder in your directory. 如果您已经按照方法设置了mongodb,请转到目录中的data文件夹。 Inside it there is a file mongod.lock. 在其中有一个文件mongod.lock。 Delete it (you wont require root privileges) just use rm mongod.lock . 删除它(您不需要root特权),只需使用rm mongod.lock Come back to main directory and enter ./mongod . 返回主目录并输入./mongod hope this will solve the p 希望这能解决问题

Personally, I have experienced this and I found a quick fix which retains all your data as well. 就个人而言,我已经经历了这一点,并且发现了一个快速修复程序,该修复程序还保留了您的所有数据。 I am a new developer and my answer will work for you if you are coding on cloud9 and using mongoDB. 我是一名new developer ,如果您在cloud9上进行编码并使用mongoDB,那么我的答案将对您有用。

Step 1: Navigate to the directory where you installed mongoDB in your terminal, you will find the file mongod* You can navigate to this directory using $ cd ~ 第1步:导航到终端中安装mongoDB的目录,您将找到文件mongod*可以使用$ cd ~ cd〜导航至该目录。

Step 2: cd into the data directory $ cd data/ 步骤2:cd进入数据目录$ cd data/

Step 3: View all files and folders in this directory ls . 步骤3:查看目录ls所有文件和文件夹。 You will find a file mongod.lock* . 您会找到一个文件mongod.lock*

Step 4: Delete this file using $ rm mongod.lock NB: DO NOT INCLUDE * 步骤4:使用$ rm mongod.lock删除此文件注意:请勿包含*

Step 5: cd back to the root directory $ cd ~ and startup mongo as usual ./mongod with all your data safe. 步骤5:cd返回根目录$ cd ~ ./mongod并像往常一样启动./mongod ,所有数据都安全。

Goodluck. 祝好运。

For free users of Cloud9 it is caused due to lack of space, because you only have 2GB available and MongoDB requires a large amount. 对于Cloud9的免费用户,这是由于空间不足而引起的,因为您只有2GB的可用空间,而MongoDB则需要大量空间。

Here is a solution: 这是一个解决方案:

mongod --port 27017 --smallfiles

Note: you may lose some of your files 注意:您可能会丢失一些文件

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM