在Ubuntu中安裝MongoDB

來源:互聯網
上載者:User

MongoDB部署實驗系列文章,MongoDB做為NoSQL資料庫,最近幾年持續升溫,越來越多的企業都開始嘗試用MongoDB代替原有Database做一些事情。MongoDB也在叢集,分區,複製上也有相當不錯的的表現。我通過將做各種MongoDB的部署實驗進行介紹。

前言

MongoDB作為一種文檔型的NoSQL資料庫,使用起來非常靈活,迴避了關係型資料庫前期的複雜資料庫設計。MongoDB儲存基於JSON格式,同時用Javascript做為資料庫操作語言,給了使用者無限想象的空間,可以通過編程在MongoDB伺服器中解決非常複雜的條件查詢的問題。

目錄

  1. MongoDB在Windows中安裝
  2. MongoDB在Linux Ubuntu中安裝
  3. 通過命令列用戶端訪問MongoDB
1 MongoDB在Windows中安裝

在Windows系統上安裝MongoDB資料庫是件非常簡單的事情,下載可執行安裝檔案(exe),雙擊安裝即可。:http://www.mongodb.org/downloads

  • MongoDB伺服器運行命令:MongoDB安裝目錄/bin/mongod.exe
  • MongoDB用戶端運行命令:MongoDB安裝目錄/bin/mongo.exe
2 MongoDB在Linux Ubuntu中安裝

本文使用的Linux是Ubuntu 12.04.2 LTS 64bit的系統,安裝MongoDB資料庫軟體包可以通過apt-get實現。但我們修要安裝官方提供MongoDB軟體源。

修改apt的source.list檔案,增加10gen的設定。

# 下載密鑰檔案~  sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.kVFab9XYw0 --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10gpg: 下載密鑰‘7F0CEB10’,從 hkp 伺服器 keyserver.ubuntu.comgpg: 密鑰 7F0CEB10:公開金鑰“Richard Kreuter <richard@10gen.com>”已匯入gpg: 沒有找到任何絕對信任的密鑰gpg: 合計被處理的數量:1gpg:               已匯入:1  (RSA: 1)# 在source.list中增加MongoDB源的配置~ echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.listdeb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen# 更新軟體源~ sudo apt-get update

在Linux Ubuntu中安裝MongoDB資料庫

#安裝MongoDB伺服器端~ sudo apt-get install mongodb-10gen

安裝完成後,MongoDB伺服器會自動啟動,我們檢查MongoDB伺服器程式

# 檢查MongoDB伺服器系統進程~  ps -aux|grep mongomongodb   6870  3.7  0.4 349208 39740 ?        Ssl  10:27   2:23 /usr/bin/mongod --config /etc/mongodb.conf# 通過啟動命令檢查MongoDB伺服器狀態~  netstat -nlt|grep 27017tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN# 通過啟動命令檢查MongoDB伺服器狀態~ sudo /etc/init.d/mongodb statusRather than invoking init scripts through /etc/init.d, use the service(8)utility, e.g. service mongodb statusSince the script you are attempting to invoke has been converted to anUpstart job, you may also use the status(8) utility, e.g. status mongodbmongodb start/running, process 6870# 通過系統服務檢查MongoDB伺服器狀態~ sudo service mongodb statusmongodb start/running, process 6870

通過web的控制台,查看MongoDB伺服器的狀態。在瀏覽器輸入 http://ip:28017 ,就可以開啟通過web的控制台了。

3. 通過命令列用戶端訪問MongoDB

安裝MongoDB伺服器,會自動地一起安裝MongoDB命令列用戶端程式。

在本機輸入mongo命令就可以啟動,用戶端程式訪問MongoDB伺服器。

~ mongoMongoDB shell version: 2.4.9connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, seehttp://docs.mongodb.org/Questions? Try the support grouphttp://groups.google.com/group/mongodb-user# 查看命令列協助> help        db.help()                    help on db methods        db.mycoll.help()             help on collection methods        sh.help()                    sharding helpers        rs.help()                    replica set helpers        help admin                   administrative help        help connect                 connecting to a db help        help keys                    key shortcuts        help misc                    misc things to know        help mr                      mapreduce        show dbs                     show database names        show collections             show collections in current database        show users                   show users in current database        show profile                 show most recent system.profile entries with time >= 1ms        show logs                    show the accessible logger names        show log [name]              prints out the last segment of log in memory, 'global' is default        use <db_name>                set current database        db.foo.find()                list objects in collection foo        db.foo.find( { a : 1 } )     list objects in foo where a == 1        it                           result of the last line evaluated; use to further iterate        DBQuery.shellBatchSize = x   set default number of items to display on shell        exit                         quit the mongo shell

MongoDB伺服器,預設情況下是允許外部存取的。這樣單節的MongoDB,我們已經成功地安裝在Linux Ubuntu系統中。

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

MongoDB備份與恢複

CentOS編譯安裝MongoDB

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

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

Ubuntu 13.04下安裝MongoDB2.4.3

如何在MongoDB中建立新資料庫和集合

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

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

聯繫我們

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