服务器崩溃后 MongoDB 无法启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13700261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MongoDB won't start after server crash
提问by Hosam Aly
My Ubuntu computer had crashed, and when I restarted it MongoDB wasn't working. I tried the following commands, and got the following output:
我的 Ubuntu 计算机崩溃了,当我重新启动它时,MongoDB 无法正常工作。我尝试了以下命令,并得到以下输出:
$ mongo
Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
$ service mongodb status
mongodb stop/waiting
$ service mongodb restart
stop: Unknown instance:
start: Rejected send message, 1 matched rules; type="method_call",
sender=":1.57" (uid=1000 pid=2227 comm="start mongodb ")
interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)"
requested_reply="0"
destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
$ tail /var/log/mongodb/mongodb.log
[initandlisten] exception in initAndListen: 12596 old lock file, terminating
dbexit:
[initandlisten] shutdown: going to close listening sockets...
[initandlisten] shutdown: going to flush diaglog...
[initandlisten] shutdown: going to close sockets...
[initandlisten] shutdown: waiting for fs preallocator...
[initandlisten] shutdown: closing all files...
[initandlisten] closeAllFiles() finished
dbexit: really exiting now
(Output reformatted to match website layout.)
(输出重新格式化以匹配网站布局。)
What happened? How can I fix it?
发生了什么?我该如何解决?
回答by Hosam Aly
The log file is telling you that you have an "old lock file". MongoDB keeps a lockfile while it's running. It creates this file when it is started, and deletes it when it's stopped. When the computer crashes (or MongoDB crashes, e.g. via kill
), this file is not deleted, and thus the database does not start. The existence of this file indicates unclean shutdown of MongoDB.
日志文件告诉您您有一个“旧锁文件”。MongoDB在运行时保留一个锁定文件。它在启动时创建这个文件,并在它停止时删除它。当计算机崩溃(或 MongoDB 崩溃,例如 via kill
)时,该文件不会被删除,因此数据库不会启动。此文件的存在表明 MongoDB 不正常关闭。
Two things can be done:
可以做两件事:
If this is a development machine and you haven't been using your database (and neither have your programs), you can remove the file manually. For MongoDB 2.2.2 running on Ubuntu 12.10, it's in
/var/lib/mongodb/mongod.lock
. For other versions, the file could be in a different path or it could be namedmongo.lock
.The safer route is to follow MongoDB's Durability and Repairguide. In summary, for a machine with the above configuration, you should execute the following commands:
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/ sudo service mongod start
如果这是一台开发机器并且您没有使用过数据库(也没有使用过您的程序),您可以手动删除该文件。对于在 Ubuntu 12.10 上运行的 MongoDB 2.2.2,它位于
/var/lib/mongodb/mongod.lock
. 对于其他版本,文件可能位于不同的路径中,也可能命名为mongo.lock
.更安全的方法是遵循 MongoDB 的Durability and Repair指南。综上所述,对于具有上述配置的机器,您应该执行以下命令:
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/ sudo service mongod start
回答by edencorbin
all I had to do was run: sudo mongod --repair
我所要做的就是运行:sudo mongod --repair
then:
然后:
sudo mongod
须藤蒙戈
回答by samson ojo
Based on my experience, I usually delete the "mongod.lock" file that is inside the database folder - In my case:
根据我的经验,我通常会删除数据库文件夹中的“mongod.lock”文件 - 就我而言:
*I browse to where the database is installed on my ubuntu i.e. "data" folder.(cd data); list the files (ls) *Then, I will remove the "mongod.lock" file that was automatically created when the database crashed, by issuing "rm mongod.lock" file.
*我浏览到我的 ubuntu 上安装数据库的位置,即“数据”文件夹。(cd 数据);列出文件 (ls) *然后,我将通过发出“rm mongod.lock”文件来删除数据库崩溃时自动创建的“mongod.lock”文件。
After which I will either issue "./mongod" to start the mongo deamon or mongo to start the mongo shell. And everything will be fine.
之后我将发出“./mongod”来启动 mongo deamon 或 mongo 来启动 mongo shell。一切都会好起来的。
回答by Touseef Murtaza
If you did not use monitoring tools like Bluepillor Monitetc you will have to face this issue because after server crash due to some reason mongo didnot start its daemon automatically then you have to make it work manually, like sudo service mongod restart
I figured this issue but it needs some more tasks to be done, please make sure your dbpath at /etc/mongod.conf
before starting your mongo daemon.
如果你没有使用Bluepill或Monit等监控工具,你将不得不面对这个问题,因为在服务器崩溃后由于某种原因 mongo 没有自动启动它的守护进程,那么你必须手动让它工作,就像sudo service mongod restart
我认为这个问题,但它需要还有一些任务要完成,请/etc/mongod.conf
在启动 mongo 守护程序之前确保您的 dbpath 位于。
For me it was
对我来说是
storage:
dbPath: /var/lib/mongodb
When i enter mongod
command it shows me MongoDB starting : pid=10795 port=27017 dbpath=/data/db 64-bit host=xyz.com
make sure your dbpath is as same as mentioned in /etc/mongod.conf
当我输入mongod
命令时,它显示我MongoDB starting : pid=10795 port=27017 dbpath=/data/db 64-bit host=xyz.com
确保您的 dbpath 与 /etc/mongod.conf 中提到的相同
To do this you can type sudo mongod --dbpath /var/lib/mongodb
and then use mongod
command to start your mongo process at your desired dbpath.
为此,您可以键入sudo mongod --dbpath /var/lib/mongodb
然后使用mongod
命令在所需的 dbpath 中启动 mongo 进程。
FYI:start your mongo process with mongod
command
仅供参考:使用mongod
命令启动您的 mongo 进程
回答by Hemant Thorat
Removing .lock
file from mongo data directory dbpath
works for me.
.lock
从 mongo 数据目录中删除文件dbpath
对我有用。
e.g sudo sudo rm {data-directory}/mongod.lock
例如 sudo sudo rm {data-directory}/mongod.lock
回答by Jeremy Lynch
Check to see if you have enough free space on your server. If there is no room left mongodb won't start.
检查您的服务器上是否有足够的可用空间。如果没有剩余空间,mongodb 将无法启动。
回答by Jage
This is probably not the best solution, but if you're desperate you can try this. It seemed that only the journal was a problem for me, so I took these steps:
这可能不是最好的解决方案,但如果你不顾一切,你可以试试这个。看来只有期刊对我来说是个问题,所以我采取了以下步骤:
- Create a new data directory. Possibly /var/lib/mongodb2
- Update your mongod.confto point to the new data dir.
- StartmongoDB.
- If it starts successfully, then you can shut down mongo againand proceed, otherwise you can stop reading here.
- Locate your previous data dir and copy the files for your database(s)to your new data directory (example, admin.0 admin.1 admin.ns, etc)
- Start mongoDBagain (still using the new data directory)
- 创建一个新的数据目录。可能是 /var/lib/mongodb2
- 更新您的 mongod.conf以指向新的数据目录。
- 启动MongoDB。
- 如果启动成功,那么你可以再次关闭mongo并继续,否则你可以在这里停止阅读。
- 找到您之前的数据目录并将您的数据库文件复制到您的新数据目录(例如,admin.0 admin.1 admin.ns 等)
- 再次启动mongoDB(仍然使用新的数据目录)
After completing these steps (took less than 5 min), I was up and running and all data appeared to be ok.
完成这些步骤后(用时不到 5 分钟),我就开始运行了,所有数据似乎都没有问题。
回答by Keijo
Thank's guys. We also faced an issue where MongoDB was restarting over and over again an it was complaining about old lock file. I stopped MongoDB from Windows service list and then I deleted the mongod.lock
file. After that I was able to start MongoDB service correctly and it worked fine.
谢谢你们。我们还面临一个问题,即 MongoDB 一遍又一遍地重新启动,并抱怨旧锁文件。我从 Windows 服务列表中停止了 MongoDB,然后我删除了该mongod.lock
文件。之后,我能够正确启动 MongoDB 服务并且运行良好。