简体   繁体   English

崩溃后重新启动MongoDB

[英]Restart MongoDB after crash

I ran MongoDB in background in the Ubuntu server with the following command : 我在Ubuntu服务器中使用以下命令在后台运行MongoDB:

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

But sometimes database crashes and I have to restart manually, my question is how to restart automatically if database crashes ? 但是有时候数据库崩溃,我必须手动重启,我的问题是如果数据库崩溃怎么自动重启?

I have tried to add in /etc/init/mongodb.conf : 我试图在/etc/init/mongodb.conf添加:

respawn
respawn limit 10 90

But still if I kill monogodb process it haven't started automatically. 但是,即使我杀死monogodb进程,它也不会自动启动。 What is the problem ? 问题是什么 ?

Thanks 谢谢

Depending what operating system you are using, you should use the packages provided for your distribution at https://docs.mongodb.com/manual/administration/install-on-linux/ and then the start scripts provided. 根据所使用的操作系统,应使用在https://docs.mongodb.com/manual/administration/install-on-linux/上提供的用于分发的软件包,然后使用提供的启动脚本。

For ubuntu you need to create the systemd file 对于ubuntu,您需要创建systemd文件

If you install the .deb package from the link I provided earlier you can then create a systemd script by doing the following. 如果通过我之前提供的链接安装.deb软件包,则可以通过执行以下操作来创建systemd脚本。

Create /etc/systemd/system/mongodb.service with the contents 使用内容创建/etc/systemd/system/mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

then run systemctl start mongodb systemctl enable mongodb 然后运行systemctl启动mongodb systemctl enable mongodb

Then you can use systemctl restart mongodb whenever you want to start. 然后,无论何时要启动,都可以使用systemctl restart mongodb。

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

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