How to run MongoDB as Windows service?

2019-01-03 11:53发布

How to setup MongoDB so it can run as Windows service?

26条回答
虎瘦雄心在
2楼-- · 2019-01-03 12:20

The recommended way mongod --install results in error:

2015-12-03T18:18:28.896+0100 I CONTROL  --install has to be used with a log file for server output

After having installed mongodb in C:\mongodb you need to simply add the logpath:

mongod --install --logpath C:\mongodb\logs\mongo.log

The path to the logfile must exist and it must be an absolute Windows path. Then you start the MongoDB service by typing:

net start MongoDB
查看更多
冷血范
3楼-- · 2019-01-03 12:20

I'm on version 2.4.9 and using a config file. The service wouldn't start until I surrounded the equals sign in the config file with spaces:

dbpath = D:\Mongo data
logpath = C:\mongodb\logs\mongo.log 
logappend = true

Originally I had:

logpath=C:\mongodb\logs\mongo.log 

I also discovered that when installing the service that you have to use an absolute path for the config file eg:

c:\mongodb\bin\>mongodb.exe C:\mongodb\bin\mongod.conf --install

Don't be tempted to put inverted commas around a dbpath with spaces. The service will appear to start when you execute net start MongoDB but it will terminate. Check the log files for confirmation that the service has really started.

查看更多
登录 后发表回答