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.exe
Router mongos.exe
Client mongo.exe
MonitoringTools mongostat.exe, mongotop.exe
ImportExportTools mongodump.exe, mongorestore.exe, mongoexport.exe,mongoimport.exe
MiscellaneousTools 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\log Step 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\db Step 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" --install Step 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 caption Caption Microsoft Windows 7 Ultimate C:\Users\1636>wmic os get osarchitecture OSArchitecture 64-bit 使用下载的msi文件开始安装到指定文件夹,如本例中的D:\MongoDB\Server\3.0\
2、配置环境变量
//如本例中将D:\MongoDB\Server\3.0\bin添加到系统环境变量PATH ;D:\MongoDB\Server\3.0\bin D:\>mkdir d:\MongoDB\data D:\>d:\MongoDB\Server\3.0\bin\mongod.exe --dbpath d:\MongoDB\data 2015-10-29T09:26:11.498+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files 2015-10-29T09:26:11.508+0800 I JOURNAL [initandlisten] journal dir=d:\MongoDB\data\journal 2015-10-29T09:26:11.509+0800 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed 2015-10-29T09:26:11.611+0800 I JOURNAL [durability] Durability thread started 2015-10-29T09:26:11.613+0800 I JOURNAL [journal writer] Journal writer thread started 2015-10-29T09:26:11.718+08