mongodb 在意外关闭后崩溃

标签 mongodb

在我们的 vps 关闭并启动它之后,mongod 服务没有自动启动,我们无法通过 service mongod start 启动它, 文件 /var/log/mongo/mongod.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 文件导致权限不足

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

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

似乎一切都很好,关于日志文件:

***** 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,记录一切正常!。 ..)

有什么建议吗?

最佳答案

这是一个权限问题,当您通过服务启动时,您正在以 mongod(或 mongodb 等)用户身份运行,并且当您使用 sudo 或调用作为根。您需要修复该文件夹中所有文件的权限,并且永远不要以 root 用户身份启动服务。

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

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 的输出,那么我可以为您提供您需要运行的确切命令

关于mongodb 在意外关闭后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838459/

相关文章:

mongodb - 如何在服务器中登录 mongodb 控制台

php - php 中的 MongoDB 地理空间查询

javascript - 根据 id 数组字段在 Mongoose 中查找文档

mongodb - 没有 root 无法将 mongod 作为服务运行

javascript - elasticsearch 自动建议返回棘手的 JSON

node.js - Mongo 仅以 ISO_8601 格式存储日期,而不是 unix

mongodb - 限制 mongodb 集合中的文档数量,没有 FIFO 策略

mongodb - Vercel 为每个请求创建新的数据库连接

mongodb - HDP沙箱中MongoDB Hadoop连接器故障产生的Hive日志在哪里?

ruby - 我可以通过 ruby​​ 驱动程序访问 mongo 的 geoNear 功能吗?