window下MongoDB的配置與安裝

來源:互聯網
上載者:User

標籤:記錄檔   cto   http   lenovo   tle   ros   red   x86   art   

前言

MongoDB 是一個基於分布式檔案儲存體的資料庫。由C++語言編寫,支援Windows,Linux,OSX,Solaris等平台,預設連接埠為27017,是一個效率非常高的nosql資料庫。

我的測試環境:window10  64位

我的安裝路徑:D:\mongodb

我學習mongodb的筆記本:MongoDB

配置mongodb我也遇到了兩個關鍵性的問題,記錄這篇部落格希望搭建mongodb的同行者,可以順利完成配置。

安裝

:http://www.mongodb.org/downloads

選擇下載版本:

我下載的是最新版本的zip格式。

需要注意的是:1、從mongodb2.2版本開始,mongodb不在支援windowXp

參考:心知部落格

PLATFORM SUPPORTStarting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB.
2、如果運行系統為windows server 2008 R2 或者 window 7,需要進入微軟官網下載補丁
IMPORTANTIf you are running any edition of Windows Server 2008 R2 or Windows 7, please install a hotfix to resolve an issue with memory mapped files on Windows.

並且這裡需要特別注意:
下載完成後會得到一個exe檔案,但是這裡並不能直接對這個檔案進行安裝,需要先將其解壓,解壓後得到 Windows6.1-KB2731284-v3-x64.msu 檔案,這時候才可以進行安裝,之後重啟即可

3、64位的MongoDB將不能在32位的windows上運行啟動配置1、建立一個用於存放mongodb資料的目錄,

這裡我建立在D:\mongodb\data\db,開啟cmd(這裡我用的Git Bash),進入到mongodb的bin目錄,運行下面命令

mongod --dbpath="D:\mongodb\data\db"

 

然後出現了我遇到的第一個問題,

2016-12-29T22:30:02.229+0800 I CONTROL  [initandlisten] MongoDB starting : pid=10220 port=27017 dbpath=C:\Program Files\MongoDB\db 64-bit host=Lenovo2016-12-29T22:30:02.234+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R22016-12-29T22:30:02.235+0800 I CONTROL  [initandlisten] db version v3.4.12016-12-29T22:30:02.237+0800 I CONTROL  [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd72016-12-29T22:30:02.238+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1t-fips  3 May 20162016-12-29T22:30:02.240+0800 I CONTROL  [initandlisten] allocator: tcmalloc2016-12-29T22:30:02.241+0800 I CONTROL  [initandlisten] modules: none2016-12-29T22:30:02.241+0800 I CONTROL  [initandlisten] build environment:2016-12-29T22:30:02.243+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl2016-12-29T22:30:02.244+0800 I CONTROL  [initandlisten]     distarch: x86_642016-12-29T22:30:02.245+0800 I CONTROL  [initandlisten]     target_arch: x86_642016-12-29T22:30:02.246+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "C:\Program Files\MongoDB\db" } }2016-12-29T22:30:02.249+0800 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: C:\Program Files\MongoDB\db, terminating2016-12-29T22:30:02.251+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...2016-12-29T22:30:02.255+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...2016-12-29T22:30:02.256+0800 I CONTROL  [initandlisten] now exiting2016-12-29T22:30:02.257+0800 I CONTROL  [initandlisten] shutting down with code:100

最後出現shutting down with code :100,

在心知部落格我找到了答案,原因在於:我們進入的命令提示字元只是普通模式,所以出現無法建立檔案的問題,切換到管理員模式,重新運行命令:

然後就可以正常啟動。

2、我把mongo命令添加到path環境變數中,

這樣我就不需要每次都進入到mongodb下的bin中執行mongo命令了。

 

3、把mongodb設定為windows服務,

採用管理員:命令提示字元,切換到安裝mongodb目錄的bin目錄,運行下面命令,把MongoDB設定為Windows服務:

 

mongod --dbpath="D:\mongodb\data\db" --logpath="D:\mongodb\data\log" --logappend --directoryperdb --serviceName "MongoDB" --serviceDisplayName "MongoDB" --install

參數解讀:

--dbpath="D:\mongodb\data\db"     mongodb的資料目錄
--logpath="D:\mongodb\data\log" --logappend   指定記錄檔。並且日誌是以追加的方式輸出的
--serviceName "MongoDB" --serviceDisplayName "MongoDB"   windows伺服器名稱和顯示名稱為MongoDB
--directoryperdb   表示每個DB都會建立一個目錄

--install        進行安裝,與之相對的是--remove

啟動停止mongodb服務的命令
啟動MongoDB:net start MongoDB停止MongoDB:net stop MongoDB

 

然後我遇到了第二個問題,伺服器安裝成功之後,進行啟動,發現無法啟動,查看log記錄檔,有這樣的資訊:

2016-12-29T23:51:23.705+0800 I CONTROL  [initandlisten] options: { service: true, storage: { dbPath: "D:\mongodb\data\db", directoryPerDB: true }, systemLog: { destination: "file", logAppend: true, path: "D:\mongodb\data\log\mongodb.log" } }2016-12-29T23:51:23.706+0800 I -        [initandlisten] Detected data files in C:\Program Files\MongoDB\db created by the ‘wiredTiger‘ storage engine, so setting the active storage engine to ‘wiredTiger‘.2016-12-29T23:51:23.707+0800 I STORAGE  [initandlisten] exception in initAndListen: 72 Requested option conflicts with current storage engine option for directoryPerDB; you requested true but the current server storage is already set to false and cannot be changed, terminating2016-12-29T23:51:23.707+0800 I NETWORK  [serviceStopWorker] shutdown: going to close listening sockets...2016-12-29T23:51:23.707+0800 I NETWORK  [serviceStopWorker] shutdown: going to flush diaglog...2016-12-29T23:51:23.707+0800 I CONTROL  [serviceStopWorker] now exiting2016-12-29T23:51:23.707+0800 I CONTROL  [serviceStopWorker] shutting down with code:49

 

大致意思就是說儲存引擎衝突,(之前在命令列啟動過mongodb服務,然後就在資料目錄產生了資料檔案)

這個時候我們可以到資料目錄中找到storage.bson這個檔案,刪除即可。

 

我們可以通過添加到環境變數中的mongo命令來啟動資料庫,這樣我們就可以通過命令列來執行一些操作了

 

 到這裡我們已經能正常使用mongodb來執行工作了,我遇到的兩個問題在心知部落格中也找到了答案。
後記

  我的mongodb的筆記本主要是記錄mongo文檔的學習情況,會不斷更新。

  

  部落格會分享一些開發中的心得以及學習階段遇到的問題最後得以解決,都會堅持下去,也很開心每天都能看到部落格園裡有很多人分享知識。

 

window下MongoDB的配置與安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.