Windows平台下安裝MongoDB

來源:互聯網
上載者:User

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.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+0800 I CONTROL  [initandlisten] MongoDB starting : pid=40540 port=27017
dbpath=d:\MongoDB\data 64-bit host=hq1636
2015-10-29T09:26:11.719+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2015-10-29T09:26:11.722+0800 I CONTROL  [initandlisten] db version v3.0.6
2015-10-29T09:26:11.725+0800 I CONTROL  [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
2015-10-29T09:26:11.728+0800 I CONTROL  [initandlisten] build info: windows sys.getwindowsversion(major=6,
 minor=1, build=7601, platform=2, service_pa
ck='Service Pack 1') BOOST_LIB_VERSION=1_49
2015-10-29T09:26:11.731+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2015-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用戶端串連到mongod
C:\Users\1636>d:\MongoDB\Server\3.0\bin\mongo.exe
2015-10-29T09:28:12.427+0800 I CONTROL  Hotfix KB2731284 or later update is not installed, will zero-out data
files
MongoDB shell version: 3.0.6
connecting to: test            //此時已串連成功
> db.version()
3.0.6
> show dbs
local  0.078GB
//如果此時需要停止mongod,則直接在原來的視窗使用ctrl+c即可1
3、將Mongodb添加為Windows服務
D:\>mkdir d:\MongoDB\data
D:\>mkdir d:\MongoDB\log
D:\> -- Author : Leshami
D:\> -- Blog  :

更多MongoDB相關內容可以看看以下的有用連結: 

MongoDB 3.0 正式版發布下載 

CentOS編譯安裝MongoDB

CentOS 編譯安裝 MongoDB與mongoDB的php擴充

CentOS 6 使用 yum 安裝MongoDB及伺服器端配置

Ubuntu 13.04下安裝MongoDB2.4.3

MongoDB入門必讀(概念與實戰並重)

Ubunu 14.04下MongoDB的安裝指南

《MongoDB 權威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

Nagios監控MongoDB分區叢集服務實戰

基於CentOS 6.5作業系統搭建MongoDB服務

MongoDB 的詳細介紹:請點這裡
MongoDB 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.