2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

【學習筆記】MongoDB分布式學習筆記2

 CevenCheng 2011-07-11

學習文檔:Oreilly.Scaling.MongoDB.Jan.2011.pdf

學習內(nèi)容:

第一章:

1.1 Sharding是什么

Sharding是MongoDB中使用的一種將大的collection分配到幾個服務(wù)器(cluster)中的方法。

MongoDB與以往數(shù)據(jù)庫分表方法的最主要的區(qū)別就是MongoDB的每一項任務(wù)都是自動運行的。

Mongo完成分片的步驟很簡單:數(shù)據(jù)庫管理員告知mongoDB增加新的服務(wù)器mongod,MongoDB會自動完成在幾個服務(wù)器之間均衡負載。

1.2 Sharding的目的

封裝集群(make the cluster invisible)

確保隨時讀寫集群(make the cluster always available for reads and writes)

集群易擴展(let the cluster grow easily)

第二章:

2.1 分割數(shù)據(jù)

一個分片指的是集群當中的一個或者多個服務(wù)器,負責存儲數(shù)據(jù)集合當中的某些子集。

如果一個分片當中包含了多個服務(wù)器mongod,那么每一個mongod中的數(shù)據(jù)信息都是相同的。

因此可以將一個分片看作是一個備份數(shù)據(jù)集合。

MongoDB中存儲的數(shù)據(jù)一般以[a,b)的形式出現(xiàn),范圍是“最小從a開始包括a,最大到b不包括b”。

2.2 分割數(shù)據(jù)(Distributing Data)

需要考慮的問題:良好的可擴展性、均衡負載

使用的分片方法:多范圍分片

具體簡單描述:假設(shè)原來分為[a,f) [f,n) [n,p) [p,z]若增加了一個新的服務(wù)器,分為[a,d) [f,j) [n,p) [p,z] {[d,f)+[j,n)}

2.3 chunks是如何被創(chuàng)建的

我們把處于某個特定范圍內(nèi)的數(shù)據(jù)叫做一個chunk。

shard key是用來分割范圍也就是創(chuàng)建chunk的關(guān)鍵字。

2.4 將collections分片

當?shù)谝淮螢槟硞€collection分片的時候,MongoDB創(chuàng)建一個chunk,這個chunk的范圍是從最小的值,到最大的值。

如果以collection中的age為shard key,且初始chunk為[1,30],且年齡在20歲以下的占總數(shù)的一半

第一次分片會被分為[1,20] [20,30]

2.5 均衡負載

由均衡負載器(balancer)負責均衡負載的問題。《略》

2.6 路由服務(wù)器 mongos

mongos是負責用戶和集群交互的。它的工作就是負責隱藏集群內(nèi)部的分片信息,并且向用戶展現(xiàn)一個整齊的但服務(wù)器接口。

當客戶使用一個mongo集群的時候,客戶所有的讀寫操作都要通過mongos。mongos負責轉(zhuǎn)發(fā)所有用戶的請求到正確分片。

2.7 配置服務(wù)器 config server

2.8 集群架構(gòu)解析

典型地,一個MongoDB汲取包含三個過程:shards負責存儲數(shù)組,mongos負責路由請求信息,config server負責維持集群狀態(tài)。


========   學習筆記2  =============

轉(zhuǎn)載自 chenliying01
最終編輯 chenliying01

創(chuàng)建一個MongoDB Cluster

學習資料:Oreilly.Scaling.MongoDB.Jan.2011.pdf

第一步:選擇Shard Key

這一步很關(guān)鍵,對以后集群的可擴展性有深刻的影響,所以Shard Key的選取一定要謹慎。

這部分內(nèi)容多且雜,不在這里細說,具體參看學習資料第三章。

第二步:將一個已經(jīng)存在的collections分片

 

具體的部署步驟見下

【轉(zhuǎn)自】http://blog.csdn.net/daizhj/archive/2010/09/07/5868360.aspx

 模擬2個shard服務(wù)和一個config服務(wù), 均運行在10.0.4.85機器上,只是端口不同
       Shard1:27020
       Shard2:27021
       Config:27022
       Mongos啟動時默認使用的27017端口

       在C,D,E磁盤下分別建立如下文件夾:

               mongodb\bin 

               mongodb\db

       然后用CMD命令行依次打開相應(yīng)文件夾下的mongd文件:

       c:\mongodb\bin\mongod --dbpath c:\mongodb\db\ --port 27020

       d:\mongodb\bin\mongod --dbpath d:\mongodb\db\ --port 27021

       e:\mongodb\bin\mongod --configsvr --dbpath e:\mongodb\db\ --port 27022          (注:config配置服務(wù)器)

      啟動mongos時,默認開啟了27017端口

      e:\mongodb\bin\mongos --configdb 10.0.4.85:27022

      然后打下mongo:

      E:\mongodb\bin>mongo   回車  (有時加端口會造成下面的addshard命令出問題)

      > use admin
          switched to db admin
      > db.runCommand( { addshard : "10.0.4.85:27020", allowLocal : 1, maxSize:2 , minKey:1, maxKey:10} )  

         --添加sharding,maxsize單位是M,此處設(shè)置比較小的數(shù)值只為演示sharding效果

         { "shardAdded" : "shard0000", "ok" : 1 }
      > db.runCommand( { addshard : "10.0.4.85:27021", allowLocal : 1, minKey:1000} )
         { "shardAdded" : "shard0001", "ok" : 1 }      

          注:如果要移除sharding,可用下面寫法

          db.runCommand( { removeshard : "localhost:10000" } );

      > db.runCommand({listshards:1});   查看shard節(jié)點列表     

      {
        "shards" : [
                {
                        "_id" : "shard0000",
                        "host" : "10.0.4.85:27020"
                },
                {
                        "_id" : "shard0001",
                        "host" : "10.0.4.85:27021"
                }
        ],
        "ok" : 1
      }

       接下來創(chuàng)建相應(yīng)數(shù)據(jù)庫并設(shè)置其"可以sharding",新建自動切片的庫user001:

       > config = connect("10.0.4.85:27022")
       > config = config.getSisterDB("config")
       > dnt_mongodb=db.getSisterDB("dnt_mongodb");
           dnt_mongodb
       > db.runCommand({enablesharding:"dnt_mongodb"})
          { "ok" : 1 }
 
       注:一旦enable了個數(shù)據(jù)庫,mongos將會把數(shù)據(jù)庫里的不同數(shù)據(jù)集放在不同的分片上。除非數(shù)據(jù)集被分片(下面會設(shè)置),否則一個數(shù)據(jù)集的所有數(shù)據(jù)將放在一個分片上。

       > db.printShardingStatus();
   --- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      { "_id" : "shard0000", "host" : "10.0.4.85:27020" }
      { "_id" : "shard0001", "host" : "10.0.4.85:27021" }
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }
        { "_id" : "dnt_mongodb", "partitioned" : true, "primary" : "shard0000" }
  
       > db.runCommand( { shardcollection : "dnt_mongodb.posts1", key : {_id : 1}, unique: true } )  
          { "collectionsharded" : "dnt_mongodb.posts1", "ok" : 1 } 
    
        --使用shardcollection 命令分隔數(shù)據(jù)集,key自動生成。 

        如果要進行GridFS sharding,則需進行如下設(shè)置:
            db.runCommand( { shardcollection : "test.fs.chunks", key : { _id : 1 } } )
            {"ok" : 1} ,更多內(nèi)容參見http://eshilin.blog.163.com/blog/static/13288033020106215227346/
      
       > db.printShardingStatus()
   --- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      { "_id" : "shard0000", "host" : "localhost:27020" }
      { "_id" : "shard0001", "host" : "localhost:27021" }
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }
        { "_id" : "user001", "partitioned" : true, "primary" : "shard0000" }
                dnt_mongodb.posts1e chunks:
                        { "name" : { $minKey : 1 } } -->> { "name" : { $maxKey :
 1 } } on : shard0000 { "t" : 1000, "i" : 0 



 

 


    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多