1. 程式人生 > 程式設計 >HDFS的基本概念和體系結構

HDFS的基本概念和體系結構

1、HDFS的系統結構

cb2effc8389cc05bf5fcde353a07df49

2、NameNode

NameNode是Apache Hadoop HDFS體系結構中的主節點,用於維護和管理DataNode(從節點)上存在的塊。NameNode是一個非常高可用性的伺服器,用於管理檔案系統名稱空間並控制客戶端對檔案的訪問。HDFS體系結構的構建方式使使用者資料永遠不會駐留在NameNode上。資料僅駐留在DataNodes上。

Functions of NameNode:

  • It is the master daemon that maintains and manages the DataNodes (slave nodes)(它是維護和管理資料節點(從節點)的主守護程式)

  • It records the metadata of all the files stored in the cluster,e.g. The location of blocks stored,the size of the files,permissions,hierarchy,etc. There are two files associated with the metadata:(它記錄叢集中儲存的所有檔案的元資料,如儲存塊的位置、檔案的大小、許可權、層次結構等。有兩個與元資料關聯的檔案)

    • FsImage: It contains the complete state of the file system namespace since the start of the NameNode.(它包含從NameNode開始的檔案系統名稱空間的完整狀態)
    • EditLogs: It contains all the recent modifications made to the file system with respect to the most recent FsImage.(它包含最近對檔案系統所做的與最新的FsImage相關的所有修改)
  • It records each change that takes place to the file system metadata. For example,if a file is deleted in HDFS,the NameNode will immediately record this in the EditLog.(它記錄檔案系統元資料發生的每個更改。例如,如果在HDFS中刪除了一個檔案,NameNode將立即將其記錄到EditLog中。)

  • It regularly receives a Heartbeat and a block report from all the DataNodes in the cluster to ensure that the DataNodes are live.(它定期從叢集中的所有datanode接收一個心跳和一個塊報告,以確保datanode是活動的)

  • It keeps a record of all the blocks in HDFS and in which nodes these blocks are located.(它記錄HDFS中的所有塊以及這些塊所在的節點)

  • The NameNode is also responsible to take care of the replication factor of all the blocks which we will discuss in detail later in this HDFS tutorial blog.(NameNode還負責處理所有塊的複製因子)

  • In case of the DataNode failure,the NameNode chooses new DataNodes for new replicas,balance disk usage and manages the communication traffic to the DataNodes.(在DataNode失敗的情況下,NameNode為新的副本選擇新的DataNode,平衡磁碟使用,並管理到DataNode的通訊流量)

3、Secondary NameNode

第二名稱節點(Secondary NameNode,SNN)是用於定期合併名稱空間映象和映象編輯日誌的輔助守護程式。和名稱節點一樣,每個叢集都有一個第二名稱節點,在大規模部署的叢集條件下,一般第二名稱節點也獨自佔用一臺伺服器。

除了這兩個守護程式之外,還有第三個守護程式或稱為輔助NameNode的程式。輔助NameNode作為輔助守護程式與主NameNode併發工作。不要混淆次要的NameNode是備份的NameNode,因為它不是。

58d35490c1dcef307dd07740d55be20f

Functions of Secondary NameNode:

  • The Secondary NameNode is one which constantly reads all the file systems and metadata from the RAM of the NameNode and writes it into the hard disk or the file system.(輔助NameNode是一個不斷從NameNode的RAM中讀取所有檔案系統和元資料並將其寫入硬碟或檔案系統中的節點)
  • It is responsible for combining the EditLogs with FsImage from the NameNode. (它負責將editlog與NameNode中的FsImage結合起來)
  • It downloads the EditLogs from the NameNode at regular intervals and applies to FsImage. The new FsImage is copied back to the NameNode,which is used whenever the NameNode is started the next time.(它會定期從NameNode下載EditLogs,並將其應用於FsImage。

新的FsImage被複制回NameNode,下一次啟動NameNode時將使用該FsImage)

Hence,Secondary NameNode performs regular checkpoints in HDFS. Therefore,it is also called CheckpointNode(因此,輔助NameNode在HDFS中執行常規檢查點。因此,它也稱為CheckpointNode。)

4、DataNode

Functions of DataNode:

  • These are slave daemons or process which runs on each slave machine.(這些是從守護程式或程式在每個從機器上執行。)
  • The actual data is stored on DataNodes.(實際資料儲存在DataNodes上)
  • The DataNodes perform the low-level read and write requests from the file system’s clients.(資料節點執行來自檔案系統客戶端的低階讀寫請求)
  • They send heartbeats to the NameNode periodically to report the overall health of HDFS,by default,this frequency is set to 3 seconds.(它們定期向NameNode傳送心跳以報告HDFS的整體健康狀況,預設情況下,該頻率設定為3秒)

到現在為止,你一定已經意識到NameNode對我們來說非常重要。如果失敗了,我們就完了。但是不要擔心,我們將在下一篇Apache Hadoop HDFS架構部落格中討論Hadoop如何解決這個單點故障問題。

5、Block

block不過是硬碟上儲存資料的最小連續位置。通常,在任何檔案系統中,您都將資料儲存為塊的集合。類似地,HDFS將每個檔案儲存為塊,這些塊分散在整個Apache Hadoop叢集中。在Apache Hadoop 2.x中,每個塊的預設大小是128 MB(在Apache Hadoop 1.x中是64 MB),您可以根據需要進行配置。

image-20191109195948409

在HDFS中,不必將每個檔案都以配置的塊大小的精確倍數儲存(128 MB,256 MB等)。讓我們舉一個例子,我有一個大小為514 MB的檔案“ example.txt”,如上圖所示。假設我們使用的預設塊大小配置為128 MB。那麼,將建立多少個塊?5個:前四個塊的大小為128 MB。但是,最後一個塊的大小僅為2 MB。

現在,你一定在想為什麼我們需要這麼大的塊大小,即128兆位元組?

每當我們談到HDFS,我們就談到巨大的資料集,即兆兆位元組和千兆位元組的資料。因此,如果我們有一個比如4 KB的塊大小,就像在Linux檔案系統中一樣,我們會有太多的塊,因此會有太多的元資料。因此,管理這些數量的塊和元資料會產生巨大的開銷,這是我們不想要的

6、Replication Management

HDFS提供了一種以資料塊的形式在分散式環境中儲存大量資料的可靠方法。還複製這些塊以提供容錯能力。預設的複製因子是3,這也是可配置的。因此,如下圖所示,每個塊複製三次並儲存在不同的datanode上(考慮預設的複製因子)

54c0b332b83cdec383d83aa2b3c7acf7

NameNode定期從DataNode收集阻止報告以維護複製因子。因此,每當塊被過度複製或複製不足時,NameNode都會根據需要刪除或新增副本。

7、Rack

87c5cb756434a88fba0ff32a4828cacd

同樣,NameNode還確保所有副本都不儲存在同一機架或單個機架中。它遵循內建的機架感知演演算法,以減少延遲並提供容錯能力。考慮到複製因子為3,機架感知演演算法表示,一個塊的第一個副本將儲存在本地機架上,接下來的兩個副本將儲存在不同的(遠端)機架上。下面就是實際的Hadoop生產叢集的外觀。在這裡,可以裝多個有DataNodes的機架。

image-20191109200316535

Advantages of Rack Awareness:

So,now you will be thinking why do we need a Rack Awareness algorithm? The reasons are:

  • To improve the network performance: The communication between nodes residing on different racks is directed via switch. In general,you will find greater network bandwidth between machines in the same rack than the machines residing in different rack. So,the Rack Awareness helps you to have reduce write traffic in between different racks and thus providing a better write performance. Also,you will be gaining increased read performance because you are using the bandwidth of multiple racks.(為了提高網路效能:位於不同機架上的節點之間的通訊通過交換機進行。通常,您會發現同一機架中的機器之間的網路頻寬大於不同機架中的機器。因此,機架感知有助於減少不同機架之間的寫入流量,從而提供更好的寫入效能。此外,您將獲得更高的讀取效能,因為您正在使用多個機架的頻寬。)

  • To prevent loss of data: We don’t have to worry about the data even if an entire rack fails because of the switch failure or power failure. And if you think about it,it will make sense,as it is said that *never put all your eggs in the same basket.(為防止資料丟失:即使由於交換機故障或電源故障導致整個機架出現故障,我們也不必擔心資料。如果你仔細想想,這是有道理的,因為據說永遠不要把所有的雞蛋放在同一個籃子裡。

8、參考資料

www.edureka.co/blog/apache…