Running MongoDB on Windows

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   使用   ar   檔案   

我不久前使用MongoDB,根據development box(編譯好的開發包,雙擊安裝)逐步設定並最後運行是很容易的,但是我想參考文檔進行設定(使用zip包)

安裝 MongoDB

從官網下載MongoDB,按照自己的需求下載不同版本,我下載的是 64-bit Zip檔案。 .msi檔案是安裝到Program Files目錄下的(預設),但是我更喜歡把安裝檔案(zip包)和資料庫檔案(建立資料庫後產生)放在一起使而且不必使用Admin運行

取出zip檔案放到 c:\MongoDB

進入 c:\MongoDB,建立一個data子目錄,進入並建立db子檔案夾和log子檔案夾,bin檔案夾已經存在,最後

你的檔案夾結構如下,

 

c:\mongodb    \bin    \data        \db        \log

配置 MongoDB

添加一個檔案  c:\MongoDB\mongod.cfg 包含以下內容

systemLog:   destination: file   path: c:\mongodb\data\log\mongodb.log   logAppend: truestorage:    dbPath: c:\mongodb\data\dbnet:   bindIp: 127.0.0.1   port: 27017

log和db的路徑還有連接埠號碼都是預設,需要改變也很容易。注意ip只綁定127.0.0.1,因為那是不安全的,所以我不想暴露在network上,更多配置選項 see the documentation.

測試MongoDB

運行以下命令

C:\MongoDb\bin>mongod.exe -f ..\mongod.cfg

然後在另一個 command window(win+R),運行服務確定他能成功運行。

當我connecting時出現以下錯誤,所以我關閉了服務

D:\MongoDb\bin>mongoMongoDB shell version: 2.6.1connecting to: test> use adminswitched to db admin> db.shutdownServer()2014-06-10T14:28:35.567-0400 DBClientCursor::init call() failedserver should be down...2014-06-10T14:28:35.571-0400 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed2014-06-10T14:28:36.579-0400 warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.2014-06-10T14:28:36.579-0400 reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn‘t connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed> exitbye

將其作為一個service安裝

我們現在知道我們的配置是正確的,所以我想去安裝一個service讓他總是運行

 

啟動一個 Administrator command prompt(擁有管理員權限)

win7 :win+R  進入cmd ,之後按住 CTRL+SHIFT+ENTER

win8:WIN+X 之後按A

現在運行命令

sc.exe create MongoDB binPath="C:\MongoDB\bin\mongod.exe --service --config=C:\MongoDB\mongod.cfg" DisplayName="MongoDB 2.6 Standard" start="auto"

你應該看到

[SC] CreateService SUCCESS

現在你可以根據以下命令開啟和關閉服務(如果不能啟動,手動開啟服務 工作管理員-服務)

net start MongoDBnet stop MongoDB

如果你想卸載服務

sc.exe delete MongoDB

原文串連 http://www.alteridem.net/2014/06/10/running-mongodb-on-windows/

Running MongoDB on Windows

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.