Mongodb 服务无法启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18524925/
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
Mongodb service won't start
提问by RussellHarrower
I am not sure why, and the service was working fine just yesterday, all of a sudden I can not get MongoDB to start up.
我不知道为什么,昨天该服务运行良好,突然间我无法启动 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]
I looked in /var/log/mongo/mongod.log and the following:
我查看了 /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
How should I go about fixing this as restarting the server, and service does not seem to work.
我应该如何在重新启动服务器时解决此问题,并且服务似乎不起作用。
ERROR after repair
修复后报错
Not sure what to do it is saying something about error couldn't open file /var/lib/mongo/local.nsterminating
不知道该怎么做是说一些关于错误无法打开文件/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
回答by RussellHarrower
After running the repair I was able to start the mongod proccessor but as root, which meant that service mongod start
would not work. To repair this issue, I needed to make sure that all the files inside the database folder were owned and grouped to mongod. I did this by the following:
运行修复后,我能够以 root 身份启动 mongod proccessor,这意味着这service mongod start
不起作用。为了修复这个问题,我需要确保数据库文件夹中的所有文件都属于 mongod 并归类到 mongod。我通过以下方式做到了这一点:
- Check the file permissions inside your database folder
- note you need to be in your dbpath folder mine was
/var/lib/mongo
I went tocd /var/lib
- I ran
ls -l mongo
- note you need to be in your dbpath folder mine was
- This showed me that databases were owned by root, which is wrong. I ran the following to fix this:
chown -R mongod:mongod mongo
. This changed the owner and group of every file in the folder to mongod. (If using the mongodb package,chown -R mongodb:mongodb mongodb
)
- 检查数据库文件夹中的文件权限
- 请注意,您需要在
/var/lib/mongo
我去过的dbpath 文件夹 中cd /var/lib
- 我跑了
ls -l mongo
- 请注意,您需要在
- 这告诉我数据库归 root 所有,这是错误的。我跑到下面来解决这个问题:
chown -R mongod:mongod mongo
。这将文件夹中每个文件的所有者和组更改为 mongod。(如果使用 mongodb 包,chown -R mongodb:mongodb mongodb
)
I hope this helps someone else in the future.
我希望这会在将来对其他人有所帮助。
回答by openNecati
I solved this by executing C:\mongodb\bin\mongod.exe --repair
first. Then when I ran MongoDB again by C:\mongodb\bin\mongod.exe
, it successfully started.
我通过C:\mongodb\bin\mongod.exe --repair
首先执行解决了这个问题。然后当我再次运行 MongoDB 时C:\mongodb\bin\mongod.exe
,它成功启动。
回答by Dineshaws
I solved this by deleting d:\test\mongodb\data\mongod.lock file. When you will reconnect mongo db than this file will auto generate in same folder. it works for me.
我通过删除 d:\test\mongodb\data\mongod.lock 文件解决了这个问题。当您重新连接 mongo db 时,此文件将在同一文件夹中自动生成。这个对我有用。
回答by user3704779
For me, the reason for not starting turned out to be an orphaned lock file at /var/lib/mongo/mongo.lock When I deleted that file, mongo would then start up OK. My system had had some messy crashes prior to this. [Fedora 14]
对我来说,未启动的原因原来是 /var/lib/mongo/mongo.lock 中的孤立锁定文件。当我删除该文件时,mongo 将正常启动。在此之前,我的系统发生了一些混乱的崩溃。[Fedora 14]
回答by user3704779
it probably might be due to the mongod.lock file, but if the error persists even after deleting it check the paths in mongo.conf; it might be a simple issue such as the configured log Path or dbPath is not there (check the paths in mongo/conf/mongod.conf and check whether they exists, sometimes mongo cannot in its own create directory structures therefore you might have to create those directories manually before starting mongod).
这可能是由于 mongod.lock 文件,但如果即使删除它后错误仍然存在,请检查 mongo.conf 中的路径;这可能是一个简单的问题,例如配置的日志路径或 dbPath 不存在(检查 mongo/conf/mongod.conf 中的路径并检查它们是否存在,有时 mongo 无法在其自己的创建目录结构中,因此您可能必须创建在启动 mongod 之前手动创建这些目录)。
回答by Roman Pekar
It's all in your error message - seems like unclean shutdown was detected. See http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/for detailed information.
这一切都在您的错误消息中 - 似乎检测到不正常关机。有关详细信息,请参阅http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/。
In my expirience, usually it helps to run mongod.exe
with --repair
option ro repair DB.
在我的经验中,通常mongod.exe
使用--repair
选项 ro repair DB运行会有所帮助。
回答by 4levels
I verified permissions but all was good (mongod:mongod). As I'm working on a large project and from a similar issue in our dev environment where we had a script consuming all available disk space, I could see in the error messages that mongod needs at least 3.7Gb free disk space to run..
我验证了权限,但一切都很好(mongod:mongod)。由于我正在处理一个大型项目,并且在我们的开发环境中遇到类似问题,我们的脚本占用了所有可用磁盘空间,我可以在错误消息中看到 mongod 至少需要 3.7Gb 可用磁盘空间才能运行..
I checked my own disk space only to see that less than 2Gb was remaining. After moving / erasing some data I can successfully start mongod again.
我检查了自己的磁盘空间,结果发现剩余空间不足 2Gb。移动/擦除一些数据后,我可以再次成功启动 mongod。
Hope this helps ;-)
希望这可以帮助 ;-)
回答by Jordan Lapp
I tried deleting the lock file, but the real reason that this happened to me was because I was using ~/data/db as the data directory. Mongo needs an absolute path to the database. Once I changed it to /home//data/db, I was in business.
我尝试删除锁定文件,但发生在我身上的真正原因是因为我使用 ~/data/db 作为数据目录。Mongo 需要数据库的绝对路径。一旦我将其更改为 /home//data/db,我就开始工作了。
回答by Jesse
I can't upvote/comment yet, but +1 for manually removing the lock file haha.
我还不能投票/评论,但是 +1 手动删除锁定文件哈哈。
My C9 workspace crashed on me and triggered an unexpected shutdown. The API advises: https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/
我的 C9 工作区在我身上崩溃并触发了意外关机。API 建议:https: //docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/
.. but removing data/mongo.lock worked for me :).
.. 但删除 data/mongo.lock 对我有用:)。
Also, just in case you're getting a connection refusal (which happened to me), running the repair command before removing the lock file could solve your problem (it did mine).
此外,以防万一您收到连接拒绝(这发生在我身上),在删除锁定文件之前运行修复命令可以解决您的问题(它确实解决了我的问题)。
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
须藤-u mongodb mongod --repair --dbpath /var/lib/mongodb/
回答by Peter Hedberg
When I ran mongod.exe from Windows Terminal I got a message Unrecognized option: mp
. There was an empty mp:
in the end of mongod.cfg
. Removing that solved the problem for me.
当我从 Windows 终端运行 mongod.exe 时,我收到一条消息Unrecognized option: mp
。mp:
结尾有空mongod.cfg
。删除它为我解决了问题。