上篇
《windows mongodb 源码安装src》讲了如何在windows上安装mongodb,但是没有写如何安装成一个windows服务。
首先 cd到源码文件夹,执行如下命令:
mongod --install --serviceName MongoDB --serviceDisplayName MongoDB --logpath D:\MongoDB\log\MongoDB.log --dbpath D:\MongoDB\data --directoryperdb
--install
安装mongodb服务
--serverName
Windows服务名称
--serverDisplayName
Windows服务管理器中显示的服务名
--logpath 日志文件路径(含文件名)
--dbpath 数据库文件夹路径
--
directoryperdb
根据数据库名建立文件夹
注意:log日志所在的文件夹和数据库所在的文件夹必须已经存在。
安装完成后,我们就可以看到日志中已经有记录了
2015-03-11T20:14:21.874+0800 Trying to install Windows service 'MongoDB'
2015-03-11T20:14:28.268+0800 Service 'MongoDB' (MongoDB) installed with command line '"D:\Program Files\mongodb-src-r2.6.8\mongod.exe" --logpath D:\MongoDB\log\MongoDB.log --dbpath D:\MongoDB\data --directoryperdb --service'
2015-03-11T20:14:28.268+0800 Service can be started from the command line with 'net start MongoDB'
刷新windows服务即可看到
也可以在CMD中使用 net start MongoDB启动服务,net stop MongoDB即可关闭