Windows平台下安装MongoDB

来源:转载

MongoDB以其操作简单、完全免费、源码公开、随时下载等特点,被广泛应用于各种大型门户网站和专业网站,大大降低了运营成本。本文描述了在Widows平台下的安装步骤及其过程,供大家参考。

一、主要步骤

1、查看当前使用的Windows版本及架构

wmic os get caption
wmic os get osarchitecture

2、下载对应的版本

http://www.mongodb.org/downloads

3、配置mongdb

创建存放数据文件的路径
md /data/db
You can specify an alternate path for data files using the –dbpath option to mongod.exe, for example:
C:/mongodb/bin/mongod.exe –dbpath d:/test/mongodb/data

If your path includes spaces, enclose the entire path in double quotes, for example:
C:/mongodb/bin/mongod.exe –dbpath “d:/test/mongo db data”

4、启动mongodb

To start MongoDB, run mongod.exe. For example, from the Command Prompt:
C:/mongodb/bin/mongod.exe
This starts the main MongoDB database process. The waiting for connections message in the console
output indicates that the mongod.exe process is running successfully.

5、连接到mongodb

To connect to MongoDB through the mongo.exe shell, open another Command Prompt.
C:/mongodb/bin/mongo.exe

6、终止mongodb

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running

二、Mongodb的主要组件

Component Set Binaries--------------- --------------------Server mongod.exeRouter mongos.exeClient mongo.exeMonitoringTools mongostat.exe, mongotop.exeImportExportTools mongodump.exe, mongorestore.exe, mongoexport.exe,mongoimport.exeMiscellaneousTools bsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe

三、配置Mongodb作为Windows服务

Step 1: Open an Administrator command prompt ###打开一个命令行窗口Step 2: Create directories. ###创建数据库数据及日志目录 mkdir c:/data/db mkdir c:/data/logStep 3: Create a configuration file ###创建配置文件 Create a configuration file. The file must set systemLog.path. Include additional configuration options as appropriate. For example, create a file at C:/mongodb/mongod.cfg that specifies both systemLog.path and storage.dbPath: systemLog: destination: file path: c:/data/log/mongod.log storage: dbPath: c:/data/dbStep 4: Install the MongoDB service. Install the MongoDB service by starting mongod.exe with the --install option and the -config option to specify the previously created configuration file. "C:/mongodb/bin/mongod.exe" --config "C:/mongodb/mongod.cfg" --installStep 5: Start the MongoDB service. net start MongoDB Step 6: Stop or remove the MongoDB service as needed. To stop the MongoDB service use the following command: net stop MongoDB To remove the MongoDB service use the following command: "C:/mongodb/bin/mongod.exe" --remove

四、安装演示

1、安装

C:/Users/1636>wmic os get captionCaptionMicrosoft Windows 7 UltimateC:/Users/1636>wmic os get osarchitectureOSArchitecture64-bit使用下载的msi文件开始安装到指定文件夹,如本例中的D:/MongoDB/Server/3.0/

2、配置环境变量

//如本例中将D:/MongoDB/Server/3.0/bin添加到系统环境变量PATH ;D:/MongoDB/Server/3.0/binD:/>mkdir d:/MongoDB/dataD:/>d:/MongoDB/Server/3.0/bin/mongod.exe --dbpath d:/MongoDB/data2015-10-29T09:26:11.498+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files2015-10-29T09:26:11.508+0800 I JOURNAL [initandlisten] journal dir=d:/MongoDB/data/journal2015-10-29T09:26:11.509+0800 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed2015-10-29T09:26:11.611+0800 I JOURNAL [durability] Durability thread started2015-10-29T09:26:11.613+0800 I JOURNAL [journal writer] Journal writer thread started2015-10-29T09:26:11.718+0800 I CONTROL [initandlisten] MongoDB starting : pid=40540 port=27017 dbpath=d:/MongoDB/data 64-bit host=hq16362015-10-29T09:26:11.719+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R22015-10-29T09:26:11.722+0800 I CONTROL [initandlisten] db version v3.0.62015-10-29T09:26:11.725+0800 I CONTROL [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f22015-10-29T09:26:11.728+0800 I CONTROL [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_492015-10-29T09:26:11.731+0800 I CONTROL [initandlisten] allocator: tcmalloc2015-10-29T09:26:11.737+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "d:/MongoDB/data" } }2015-10-29T09:26:11.906+0800 I NETWORK [initandlisten] waiting for connections on port 27017 //此处已表明mongodb已启动等待连接在打开一个单独的cmd窗口,使用mongo客户端连接到mongodC:/Users/1636>d:/MongoDB/Server/3.0/bin/mongo.exe2015-10-29T09:28:12.427+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out datafilesMongoDB shell version: 3.0.6connecting to: test //此时已连接成功> db.version()3.0.6> show dbslocal 0.078GB//如果此时需要停止mongod,则直接在原来的窗口使用ctrl+c即可

3、将Mongodb添加为Windows服务

D:/>mkdir d:/MongoDB/dataD:/>mkdir d:/MongoDB/logD:/> -- Author : LeshamiD:/> -- Blog : http://blog.csdn.net/leshamiD:/>echo logpath=d:/MongoDB/log/mongd.log> "d:/MongoDB/mongod.cfg"D:/>echo dbpath=d:/MongoDB/data>> "d:/MongoDB/mongod.cfg"D:/>type d:/MongoDB/mongod.cfglogpath=d:/MongoDB/log/mongd.logdbpath=d:/MongoDB/dataD:/>sc.exe create MongoDB binPath= "D:/MongoDB/Server/3.0/bin/mongod.exe --service --config=D:/MongoDB/mongod.cfg"[SC] CreateService SUCCESSD:/>net start MongoDBThe MongoDB service is starting.The MongoDB service was started successfully.D:/>net stop MongoDBThe MongoDB service is stopping.The MongoDB service was stopped successfully.

4、修复Bug:Hotfix KB2731284

https://support.microsoft.com/zh-cn/kb/2731284
Linux下快速安装MongoDB



分享给朋友:
您可能感兴趣的文章:
随机阅读: