How to run MongoDB as Windows service?

2019-01-03 11:53发布

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

26条回答
Deceive 欺骗
2楼-- · 2019-01-03 12:09

The simplest way is,

  1. Create folder C:\data\db
  2. Create file C:\data\db\log.txt
  3. Open command prompt as "Run as Administrator" and make sure the mogodb bin directory path is correct and write

    C:\Program Files\MongoDB\Server\3.4\bin> mongod.exe --install mongod --dbpath="c:\data\db" --logpath="c:\data\db\log.txt" 
    
  4. Start mongodb service:

    net run MongoDB
    
查看更多
戒情不戒烟
3楼-- · 2019-01-03 12:10

Run "cmd.exe" as administrator and then run "sc.exe" to add a new Windows service.

for example:

sc.exe create MongoDB binPath= "c:\program files\mongodb\server\3.2\bin\mongod.exe"
查看更多
爷、活的狠高调
4楼-- · 2019-01-03 12:12

Working on Mongo DB: 3.6

(1) Install MongoDB

(2) Add bin to environment path variable

(3) Create c:\data\db

(4) Create c:\data\mongod.log

(5) Run below Command on bin folder

.\mongod.exe --install --logpath c:\data\mongod.log --logappend --bind_ip 12 7.0.0.1 --dbpath c:\data\db

(6) To start mongo db as service

net start MongoDB

(7) Finally run mongo in command line to check mongo shell is open or not.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-03 12:14

I tried all answers and then did it the way https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/#configure-a-windows-service-for-mongodb-community-edition describes it.

Use a config file...

"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install

查看更多
相关推荐>>
6楼-- · 2019-01-03 12:14

For version 2.4.3 (current version as of posting date), create a config file and then execute the following:

C:\MongoDB\bin\mongod.exe --config C:\MongoDB\mongod.cfg --service

查看更多
Fickle 薄情
7楼-- · 2019-01-03 12:14

Currently (up to version 2.4.4), if any path (dbpath/logpath/config) contains spaces, then the service won't start, and show the error: "The service is not responding to the control function".

查看更多
登录 后发表回答