如何在一个命令中停止mongo DB [英] How to stop mongo DB in one command

查看:83
本文介绍了如何在一个命令中停止mongo DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在cli上启动/停止MongoDB.开始非常简单:

./mongod

但是要停止mongo DB,我需要先运行打开的mongo shell,然后键入两个命令:

$ ./mongo

使用管理员

db.shutdownServer()

所以我不知道如何在一行中停止mongo DB.有帮助吗?

解决方案

开始和停止MongoDB 在MongoDB手册中进行了介绍.它说明了通过外壳,cli,驱动程序等停止MongoDB的各种选项.还详细介绍了错误地停止MongoDB的风险(例如数据损坏),并讨论了不同的终止信号.

此外,如果您已使用软件包管理器为 Ubuntu安装了MongoDB Debian ,则可以停止mongodb(当前在ubuntu中使用mongod),如下所示:

  • 新贵:sudo service mongod stop

  • Sysvinit:sudo /etc/init.d/mongod stop

或者在 Mac OS X

或者在红色上基于Hat 的系统:

  • service mongod stop

或者在 Windows上(如果已安装为名为MongoDB的服务:

)
  • net stop MongoDB

如果未安装为服务(从Windows 7+开始),则可以运行:

  • taskkill /f /im mongod.exe

要了解有关不正常关机的问题的更多信息,如何最好地避免这种情况,以及在不正常关机的情况下该怎么办,请参见: 解决方案

Starting and Stopping MongoDB is covered in the MongoDB manual. It explains the various options of stopping MongoDB through the shell, cli, drivers etc. It also details the risks of incorrectly stopping MongoDB (such as data corruption) and talks about the different kill signals.

Additionally, if you have installed MongoDB using a package manager for Ubuntu or Debian then you can stop mongodb (currently mongod in ubuntu) as follows:

  • Upstart: sudo service mongod stop

  • Sysvinit: sudo /etc/init.d/mongod stop

Or on Mac OS X

Or on Red Hat based systems:

  • service mongod stop

Or on Windows if you have installed as a service named MongoDB:

  • net stop MongoDB

And if not installed as a service (as of Windows 7+) you can run:

  • taskkill /f /im mongod.exe

To learn more about the problems of an unclean shutdown, how to best avoid such a scenario and what to do in the event of an unclean shutdown, please see: Recover Data after an Unexpected Shutdown.

这篇关于如何在一个命令中停止mongo DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆