2015-10-05 55 views
0

發生了最奇怪的事情。我們有一個mongodb實例,將日誌和日誌記錄在由ebs支持的單個amazon ec2上運行的獨立硬盤上。今天早上服務器意外關閉,當我看着它時,我注意到mongo沒有在啓動時啓動。MongoDB意外關機和數據丟失

我手動使用命令

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文件,儘管存在舊文件。這裏發生了什麼以及如何恢復數據?

回答

0

沒有跡象表明有任何損壞。日誌表明這個實例是在一個空捲上啓動的。

除了logPath之外,您的MongoDB進程正在使用默認參數啓動。所以,它將使用/ data/db作爲數據目錄的位置。根據您對問題的初步描述,您可能已經在單獨的日誌和數據目錄中運行EBS掛載,即您的MongoDB配置使用了--dbpath。

  1. 檢查是否正在使用相同的MongoDB配置,使用前 服務器下樓
  2. 檢查您的EBS卷裝的預期。您可以使用mount選項來確認 path/data/db指向正確的EBS卷。

而且可以肯定的是,如果實例使用臨時驅動器,那麼當實例關閉時數據將會丟失。有時候人們會將短暫的驅動器與彈性塊存儲混淆,其中持久存在。