这篇文章已经过时了!
请参考此最新指南以将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服务安装
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
做完了
参考
翻译自: https://mkyong.com/mongodb/how-to-run-mongodb-as-windows-service/