mongodb 我可以杀死 mongod 来阻止 mongo 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21431091/
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
Can I just kill mongod to stop mongo?
提问by Michael
I am very new at Mongo. I am running mongod
as described herein Mac OS X
. I am running two mongod
processes from the command line. If I need to stop the mongod
processes I just execute kill <pid of mongod>
. Is it the recommended way to stop mongod
?
我在 Mongo 很新。我正在mongod
描述这里在Mac OS X
。我正在mongod
从命令行运行两个进程。如果我需要停止mongod
进程,我只需执行kill <pid of mongod>
. 这是推荐的停止方式mongod
吗?
回答by Esa
This is quite late, but I had same problem now, and I found one easy way :
这已经很晚了,但我现在遇到了同样的问题,我找到了一种简单的方法:
Esan-iMac:~$mongo admin --eval "db.shutdownServer()"
MongoDB shell version: 2.6.4
connecting to: admin
2015-02-19T10:54:22.574+0200 DBClientCursor::init call() failed
server should be down...
It's giving some odd messages, but it works.
它给出了一些奇怪的信息,但它有效。
And I made alias-command for running it easy.
我制作了alias-command 以便轻松运行。
alias stop-mongo='/opt/mongo/release/bin/mongo admin --eval "db.shutdownServer()"'
This works at least if you start your mongo manually (e.g. with --fork option).
这至少在您手动启动 mongo 时有效(例如使用 --fork 选项)。
回答by Mailis Toompuu
It finally succeeded (Ubuntu 15.04) with
它终于成功了(Ubuntu 15.04)
//1.find process by name:
//1.按名称查找进程:
$ pgrep mongo
1350
1350
//2.kill mongod-process
//2.kill mongod-process
$ kill 1350
回答by saurabheights
回答by Juan Rada
Windows
视窗
use admin
db.shutdownServer()
For systems with auth enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.
对于启用了身份验证的系统,用户只能在对 admin 数据库进行身份验证或通过未启用身份验证的系统上的 localhost 接口时发出 db.shutdownServer() 。
Linux
Linux
mongod --shutdown
you can also use
你也可以使用
kill <mongod process ID>
see http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
见http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
回答by seunggabi
terminal$ kill $(pgrep mongod)
终端 $ 杀死 $(pgrep mongod)
回答by Cross
For year of 2020:
2020年:
Mongo should be installed through Brew, rather than the old school style on linux: i.e. tar.gz package download/uncompress/configure/run.
Mongo 应该通过 Brew 安装,而不是 linux 上的老派风格:即 tar.gz 包下载/解压缩/配置/运行。
In the brew way, if Mongo is installed by brew tap mongodb/brew
and brew install mongodb-community
, you could do as follows to stop (and disable) it alike Systemd on Linux.
在 brew 方式中,如果 Mongo 是由brew tap mongodb/brew
and安装的brew install mongodb-community
,您可以执行以下操作来停止(和禁用)它,就像 Linux 上的 Systemd。
~ brew services list
Name Status User Plist
mongodb-community started zhengxin /Users/zhengxin/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
~ brew services stop mongodb-community
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community)
回答by daksh_019
Just encountered an issue with "just killing the mongod" in mac...
刚刚在mac中遇到了“just kill the mongod”的问题...
The mongod is kept running as a service by "launchctl" in mac systems. "just killing" it will kill that service.
Now to use mongo shell we do mongod again, however for other development purpose like connecting from node we need to make sure to run mongod time and again.
Other alternative is shut down the system and start again.
mongod 在 mac 系统中通过“launchctl”作为服务运行。“只是杀死”它会杀死该服务。
现在要使用 mongo shell,我们再次执行 mongod,但是对于其他开发目的,例如从节点连接,我们需要确保一次又一次地运行 mongod。
另一种选择是关闭系统并重新启动。
Better Way :
更好的方法 :
Start using launchctl to manage such services. Here is an example for that :
开始使用 launchctl 来管理此类服务。这是一个例子:
What is the correct way to start a mongod service on linux / OS X?
回答by JohnP
If you have configured autostart, killing the process won't help, new one will start immediately. In order to disable autostart, you have to locate the autostart file first. You can try to find the file using e.g.
如果您配置了自动启动,则终止进程无济于事,新进程将立即启动。为了禁用自动启动,您必须首先找到自动启动文件。您可以尝试使用例如查找文件
find / -name "mongodb.plist"
or locate "mongodb.plist"
find / -name "mongodb.plist"
或者 locate "mongodb.plist"
After the file is found, remove the autostart config using (you can try without sudo
first, it's not needed if you have done the installation using Homebrew):
找到文件后,使用删除自动启动配置(您可以先尝试sudo
,如果您使用 Homebrew 完成安装则不需要):
sudo launchctl unload -w <file>
If you want to kill the process anyway and it's not using autostart, remember not to use kill -9 <PID>
, it can damage the db. kill -1 <PID>
or kill -15 <PID>
should be safe options.
如果您无论如何都想终止该进程并且它没有使用自动启动,请记住不要使用kill -9 <PID>
,它会损坏数据库。kill -1 <PID>
或者kill -15 <PID>
应该是安全的选择。
回答by Marshall Farrier
The easiest way is Ctrl + C
, which worked for me on a blocking bash shell under El Capitan.
最简单的方法是Ctrl + C
,它在 El Capitan 下的阻塞 bash shell 上对我有用。