1)、下载MongoDB
http://downloads.mongodb.org/win32/mongodb-win32-i386-2.0.4.zip
2)、设置MongoDB目录
将其解压到 d:\,再重命名为mongodb,路径为d:\mongodb
3)、设置数据文件路径
在d:盘建一个data文件夹,在data文件夹中新建db文件夹,路径d:\data\db
4)、启动MongoDB服务
进入 cmd 提示符控制台,
D:\mongodb\bin\mongod.exe --dbpath=d:\data\db
1. Mon Apr 16 08:50:54
2. Mon Apr 16 08:50:54 warning: 32-bit servers don't have journaling enabled by def
3. ault. Please use --journal if you want durability.
4. Mon Apr 16 08:50:54
5. Mon Apr 16 08:50:54 [initandlisten] MongoDB starting : pid=5084 port=27017 dbpat
6. h=d:\data\db 32-bit host=PC-201012302214
7. Mon Apr 16 08:50:54 [initandlisten]
8. Mon Apr 16 08:50:54 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are
9. limited to about 2 gigabytes of data
10. Mon Apr 16 08:50:54 [initandlisten] ** see http://blog.mongodb.org/post/13
11. 7788967/32-bit-limitations
12. Mon Apr 16 08:50:54 [initandlisten] ** with --journal, the limit is lower
13. Mon Apr 16 08:50:54 [initandlisten]
14. Mon Apr 16 08:50:54 [initandlisten] db version v2.0.4, pdfile version 4.5
15. Mon Apr 16 08:50:54 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506
16. cb21f8ebf
17. Mon Apr 16 08:50:54 [initandlisten] build info: windows sys.getwindowsversion(ma
18. jor=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB
19. _VERSION=1_42
20. Mon Apr 16 08:50:54 [initandlisten] options: { dbpath: "d:\data\db" }
21. Mon Apr 16 08:50:54 [websvr] admin web console waiting for connections on port 2
22. 8017
23. Mon Apr 16 08:50:54 [initandlisten] waiting for connections on port 27017
MongoDB服务端的默认连接端口:27017
5)、将MongoDB作为 Windows 服务随机启动
先创建D:\mongodb\logs\mongodb.log文件,用于存储MongoDB的日志文件, 再安装系统服务:
D:\mongodb\bin\mongod --dbpath=d:\data\db --logpath=d:\mongodb\log
s\mongodb.log --install
all output going to: d:\mongodb\logs\mongodb.log
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.
D:\>net start mongodb
Mongo DB 服务已经启动成功。
D:>
注意:如果需要卸载服务,执行命令:sc delete MongoDB
6)、客户端连接验证
新打开一个CMD输入:d:\mongodb\bin\mongo,如果出现下面提示,那么您就可以开始MongoDB之旅了:
1. d:\mongodb\bin\mongo
2. MongoDB shell version: 2.0.4
3. connecting to: test
4. >
7)、查看MongoDB日志
查看D:\mongodb\logs\mongodb.log文件,即可对MongoDB的运行情况进行查看或排错。