【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".
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值