1、下載
下載地址:http://www.mongodb.org/downloads
從其下載頁面就可以看出MongoDB還真的是不賴,支持各個操作系統,其驅動也有好多,其中就有我喜歡的Java和Python驅動,看樣子我真的應該學習下了。
我下載的是Windows 32 1.7.1版本的【http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.7.1.zip】(正在開發中,不穩定,不過學習可以了),它的說明中有個限制,數據最大隻能32GB,不過對於學習來說,已經足夠了。
2、安裝
安裝非常簡單,解壓就行了,我解壓後,放在D:/MongoDB目錄下。
爲了命令行的方便,我把D:/MongoDB/bin加到系統環境變量的path中了。
3、運行
D:\>mongod --dbpath D:/MongoDB/data
Sun Oct 24 15:07:05 MongoDB starting : pid=2472 port=27017 dbpath=D:/MongoDB/data 32-bit
** NOTE: This is a development version (1.7.1) of MongoDB.
** Not recommended for production.
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Sun Oct 24 15:07:05 db version v1.7.1, pdfile version 4.5
Sun Oct 24 15:07:05 git version: cee2d0d6816a704126c283401db24c949d5f52a3
Sun Oct 24 15:07:05 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LIB_VERSION=1_35
Sun Oct 24 15:07:05 [initandlisten] waiting for connections on port 27017
Sun Oct 24 15:07:05 [websvr] web admin interface listening on port 28017
由於是開發版,上面就有個警告,沒關係,忽略它。
最後兩行說明的數據庫端口和Web端口,分別是27017和28017,在瀏覽器中打開http://localhost:28017,可以看到其相關的一些信息。
4、安裝Windows服務
每次運行mongod --dbpath D:/MongoDB/data命令行來啓動MongoDB實在是不方便,就像我免安裝的MySQL一樣,我想把它作爲Windows服務,這樣就方便多了。
D:\MongoDB\bin>mongod --logpath D:\MongoDB\logs\MongoDB.log --logappend --dbpath D:\MongoDB\data --directoryperdb --serviceName MongoDB --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"'.
注意:這條命令要到MongoDB的bin目錄下運行,剛開始的時候,我就直接在D:\下運行,結果服務的可執行目錄爲【"D:\mongod" --logpath "D:\MongoDB\logs\MongoDB.log" --logappend --dbpath "D:\MongoDB\data" --directoryperdb --service 】,肯定是不對的。
該命令行指定了日誌文件:D:\MongoDB\logs\MongoDB.log,日誌是以追加的方式輸出的;
數據文件目錄:D:\MongoDB\data,並且參數--directoryperdb說明每個DB都會新建一個目錄;
Windows服務的名稱:MongoDB;
以上的三個參數都是可以根據自己的情況而定的,呵呵。
最後是安裝參數:--install,與之相對的是--remove
啓動MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB