如何设置MongoDB,使其可以作为Windows服务运行?


当前回答

我尝试了所有的答案,然后按照https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/#configure-a-windows-service-for-mongodb-community-edition描述的方式来做。

使用配置文件…

“C:\mongodb\bin\mongo .exe”——config“C:\mongodb\mongo .cfg”——安装

其他回答

不像其他答案。

在系统重启/重新启动时自动启动服务

MongoDB安装

窗户

(1)安装MongoDB

(2)添加bin到路径

(3)创建c:\data\db

(4)创建c:\data\log

(5)创建c:\data\mongo .cfg

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db

(6)创建在重启时自动启动的服务。以管理员身份运行..

sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\data\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

(7)启动服务。以管理员身份运行..

net start MongoDB

重要:即使显示“MongoDB服务已成功启动”,它也可能失败

要再次检查打开的控制面板>服务,确保MongoDB服务的状态为“Running”

如果不是,检查C:\data\log\mongo .log中的日志文件,找出失败的原因并修复它

(不要通过控制面板>服务启动MongoDB,使用..net start MongoDB

(8)最后,重新启动你的机器,运行MongoDB,重新启动时它仍将运行

如果你想杀死它…

net stop MongoDB

sc.exe delete MongoDB

这对我来说很管用:

sc.exe create MongoDB binPath= "d:\MongoDB\bin\mongod.exe --service --config=d:\MongoDB\bin\mongod.config" displayname= "MongoDB 2.6 Standard" start= "auto"

逃脱binPath是失败的我在Mongo文档中描述

失败:

sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"

不仅——安装,

还需要——dbpath和——logpath

重启操作系统后,你需要删除“mongod”。手动锁”

考虑使用

mongod --install --rest --master

对于2.4.3版本(发布日期的当前版本),创建一个配置文件,然后执行以下命令:

C:\MongoDB\bin\mongo .exe——config C:\MongoDB\mongo .cfg——service