1. 下载MongoDB的windows版本:mongodb-win32-x86_64-2008plus-ssl-3.0.4.zip,Linux版本也在这里下载,下载地址: http://www.mongodb.org/downloads
2. 解压MongoDB在D:\server\mongodb, 在D:\server\mongodb下创建db目录和logs目录,用来存数据文件和日志。
3. 新建环境变量mongodb_home,值为E:\server\mongodb,在Path里添加 %mongodb_home%\bin;
4. 在%mongodb_home%目录创建mongo.conf文件,配置dbpath和logpath信息:
dbpath = E:\server\mongodb\db logpath = E:\server\mongodb\logs\mongodb.log port = 27017 logappend = true
在%mongodb_home%\bin目录执行安装mongodb服务的命令:
mongod --config E:\server\mongodb\mongo.conf
MongoDB服务安装成功的消息:
2015-07-09T22:15:33.367+0800 I CONTROL [thread1] Hotfix KB2731284 or later update is not installed, will zero-out data files 2015-07-09T22:15:33.368+0800 I CONTROL [thread1] Trying to install Windows service 'MongoDB' 2015-07-09T22:15:33.844+0800 I CONTROL [thread1] Service 'MongoDB' (MongoDB) installed with command line 'D:\server\mongodb\bin\mongod.exe --dbpath=D:\server\mongodb\db --logpath=D:\server\mongodb\logs\mongodb.log --service' 2015-07-09T22:15:33.845+0800 I CONTROL [thread1] Service can be started from the command line with 'net start MongoDB'
PS:如果此命令不能正常启动, 就改为以管理员身份启动CMD窗口。
5. mongoDB的端口为27017, 在浏览器访问 http://localhost:27017, 会输出提示:
It looks like you are trying to access MongoDB over HTTP on the native driver port.
6. 在bin目录重新打开一个终端, 输入mongo,提示:
2015-07-09T22:24:21.791+0800 I CONTROL [thread1] Hotfix KB2731284 or later upda te is not installed, will zero-out data files MongoDB shell version: 3.1.4 connecting to: test Server has startup warnings: 2015-07-09T22:18:28.395+0800 I CONTROL [initandlisten] 2015-07-09T22:18:28.395+0800 I CONTROL [initandlisten] ** NOTE: This is a devel opment version (3.1.4) of MongoDB. 2015-07-09T22:18:28.395+0800 I CONTROL [initandlisten] ** Not recommended for production. 2015-07-09T22:18:28.395+0800 I CONTROL [initandlisten]
信息显示mongodb启动状态正常。
PS:如需要帮助信息,可使用help命令。
7. 查看mongoDB日志, 在D:\server\mongodb\logs目录下, 存着mongoDB的操作日志,可对mongDB的运行情况进行查看或排错。
8. 操作命令:
启动MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB
删除MongoDB:sc delete MongoDB