mongodb的安裝部署

來源:互聯網
上載者:User

標籤:webseven   mongodb   

1.下載軟體:
    wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.3.tgz

2.解壓安裝:
    tar -zxvf mongodb-linux-x86_64-rhel62-3.0.3.tgz
    mv mongodb-linux-x86_64-rhel62-3.0.3 /usr/local/
    cd /usr/local/
    ln -s mongodb-linux-x86_64-rhel62-3.0.3 mongodb
    mkdir -p data/db mkdir data/log
3.啟動:
    echo ‘export PATH=/usr/local/mongodb/bin:$PATH‘ >/etc/profile.d/mongodb.sh
    source /etc/profile.d/mongodb.sh
    命令列啟動:
    ./mongod --dbpath=../data/db --logpath=../data/log/mongod.log  --fork
    mongod為服務端程式  --dbpath指定資料的儲存目錄  --logpath指定日誌的儲存目錄  --fork指定以守護進程的方式啟動(注意,以守護進程方式啟動的話必須指定日誌儲存路徑)
    
    設定檔啟動:
    [[email protected] bin]# cat /etc/mongod.conf
    logpath=/usr/local/mongodb/data/log/mongod.log
    logappend=true
    fork=true
    dbpath=/usr/local/mongodb/data/db
    port=27017
    rest=true;
    #預設的mongodb會監控27017連接埠不甚安全,可以用--port參數進行設定其監控的連接埠。mongodb預設的會在服務的連接埠號碼加上1000的連接埠上啟動一個web伺服器,要使用web伺服器的有關內容,需要啟用--rest參數;
    #http://192.168.16.131:28017
    [[email protected] bin]#./mongod -f /etc/mongod.conf
4.mongodb的架構介紹:
    4.1資料邏輯結構
    MongoDB的資料邏輯結構由:資料庫(database)、集合(collections)、文檔(document)三部分組成。
    一個MongoDB支援多個資料庫,每個資料庫中包含多個集合(相當於關聯式資料庫中的表),每個集合中包含多個文檔(相當於關係型資料庫中表的一行)。

    4.2資料存放區結構
    MongoDB中,每個資料庫包含一個.ns和一個或多個資料檔案,其中,資料檔案會隨著資料量的增多而變多,例如Test資料庫的資料檔案就由Test.0、Test.1、Test.2等等組成。MongoDB採用預分配空間機制,每個預分配空間的檔案都採用0進行填充,由於集合中的資料增加,資料檔案每新分配一次,它的大小會是上一個檔案大小的2倍,資料庫裡每個集合和索引都對應一個命名空間,這些命名空間的中繼資料都儲存在.ns檔案裡。

    4.3BSON
    BSON是一種類似於json的二進位的儲存格式,Binary JSON,支援內建的文檔對象和數組對象,並且包含JSON所沒有的一些資料類型。MongoDB採用BSON這種結構來儲存資料和進行網路資料交換,把這個格式轉化成Document的概念,由於BSON是模式自由的,所以document也是模式自由的。
5.mongodb的簡單操作:
    [[email protected] ~]# mongo
    > 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
    > show users
    > show profile
    db.system.profile is empty
    Use db.setProfilingLevel(2) will enable profiling
    Use db.system.profile.find() to show raw profile entries
    #列出當前有哪些資料庫
    > show dbs;
    local  0.078GB
    > db.test_1.save({1:"AAA"});
    WriteResult({ "nInserted" : 1 })
    > db.test_1.save({2:"BBB"});
    WriteResult({ "nInserted" : 1 })
    > db.test_1.find();
    { "_id" : ObjectId("556d171a75f85e97eeec2f5b"), "1" : "AAA" }
    { "_id" : ObjectId("556d172375f85e97eeec2f5c"), "2" : "BBB" }
    > show dbs;
    local  0.078GB
    test   0.078GB
    #查看當前的資料庫
    > db
    test
    #列出當前資料庫中有哪些集合
    > show collections
    system.indexes
    test_1
6.關閉mongodb:
    [[email protected] ~]# mongo
    > use admin
    switched to db admin
    > db.shutdownServer();
    2015-06-01T19:35:45.155-0700 I NETWORK  DBClientCursor::init call() failed
    server should be down...
    2015-06-01T19:35:45.159-0700 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
    2015-06-01T19:35:45.159-0700 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
    2015-06-01T19:35:45.160-0700 I NETWORK  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

本文出自 “webseven” 部落格,請務必保留此出處http://webseven.blog.51cto.com/4388012/1657585

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.