Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Windows上停止mongodb服务器?_Windows_Mongodb_Service_Command Line - Fatal编程技术网

如何在Windows上停止mongodb服务器?

如何在Windows上停止mongodb服务器?,windows,mongodb,service,command-line,Windows,Mongodb,Service,Command Line,我正在使用nginx/PHP/MongoDB堆栈,并试图通过创建两个批处理文件在Windows上设置我的开发环境 start.bat cd C:\www\nginx start nginx cd C:\www\php start php-cgi.exe -b 127.0.0.1:9000 cd C:\www\mongodb start mongod 停,蝙蝠 cd C:\www\nginx nginx -s quit cd C:\www\php taskkill /F /IM php-cgi.

我正在使用nginx/PHP/MongoDB堆栈,并试图通过创建两个批处理文件在Windows上设置我的开发环境

start.bat

cd C:\www\nginx
start nginx
cd C:\www\php
start php-cgi.exe -b 127.0.0.1:9000
cd C:\www\mongodb
start mongod
停,蝙蝠

cd C:\www\nginx
nginx -s quit
cd C:\www\php
taskkill /F /IM php-cgi.exe
cd C:\www\mongodb
mongo --eval "use admin; db.shutdownServer(); quit"  # this doesn't work
mongo --eval stop_mongod.js  # this doesn't work either
使用taskkill停止mongod不是一个选项,因为这可能会导致数据损坏。
有什么建议吗?

我想,使用TASKKILL/IM mongod.exe可以优雅地终止mongodb服务器。

来自mongo shell:


使用dbname

此命令在脚本模式下不工作。相反,您需要在连接中显式定义数据库(在上面的示例中为/dbname)

或者,也可以在脚本中创建连接:

db2 = connect("server:27017/otherdbname")

我想出了以下代码: 将以下代码段保存在stop_mongod.js文件中:

 db = connect("localhost:27017/admin");
 db.shutdownServer();
 quit();
如有必要,调整连接管柱。然后从命令行或批处理脚本中:

mongo stop_mongod.js

我不确定这样做是否正确,发送kill可能会损坏您的mongo服务器,并且您需要在发生崩溃后修复数据库

也许你已经解决了这个问题,但我是这样做的:

mongo admin --eval "db.shutdownServer()"
我自动连接到管理员的集合,接下来,我只需要运行消光

以下是关于如何正确阻止Mongodb的官方链接:


最好

如果服务器作为终端中的前台进程运行,则 可以通过按来完成

Ctrl-C
干净地关闭正在运行的服务器的另一种方法是使用shutdown命令

> use admin
> db.shutdownServer();

从Windows命令行。我正在64位Windows7Pro SP1上使用MongoDB3.4服务器

以下链接解释了这些步骤:

以下控制台命令行在启动时终止MongoDB:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\System32>"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --remove
2017-12-06T08:15:47.883-0600 I CONTROL  [main] Trying to remove Windows service 'MongoDB'
2017-12-06T08:15:47.884-0600 I CONTROL  [main] Service 'MongoDB' removed
MongoDB服务创建命令行(如下所示)位于Windows注册表中:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MongoDB
要进行检查,请执行以下操作:

C:\Windows\System32>sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --c
onfig=\"C:\Program Files\MongoDB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
[SC] CreateService SUCCESS

C:\Windows\System32>net start MongoDB
The MongoDB service is starting.
The MongoDB service was started successfully.

C:\Windows\System32>net stop MongoDB
The MongoDB service is stopping.
The MongoDB service was stopped successfully.

C:\Windows\System32>"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --remove
2017-12-06T08:16:36.504-0600 I CONTROL  [main] Trying to remove Windows service 'MongoDB'
2017-12-06T08:16:36.505-0600 I CONTROL  [main] Service 'MongoDB' removed

C:\Windows\System32> 
  • 以管理员身份打开命令提示符/Powershell
  • 执行“净停止MongoDB”

  • 如果将mongodb作为服务安装在windows上。您可以在提升的命令提示符下使用以下命令停止服务

     net stop mongodb
    

    以管理员身份打开命令提示符

    net stop mongodb
    

    “mongo admin--eval”db.shutdownServer()“'也应该这样做。这对于我在Windows实例上对一些mongo进行临时维护来说效果很好。它比使用Windows“net stop”cmd更可靠。但现在我无法从这里使用提示启动它:powershell中的
    net
    命令是否有
    status
    ?您可以从cmd手动停止使用“services.msc”,并在该列表中选择mongodb服务并停止它。我发现这很有用!