如何在一个命令中停止mongo DB [英] How to stop mongo DB in one command
问题描述
我需要能够在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 上>
-
使用
$ top
查找mongod进程的PID
-
通过
$ kill <PID>
( Mongo文档对此有更多信息)
或者在红色上基于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
Find PID of mongod process using
$ top
Kill the process by
$ kill <PID>
(the Mongo docs have more info on this)
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屋!