mongodb在意外关闭后崩溃 [英] mongodb crashes after unexpected shutdown

查看:74
本文介绍了mongodb在意外关闭后崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的vps崩溃并启动后,mongod服务没有自动启动,我们无法通过service mongod start启动它, 文件/var/log/mongo/mongod.log包含以下日志:

after our vps got down and we boot it, mongod service didnt start automatically and we cannot start it by service mongod start, file /var/log/mongo/mongod.log contains following log:

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


Thu Oct 11 13:51:18 
Thu Oct 11 13:51:18 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 11 13:51:18 
Thu Oct 11 13:51:18 [initandlisten] MongoDB starting : pid=3821 port=27017 dbpath=/var/lib/mongo 32-bit host=server2.paransa.org
Thu Oct 11 13:51:18 [initandlisten] 
Thu Oct 11 13:51:18 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 11 13:51:18 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 11 13:51:18 [initandlisten] **       with --journal, the limit is lower
Thu Oct 11 13:51:18 [initandlisten] 
Thu Oct 11 13:51:18 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Thu Oct 11 13:51:18 [initandlisten] 
Thu Oct 11 13:51:18 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Oct 11 13:51:18 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Oct 11 13:51:18 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Oct 11 13:51:18 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" }
Thu Oct 11 13:51:18 [initandlisten] couldn't open /var/lib/mongo/mydb_main.ns errno:13 Permission denied
Thu Oct 11 13:51:18 [initandlisten] error couldn't open file /var/lib/mongo/mydb_main.ns terminating
Thu Oct 11 13:51:18 dbexit: 
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to close listening sockets...
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to flush diaglog...
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to close sockets...
Thu Oct 11 13:51:18 [initandlisten] shutdown: waiting for fs preallocator...
Thu Oct 11 13:51:18 [initandlisten] shutdown: closing all files...
Thu Oct 11 13:51:18 [initandlisten] closeAllFiles() finished
Thu Oct 11 13:51:18 [initandlisten] shutdown: removing fs lock...
Thu Oct 11 13:51:18 dbexit: really exiting now

如您所见,日志显示mongo服务器无法打开* .ns文件,导致许可湖

as you may see, log says mongo server cant open *.ns file cause lake of permission

但是如果我通过以下命令手动运行服务器:

but if i run the server manually by following command:

mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf

似乎一切正常,关于日志文件:

it seems everything is fine and about the log file:

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


Thu Oct 11 14:02:06 
Thu Oct 11 14:02:06 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 11 14:02:06 
Thu Oct 11 14:02:06 [initandlisten] MongoDB starting : pid=4090 port=27017 dbpath=/var/lib/mongo 32-bit host=server2.paransa.org
Thu Oct 11 14:02:06 [initandlisten] 
Thu Oct 11 14:02:06 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 11 14:02:06 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 11 14:02:06 [initandlisten] **       with --journal, the limit is lower
Thu Oct 11 14:02:06 [initandlisten] 
Thu Oct 11 14:02:06 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Thu Oct 11 14:02:06 [initandlisten] 
Thu Oct 11 14:02:06 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Oct 11 14:02:06 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Oct 11 14:02:06 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Oct 11 14:02:06 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" }
Thu Oct 11 14:02:07 [websvr] admin web console waiting for connections on port 28017
Thu Oct 11 14:02:07 [initandlisten] waiting for connections on port 27017

并使用--repair arg并没有帮助 (也许是因为它可以用mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf手动启动,并在命令中添加--repair arg,所以可以很好地记录一切!...)

and using --repair arg didnt help (maybe because it could start manually with mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf and adding --repair arg to the command, logs everything is fine!...)

有什么建议吗?

推荐答案

这是一个权限问题,通过服务启动时,您以mongod(或mongodb等)用户身份运行,并且可能以root用户身份运行(您当您使用sudo或以root身份调用时,请在上面的注释中确认这一点.您需要修复该文件夹中所有文件的权限,而永远不要以root用户身份启动服务.

This is a permissions issue, you are running as mongod (or mongodb etc.) user when you start via service, and you are likely running as root (you confirm this in the comments above) when you are using sudo or invoking as root. You need to fix the permissions for all the files in that folder and not start the service as root, ever.

要基于发布的内容修复文件,假设您的相关用户是mongodb,而该组是mongodb,则可以使用sudo(或以root身份)执行以下操作-替换系统的适当用户:

To fix the files based on what you have posted, assuming your relevant user is mongodb and the group is mongodb, you would do the following with sudo (or as root) - substitute for the appropriate user for your system:

chown -R mongodb:mongodb /var/lib/mongo
chown -R mongodb:mongodb /var/run/mongodb
chown mongodb:mongodb /var/log/mongo/mongod.log

一旦您修复了这些文件夹的权限,您就应该能够通过服务再次启动.注意:如果您发布ls -al /var/lib/mongo的输出,那么我可以为您提供运行所需的确切命令

Once you fix the permissions on these folders you should be able to start via service again. Note: if you post the output of ls -al /var/lib/mongo then I can give you the exact commands you need to run

这篇关于mongodb在意外关闭后崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆