34

我不知道为什么,昨天服务运行良好,突然我无法启动 MongoDB。

[root@purr ~]# service mongod start
Starting mongod: Thu Aug 29 23:26:07.550 
Thu Aug 29 23:26:07.550 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Aug 29 23:26:07.550 
about to fork child process, waiting until server is ready for connections.
forked process: 5078
all output going to: /var/log/mongo/mongod.log
ERROR: child process failed, exited with error number 100
                                                           [FAILED]

我查看了 /var/log/mongo/mongod.log 和以下内容:

***** SERVER RESTARTED *****


Thu Aug 29 23:29:05.874 [initandlisten] MongoDB starting : pid=5118 port=27017 dbpath=/var/lib/mongo 32-bit host=purr.ipetfindr.com
Thu Aug 29 23:29:05.874 [initandlisten]
Thu Aug 29 23:29:05.874 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Thu Aug 29 23:29:05.874 [initandlisten] **   32 bit builds are limited to less than 2GB of data (or less with --journal).
Thu Aug 29 23:29:05.874 [initandlisten] **   Note that journaling defaults to off for 32 bit and is currently off.
Thu Aug 29 23:29:05.874 [initandlisten] **   See http://dochub.mongodb.org/core/32bit
Thu Aug 29 23:29:05.874 [initandlisten]
Thu Aug 29 23:29:05.874 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Thu Aug 29 23:29:05.875 [initandlisten]
Thu Aug 29 23:29:05.875 [initandlisten] db version v2.4.6
Thu Aug 29 23:29:05.875 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Thu Aug 29 23:29:05.875 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Aug 29 23:29:05.875 [initandlisten] allocator: system
Thu Aug 29 23:29:05.875 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidf$
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Thu Aug 29 23:29:05.875 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Thu Aug 29 23:29:05.875 dbexit:
Thu Aug 29 23:29:05.875 [initandlisten] shutdown: going to close listening sockets...
Thu Aug 29 23:29:05.875 [initandlisten] shutdown: going to flush diaglog...
Thu Aug 29 23:29:05.875 [initandlisten] shutdown: going to close sockets...
Thu Aug 29 23:29:05.875 [initandlisten] shutdown: waiting for fs preallocator...
Thu Aug 29 23:29:05.875 [initandlisten] shutdown: closing all files...
Thu Aug 29 23:29:05.875 [initandlisten] closeAllFiles() finished
Thu Aug 29 23:29:05.875 dbexit: really exiting now

我应该如何解决这个问题,重新启动服务器,服务似乎不起作用。

修复后的错误

不知道该怎么做是说关于错误无法打开文件/var/lib/mongo/local.ns终止

***** SERVER RESTARTED *****


Fri Aug 30 04:49:43.041 [initandlisten] MongoDB starting : pid=3300 port=27017 dbpath=/var/lib/mongo 32-bit host=purr.ipetfindr.com
Fri Aug 30 04:49:43.041 [initandlisten]
Fri Aug 30 04:49:43.041 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Fri Aug 30 04:49:43.041 [initandlisten] **   32 bit builds are limited to less than 2GB of data (or less with --journal).
Fri Aug 30 04:49:43.041 [initandlisten] **   Note that journaling defaults to off for 32 bit and is currently off.
Fri Aug 30 04:49:43.041 [initandlisten] **   See http://dochub.mongodb.org/core/32bit
Fri Aug 30 04:49:43.041 [initandlisten]
Fri Aug 30 04:49:43.041 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Fri Aug 30 04:49:43.041 [initandlisten]
Fri Aug 30 04:49:43.041 [initandlisten] db version v2.4.6
Fri Aug 30 04:49:43.041 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Fri Aug 30 04:49:43.041 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Fri Aug 30 04:49:43.041 [initandlisten] allocator: system
Fri Aug 30 04:49:43.041 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidf$
Fri Aug 30 04:49:43.058 [initandlisten] couldn't open /var/lib/mongo/local.ns errno:13 Permission denied
Fri Aug 30 04:49:43.058 [initandlisten] error couldn't open file /var/lib/mongo/local.ns terminating
Fri Aug 30 04:49:43.059 dbexit:
Fri Aug 30 04:49:43.059 [initandlisten] shutdown: going to close listening sockets...
Fri Aug 30 04:49:43.059 [initandlisten] shutdown: going to flush diaglog...
Fri Aug 30 04:49:43.059 [initandlisten] shutdown: going to close sockets...
Fri Aug 30 04:49:43.059 [initandlisten] shutdown: waiting for fs preallocator...
Fri Aug 30 04:49:43.059 [initandlisten] shutdown: closing all files...
Fri Aug 30 04:49:43.059 [initandlisten] closeAllFiles() finished
Fri Aug 30 04:49:43.059 [initandlisten] shutdown: removing fs lock...
Fri Aug 30 04:49:43.059 dbexit: really exiting now
4

12 回答 12

48

运行修复后,我能够以 root 身份启动 mongod 处理器,这意味着这service mongod start不起作用。要修复这个问题,我需要确保数据库文件夹中的所有文件都归 mongod 所有并分组。我通过以下方式做到了这一点:

  1. 检查数据库文件夹中的文件权限
    1. 请注意,您需要在我的 dbpath 文件夹 /var/lib/mongocd /var/lib
    2. 我跑了ls -l mongo
  2. 这向我表明数据库归 root 所有,这是错误的。我运行以下命令来解决这个问题:chown -R mongod:mongod mongo。这将文件夹中每个文件的所有者和组更改为 mongod。(如果使用 mongodb 包,chown -R mongodb:mongodb mongodb

我希望这对将来的其他人有所帮助。

于 2013-08-30T10:15:16.887 回答
14

我通过C:\mongodb\bin\mongod.exe --repair先执行解决了这个问题。然后当我再次运行 MongoDB 时C:\mongodb\bin\mongod.exe,它成功启动了。

于 2014-02-15T01:40:16.837 回答
11

我通过删除 d:\test\mongodb\data\mongod.lock 文件解决了这个问题。当您重新连接 mongo db 时,此文件将自动生成在同一文件夹中。这个对我有用。

于 2014-09-18T10:22:08.530 回答
3

对我来说,没有启动的原因原来是 /var/lib/mongo/mongo.lock 中的孤立锁文件当我删除该文件时,mongo 会启动正常。在此之前,我的系统发生了一些混乱的崩溃。[Fedora 14]

于 2014-06-03T21:15:33.860 回答
3

这可能是由于 mongod.lock 文件,但如果即使删除后错误仍然存​​在,请检查 mongo.conf 中的路径;这可能是一个简单的问题,例如配置的日志路径或 dbPath 不存在(检查 mongo/conf/mongod.conf 中的路径并检查它们是否存在,有时 mongo 无法在自己的目录结构中创建,因此您可能必须创建这些目录在启动 mongod 之前手动)。

于 2016-12-29T10:52:48.550 回答
1

这一切都在您的错误消息中 - 似乎检测到不干净的关机。有关详细信息,请参阅http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/

mongod.exe根据我的经验,通常使用--repair选项 ro repair DB运行会有所帮助。

于 2013-08-30T04:53:15.350 回答
1

我验证了权限,但一切都很好(mongod:mongod)。由于我正在处理一个大型项目,并且在我们的开发环境中有一个类似的问题,我们有一个消耗所有可用磁盘空间的脚本,我可以在错误消息中看到 mongod 需要至少 3.7Gb 可用磁盘空间才能运行..

我检查了自己的磁盘空间,发现剩余的空间不足 2Gb。移动/擦除一些数据后,我可以再次成功启动 mongod。

希望这可以帮助 ;-)

于 2014-06-12T13:00:17.770 回答
1

我尝试删除锁定文件,但发生这种情况的真正原因是因为我使用 ~/data/db 作为数据目录。Mongo 需要数据库的绝对路径。一旦我将其更改为 /home//data/db,我就开始做生意了。

于 2016-05-13T16:20:22.093 回答
0

删除 C:\mongodb\data\ 路径下的 .lock 文件,然后重启 mongodb 服务。

于 2016-02-17T18:59:40.280 回答
0

我还不能投票/评论,但是 +1 用于手动删除锁定文件哈哈。

我的 C9 工作区在我身上崩溃并触发了意外关机。API 建议: https ://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/

..但删除 data/mongo.lock 对我有用:)。

此外,以防万一您遇到拒绝连接(这发生在我身上),在删除锁定文件之前运行修复命令可以解决您的问题(它确实是我的)。

sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/

于 2017-06-09T23:17:34.923 回答
0

当我从 Windows 终端运行 mongod.exe 时,我收到一条消息Unrecognized option: mpmp:结尾处是空的mongod.cfg。删除它为我解决了问题。

于 2019-05-09T14:33:20.857 回答
0

在我的情况下,每当我的本地系统在没有停止 MongoDB 服务器的情况下关闭时,它也会显示一些锁定问题。

但它只能通过使用 sudo 命令工作: -

$ sudo mongod --port 27017

于 2020-09-19T09:10:47.737 回答