简体   繁体   English

MongoDB数据消失了

[英]MongoDB data disappeared

I have MongoDB running in replication mode, with 3 instances, on AWS. 我在AWS上以3个实例在复制模式下运行MongoDB。 The setup has been up and running for over a year. 该设置已经启动并运行了一年多。 With periodic updates to the application server (running Node.js code). 定期更新应用程序服务器(运行Node.js代码)。 The application server has been running the same code for several months. 应用服务器已经运行相同的代码已有几个月了。 Last night all calls to the DB started failing, when I logged in to the AWS EC2 Instance running the primary MongoDB, I could not find any of the collections from the mongo shell. 昨晚,所有对数据库的调用都开始失败,当我登录到运行主要MongoDB的AWS EC2实例时,我无法从mongo shell中找到任何集合。 This is the same mongo shell that's been up and running for months (I use tmux to connect). 这是已经运行了几个月的mongo shell(我使用tmux进行连接)。

Based on the size consumption on the filesystem, from what I remember, I think the data is there, but I'm not sure how to access it now. 基于文件系统的大小消耗,据我所记得,我认为数据已经存在,但是我不确定现在如何访问它。

sudo /usr/bin/mongod --replSet ReplicaSet --port 27017 --dbpath /data/db

The above command was used to start the mongo db, nothing has been changed, but the data simply disappeared last night. 上面的命令是用来启动mongo db的,什么都没有改变,但是昨晚数据只是消失了。 The same is true on all 3 servers (Primary and 2 Secondaries) 在所有3台服务器(主服务器和2个辅助服务器)上都一样

Any help is extremely welcomed... 任何帮助都非常受欢迎...

See mongodb log if any dropDatabase command has been executed or not. 请参阅mongodb日志,了解是否已执行任何dropDatabase命令。 Generally its /var/log/mongo/mongo.log. 通常是/var/log/mongo/mongo.log。 Or see /etc/mongo.conf for log file location. 或参阅/etc/mongo.conf了解日志文件的位置。

Recently some exposed mongoDB has been hacked for ransom. 最近,一些暴露的mongoDB已被勒索赎金。

News is here 新闻在这里

I imagine you solved this by now. 我想您现在已经解决了这个问题。 I am going to give an answer for anyone with similar issues. 我将为有类似问题的任何人提供答案。 I am not sure of your experience level with MongoDB, so I will try to layout more information than you probably need. 我不确定您在MongoDB方面的经验水平,因此我将尝试安排比您可能需要的更多的信息。 Anyway,I have had a similar issue as you are experiencing. 无论如何,我遇到了与您遇到的类似问题。 I love MongoDB, but it has a learning curve with it, mine was with what happens with "unconfined documents". 我喜欢MongoDB,但是它有一个学习曲线,我的经验是处理“无限制文档”。 If like me, you have MongoDB set to auto-restart in the event of a crash, then unless you check your logs, you may never be aware of a crash. 如果像我一样,您将MongoDB设置为在发生崩溃时自动重新启动,那么除非您检查日志,否则您可能永远不会意识到崩溃。 If a crash occurs, or even a reset, there are times when documents that are there, but fall into the "unconfirmed" category are lost. 如果发生崩溃或什至重置,有时丢失丢失但属于“未确认”类别的文档。 So... 所以...

  1. One possible answer is to update MongoDB to a more current version. 一种可能的答案是将MongoDB更新到最新版本。 Some older ones I have come to understand have a larger problem with this. 我逐渐了解的一些较旧的问题与此有关。
  2. Understand "write concerns" and how they relate to data durability. 了解“写关注点”及其与数据持久性的关系。 An article that helped me a lot with this is: 一篇对我有很大帮助的文章是:
    https://www.percona.com/blog/2016/07/14/mongodb-data-durability/ https://www.percona.com/blog/2016/07/14/mongodb-data-durability/

  3. Make sure conf file is being loaded. 确保conf文件正在加载。 Perhaps it is not seeing your data for some reason. 也许由于某种原因没有看到您的数据。 You can, for a test, load mongod.exe and specify the path directly to your db for a test, ie: 对于测试,您可以加载mongod.exe并直接指定要测试的数据库的路径,即:

mongod --dbpath c:\\mongo\\data\\db mongod --dbpath c:\\ mongo \\ data \\ db

For debian/ubuntu 对于debian / ubuntu

$ mongo
> use admin
> db.shutdownServer()

and then 接着

mongod --fork --logpath /var/log/mongodb.log --dbpath /var/lib/mongodb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM