【问题标题】:MongoDB unexpected shutdown and data lossMongoDB 意外关闭和数据丢失
【发布时间】:2015-10-06 01:47:05
【问题描述】:

最奇怪的事情发生了。我们有一个 mongodb 实例,日志和日志都在单独的硬盘驱动器上运行,该驱动器运行在由 ebs 支持的单个亚马逊 ec2 上。今天早上服务器意外关闭,当我查看它时,我注意到 mongo 没有在启动时启动。

我使用命令手动启动了 mongo

sudo mongod --fork --logpath /var/log/mongodb.log

它运行良好,但是当我查看数据库时,我们所有的数据都丢失了。我尝试使用 --repair 选项退出,但它什么也没做。这是初始 mongod 的日志的样子:

2015-10-05T16:39:17.881+0000 [initandlisten] MongoDB starting : 

pid=2757 port=27017 dbpath=/data/db 64-bit host=ip-172-31-59-166
2015-10-05T16:39:17.882+0000 [initandlisten] db version v2.6.8
2015-10-05T16:39:17.882+0000 [initandlisten] git version: 3abc04d6d4f71de00b57378e3277def8fd7a6700
2015-10-05T16:39:17.882+0000 [initandlisten] build info: Linux build5.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
2015-10-05T16:39:17.882+0000 [initandlisten] allocator: tcmalloc
2015-10-05T16:39:17.882+0000 [initandlisten] options: { processManagement: { fork: true }, systemLog: { destination: "file", path: "/var/log/mongodb.log" } }
2015-10-05T16:39:17.890+0000 [initandlisten] journal dir=/data/db/journal
2015-10-05T16:39:17.893+0000 [initandlisten] recover : no journal files present, no recovery needed
2015-10-05T16:39:17.893+0000 [initandlisten] preallocating a journal file /data/db/journal/prealloc.1
2015-10-05T16:39:28.081+0000 [initandlisten] preallocating a journal file /data/db/journal/prealloc.2
2015-10-05T16:39:40.496+0000 [initandlisten] allocating new ns file /data/db/local.ns, filling with zeroes...
2015-10-05T16:39:40.654+0000 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...
2015-10-05T16:39:40.654+0000 [FileAllocator] creating directory /data/db/_tmp
2015-10-05T16:39:40.659+0000 [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB,  took 0.002 secs
2015-10-05T16:39:40.664+0000 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2015-10-05T16:39:40.664+0000 [initandlisten]     added index to empty collection
2015-10-05T16:39:40.665+0000 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0  reslen:37 169ms
2015-10-05T16:39:40.669+0000 [initandlisten] waiting for connections on port 27017

这看起来 MongoDB 初始启动没有问题。但它也表示它正在创建新的 ns 文件,尽管旧文件存在。这里发生了什么?如何恢复数据?

【问题讨论】:

    标签: mongodb amazon-ec2 data-loss


    【解决方案1】:

    没有任何迹象表明有任何损坏。日志表明此实例是在空卷上启动的。

    除了 logPath,您的 MongoDB 进程使用默认参数启动。因此,它将使用 /data/db 作为数据目录的位置。根据您对问题的初始描述,您可能一直在运行 EBS 挂载的单独日志和数据目录,即您的 MongoDB 配置使用了 --dbpath。

    1. 检查您使用的 MongoDB 配置是否与之前使用的相同 在服务器宕机之前
    2. 检查您的 EBS 卷是否按预期安装。您可以使用mount 选项来确认 路径 /data/db 指向正确的 EBS 卷。

    为了确定……如果实例使用了临时驱动器,则在实例关闭时数据将会丢失。有时人们会将临时驱动器与弹性块存储混淆,后者是持久的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多