原文地址:http://www.cnblogs.com/yudigen/archive/2012/01/12/2320212.html
下面主要是我在Windows上(Win7)安裝、運行、安裝Windows服務的筆記,以作備忘。
1、下載
下載地址:http://www.mongodb.org/downloads
從其下載頁面就可以看出MongoDB還真的是不賴,支持各個操作系統,其驅動也有好多,目前我用的是.net平臺的。
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:27017,可以看到其相關的一些信息。
4、安裝Windows服務
每次運行mongod --dbpath D:/MongoDB/data命令行來啓動MongoDB實在是不方便,把它作爲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;
以上的三個參數都是可以根據自己的情況而定的,可以通過 mongod --help 查看更多的參數 。
最後是安裝參數:--install,與之相對的是--remove
啓動MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB
以上是我的安裝MongoDB的初體驗,希望能與各位朋友一起學習MongoDB!