【MongoDB】MongoDB as Win7 service

Every time, we use mongoDB, must to manual input:

C:\users\XXX>cd /d d:\MongoDB\bin
d:\MongoDB\bin>mongod -dbpath D:\MongoDB\data

So, we can install it as Windows service.

[size=large][b]Success:[/b][/size]
Right click the command prompt, and open it with "Run as Administrator".

C:\Windows\system32>cd /d d:\MongoDB\bin
d:\MongoDB\bin>mongod -dbpath D:\MongoDB\data --logpath D:\MongoDB\logs\mongodb.log --logappend --directoryperdb --serviceName MongoDB --install
all output going to: D:\MongoDB\logs\mongodb.log


show mongodb.log
[quote]Wed Dec 05 18:18:38 Trying to install Windows service 'MongoDB'
Wed Dec 05 18:18:38 Service 'MongoDB' (Mongo DB) installed with command line '"d:\MongoDB\bin\mongod.exe" -dbpath "D:\MongoDB\data" --logpath "D:\MongoDB\logs\mongodb.log" --logappend --directoryperdb --service '
Wed Dec 05 18:18:38 Service can be started from the command line with 'net start MongoDB'[/quote]

start MongoDB:
d:\MongoDB\bin>net start MongoDB
The Mongo DB service is starting.
The Mongo DB service was started successfully.


stop MongoDB:
d:\MongoDB\bin>net stop MongoDB
System error 109 has occurred.
The pipe has been ended.

---> I dont know this question, but in the log file, the service was stopped.

delete MongoDB:
C:\Windows\System32>sc delete MongoDB
[SC] DeleteService SUCCESS

or run regedit, find HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->Services->MongoDB, then delete it.

[b][size=large]Attention:[/size][/b]
1. --dbpath: data directory
--directoryperdb: Each DB will create a new directory.
2. --logpath: log file directory
here,log file must be XXX.log, if it isn't existed, it will be created automatically.
--logappend: XXX.log output in additional way.
3. --serviceName: Windows service name, here pay attention to the letter "N".
4. all the above commands must run as administrator.

[size=large][b]Question in the process:[/b][/size]
1.
d:\MongoDB\bin>mongod -dbpath D:\MongoDB\data --install
Wed Dec 05 18:07:37 --install has to be used with --logpath

------> This because we need to install --logpath

2. If we don't open the command prompt as administrator, it maybe occurrce the following error:
 Error connecting to the service Control Manager: Access is denied. (5)

or, we start MongoDB, also occurrce the error:
 System error 5 has occurred. 
Access is denied.

------> So must "Run as administrator".
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章