mongodb 在 Mac OS X 上停止 mongod 的干净方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8495293/
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
What's a clean way to stop mongod on Mac OS X?
提问by emilebaizel
i'm running mongo 1.8.2 and trying to see how to cleanly shut it down on Mac.
我正在运行 mongo 1.8.2 并尝试查看如何在 Mac 上干净地关闭它。
on our ubuntu servers i can shutdown mongo cleanly from the mongo shell with:
在我们的 ubuntu 服务器上,我可以使用以下命令从 mongo shell 干净地关闭 mongo:
> use admin
> db.shutdownServer()
but on my Mac, it does not kill the mongod process. the output shows that it 'should be' shutdown but when i ps -ef | grep mongo it shows me an active process. also, i can still open a mongo shell and query my dbs like it was never shutdown.
但在我的 Mac 上,它不会终止 mongod 进程。输出显示它“应该”关闭,但是当 i ps -ef | grep mongo 它向我展示了一个活跃的过程。此外,我仍然可以打开一个 mongo shell 并查询我的数据库,就像它从未关闭一样。
the output from my db.shutdownServer() locally is:
我的 db.shutdownServer() 在本地的输出是:
MongoDB shell version: 1.8.2
connecting to: test
> use admin
switched to db admin
> db.shutdownServer()
Tue Dec 13 11:44:21 DBClientCursor::init call() failed
Tue Dec 13 11:44:21 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down...
Tue Dec 13 11:44:21 trying reconnect to 127.0.0.1
Tue Dec 13 11:44:21 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1
Tue Dec 13 11:44:21 Error: error doing query: unknown shell/collection.js:150
i know i can just kill the process but i'd like to do it more cleanly.
我知道我可以终止这个过程,但我想做得更干净。
回答by James Chen
It's probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first:
这可能是因为 launchctl 正在管理您的 mongod 实例。如果要启动和关闭 mongod 实例,请先卸载它:
launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
Then start mongod manually:
然后手动启动mongod:
mongod -f path/to/mongod.conf --fork
You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist
.
您可以从~/Library/LaunchAgents/org.mongodb.mongod.plist
.
After that, db.shutdownServer()
would work just fine.
在那之后,db.shutdownServer()
会工作得很好。
Added Feb 22 2014:
2014 年 2 月 22 日添加:
If you have mongodb installed via homebrew, homebrew actually has a handy brew services
command. To show current running services:
如果您通过自制软件安装了 mongodb,自制软件实际上有一个方便的brew services
命令。显示当前正在运行的服务:
brew services list
brew services list
To start mongodb:
启动mongodb:
brew services start mongodb
brew services start mongodb
To stop mongodb if it's already running:
如果 mongodb 已经在运行,则停止它:
brew services stop mongodb
brew services stop mongodb
Update
更新
As edufinn pointed out in the comment, brew services
is now available as user-defined command and can be installed with following command: brew tap gapple/services
.
正如 edufinn 在评论中指出的那样,brew services
现在可以作为用户定义的命令使用,并且可以使用以下命令进行安装:brew tap gapple/services
.
回答by Raphael
If you installed mongodb with homebrew, there's an easier way:
如果您使用自制软件安装了 mongodb,则有一种更简单的方法:
List mongo job with launchctl:
使用 launchctl 列出 mongo 作业:
launchctl list | grep mongo
Stop mongo job:
停止 mongo 工作:
launchctl stop <job label>
(For me this is launchctl stop homebrew.mxcl.mongodb
)
(对我来说这是launchctl stop homebrew.mxcl.mongodb
)
Start mongo job:
开始 mongo 工作:
launchctl start <job label>
回答by Sanchit Singhania
Simple way is to get the process id of mongodb and kill it. Please note DO NOT USE kill -9 pid for this as it may cause damage to the database.
简单的方法是获取mongodb的进程id并杀死它。请注意不要为此使用kill -9 pid,因为它可能会损坏数据库。
so, 1. get the pid of mongodb
所以,1.获取mongodb的pid
$ pgrep mongo
$ pgrep 蒙戈
you will get pid of mongo, Now
你会得到 mongo 的 pid,现在
$ kill
$杀
You may use kill -15 as well
你也可以使用 kill -15
回答by the_haystacker
If you have installed mongodb community server via homebrew, then you can do:
如果您已经通过自制软件安装了 mongodb 社区服务器,那么您可以执行以下操作:
brew services list
This will list the current services as below:
这将列出当前的服务如下:
Name Status User Plist
mongodb-community started sangeeth /Users/sangeeth/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
redis stopped
Then you can restart mongodb by first stopping and restart:
然后您可以通过先停止并重新启动来重新启动mongodb:
brew services stop mongodb
brew services start mongodb
回答by Rafa
I prefer to stop the MongoDB server using the port
command itself.
我更喜欢使用port
命令本身停止 MongoDB 服务器。
sudo port unload mongodb
And to start it again.
并重新开始。
sudo port load mongodb
回答by Tyler Brock
Check out these docs:
查看这些文档:
If you started it in a terminal you should be ok with a ctrl + 'c'
-- this will do a clean shutdown.
如果您在终端中启动它,您应该可以使用ctrl + 'c'
-- 这将彻底关闭。
However, if you are using launchctl there are specific instructions for that which will vary depending on how it was installed.
但是,如果您使用的是 launchctl,则有具体说明,具体说明取决于安装方式。
If you are using Homebrew it would be launchctl stop homebrew.mxcl.mongodb
如果您使用的是 Homebrew,它将是 launchctl stop homebrew.mxcl.mongodb
回答by Alexander Swensen
This is an old question, but its one I found while searching as well.
这是一个老问题,但我在搜索时也发现了这个问题。
If you installed with brew
then the solution would actually be the this:
如果您安装了,brew
那么解决方案实际上是这样的:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist