如何将MongoDB作为Windows服务运行

这篇文章已经过时了!
请参考此最新指南以将MongoDB安装为Windows服务。

向您展示如何在Windows上安装MongoDB的指南。

1. mongod –帮助

通过键入“ mongod --help ”来了解所有与Windows服务相关的命令。

C:\MongoDB\bin>mongod --help

Windows Service Control Manager options:
  --install                install mongodb service
  --remove              remove mongodb service
  --reinstall             reinstall mongodb service (equivilant of mongod
                             --remove followed by mongod --install)
  --serviceName arg           windows service name
  --serviceDisplayName arg windows service display name
  --serviceDescription arg    windows service description
  --serviceUser arg              user name service executes as
  --servicePassword arg       password used to authenticate serviceUser

您需要两个--install--remove参数。

2.安装为Windows服务

要作为Windows服务安装,请发出“ mongod --install ”,例如:

#> mongod --dbpath "c:\mymongodb" --logpath "c:\mymongodb\logs.txt" --install --serviceName "MongoDB"
all output going to: c:\mymongodb\logs.txt
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.

这意味着,安装一个指向“ c:\mymongodb ”数据目录的MongoDB,将输出记录到“ c:\mymongodb\logs.txt ”,以及一个名为“ MongoDB ”的Windows服务。

图片:MongoDB作为Windows服务安装

mongodb as windows service

3.卸载

要卸载上面安装的MongoDB服务,请发出“ mongod --remove ”以及安装的服务名称。

#> mongod --remove --serviceName "MongoDB"
Deleting service MongoDB.
Service deleted successfully.
Fri Apr 29 18:39:06 dbexit:
Fri Apr 29 18:39:06 shutdown: going to close listening sockets...
Fri Apr 29 18:39:06 shutdown: going to flush diaglog...
Fri Apr 29 18:39:06 shutdown: going to close sockets...
Fri Apr 29 18:39:06 shutdown: waiting for fs preallocator...
Fri Apr 29 18:39:06 shutdown: closing all files...
Fri Apr 29 18:39:06 closeAllFiles() finished
Fri Apr 29 18:39:06 dbexit: really exiting now

做完了

参考

  1. MongoDB作为Windows服务

翻译自: https://mkyong.com/mongodb/how-to-run-mongodb-as-windows-service/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值