概覽
離線fsimage查看器 是一個將 hdfs fsimage 文件的內容轉儲為人類可讀格式的工具,並提供只讀的 WebHDFS API,以允許離線分析和檢查 Hadoop 集群的名稱空間。該工具能夠相對快速地處理非常大的fsimage文件。該工具處理 Hadoop 2.4及以上版本中包含的格式。如果您希望處理舊的格式,可以使用 Hadoop 2.3或 oiv _ legacy Command 的離線fsimage查看器。如果工具不能處理fsimage文件,它將干凈地退出。離線fsimage查看器不需要運行 Hadoop 集群; 它在操作中完全離線。
離線fsimage查看器提供了幾個輸出處理器:
- Web 是默認的輸出處理器。它啟動一個公開只讀的 WebHDFS API 的 HTTP 服務器。用戶可以使用 HTTP REST API 交互式地調查名稱空間。
- XML 創建一個 fsimage 的 XML 文檔,並包含 fsimage 中的所有信息。這個處理器的輸出可以通過 XML 工具進行自動化處理和分析。由於 XML 語法的冗長性,該處理器還將生成最大量的輸出。
- FileDistribution 是分析名稱空間fsimage文件大小的工具。為了運行該工具,應該通過指定 maxSize 和一個步驟來定義一個整數范圍[0,maxSize ]。整數的范圍被划分為大小為[0,s [1] ,... ,s [ n-1] ,maxSize ]的部分,處理器計算系統中有多少文件落入每個部分[ s [ i-1] ,s [ i ]]中。請注意,大於 maxSize 的文件總是落入最后一個段中。默認情況下,輸出文件格式為選項卡分隔的兩列表: Size 和 NumFiles。其中 Size 表示段的開始,numFiles 表示形成映像的文件數,其大小在該段中。通過指定 option-format,輸出文件將以人類可讀的方式格式化,而不是在 Size 列中顯示大量字節。此外,“大小”列將更改為“大小范圍”列。
用法
Web Processor
Web 處理器啟動一個 HTTP 服務器,該服務器公開只讀的 WebHDFS API。用戶可以指定要偵聽的地址(默認情況下 localhost: 5978)。
bash$ bin/hdfs oiv -i fsimage
14/04/07 13:25:14 INFO offlineImageViewer.WebImageViewer: WebImageViewer
started. Listening on /127.0.0.1:5978. Press Ctrl+C to stop the viewer.
用戶可以通過以下 shell 命令訪問查看器並獲取 fsimage 的信息:
bash$ bin/hdfs dfs -ls webhdfs://127.0.0.1:5978/
Found 2 items
drwxrwx--* - root supergroup 0 2014-03-26 20:16 webhdfs://127.0.0.1:5978/tmp
drwxr-xr-x - root supergroup 0 2014-03-31 14:08 webhdfs://127.0.0.1:5978/user
要獲取所有文件和目錄的信息,只需使用以下命令:
bash$ bin/hdfs dfs -ls -R webhdfs://127.0.0.1:5978/
用戶還可以通過 HTTP REST API 獲得 JSON 格式的 filestat。
bash$ curl -i http://127.0.0.1:5978/webhdfs/v1/?op=liststatus
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 252
{"FileStatuses":{"FileStatus":[
{"fileId":16386,"accessTime":0,"replication":0,"owner":"theuser","length":0,"permission":"755","blockSize":0,"modificationTime":1392772497282,"type":"DIRECTORY","group":"supergroup","childrenNum":1,"pathSuffix":"user"}
]}}
Web 處理器現在支持以下操作:
- 列表狀態
- Getfileatus
- GETACLSTATUS
- GETXATTRS
- LISTXATTRS
- [CONTENTSUMMARY] (./WebHDFS.html#Get_Content_Summary_of_a_Directory)
XML 處理器
XML 處理器用於轉儲文件中的所有內容。用戶可以通過-i 和-o 命令行指定輸入和輸出文件。
bash$ bin/hdfs oiv -p XML -i fsimage -o fsimage.xml
這將創建一個名為 fsimage.xml 的文件,其中包含 fsimage 中的所有信息。對於非常大的fsimage文件,這個過程可能需要幾分鍾。
將離線fsimage查看器與 XML 處理器一起應用將導致以下輸出:
<?xml version="1.0"?>
<fsimage>
<NameSection>
<genstampV1>1000</genstampV1>
<genstampV2>1002</genstampV2>
<genstampV1Limit>0</genstampV1Limit>
<lastAllocatedBlockId>1073741826</lastAllocatedBlockId>
<txid>37</txid>
</NameSection>
<INodeSection>
<lastInodeId>16400</lastInodeId>
<inode>
<id>16385</id>
<type>DIRECTORY</type>
<name></name>
<mtime>1392772497282</mtime>
<permission>theuser:supergroup:rwxr-xr-x</permission>
<nsquota>9223372036854775807</nsquota>
<dsquota>-1</dsquota>
</inode>
...remaining output omitted...
ReverseXML 處理器
ReverseXML 處理器與 XML 處理器相反。用戶可以通過-i 和-o 命令行指定輸入 XML 文件和輸出 fsimage 文件。
bash$ bin/hdfs oiv -p ReverseXML -i fsimage.xml -o fsimage
這將從一個 XML 文件重新構造一個 fsimage。
FileDistribution處理器
FileDistribution 處理器可以分析名稱空間映像中的文件大小。用戶可以通過-maxSize 和-step 命令行指定,maxSize (默認值為128gb)和 step (默認值為2mb)。
bash$ bin/hdfs oiv -p FileDistribution -maxSize maxSize -step size -i fsimage -o output
處理器將計算系統中有多少文件落入每個段中。輸出文件格式化為標簽分隔的兩列表格,如下面的輸出所示:
Size NumFiles
4 1
12 1
16 1
20 1
totalFiles = 4
totalDirectories = 2
totalBlocks = 4
totalSpace = 48
maxFileSize = 21
為了使輸出結果看起來更具可讀性,用戶還可以指定-format 選項。
bash$ bin/hdfs oiv -p FileDistribution -maxSize maxSize -step size -format -i fsimage -o output
這將產生以下產出:
Size Range NumFiles
(0 B, 4 B] 1
(8 B, 12 B] 1
(12 B, 16 B] 1
(16 B, 21 B] 1
totalFiles = 4
totalDirectories = 2
totalBlocks = 4
totalSpace = 48
maxFileSize = 21
Delimited處理器
Delimited處理程序生成 fsimage 的文本表示形式,每個元素之間用分隔符字符串分隔(缺省情況下為 t)。用戶可以通過分隔符選項指定新的分隔符字符串。
bash$ bin/hdfs oiv -p Delimited -delimiter delimiterString -i fsimage -o output
此外,用戶可以通過以下命令指定一個臨時目錄來緩存中間結果:
bash$ bin/hdfs oiv -p Delimited -delimiter delimiterString -t temporaryDir -i fsimage -o output
如果沒有設置,帶分隔符的處理器將在輸出文本之前在內存中構造名稱空間。這個處理器的輸出結果應該類似於下面的輸出:
Path Replication ModificationTime AccessTime PreferredBlockSize BlocksCount FileSize NSQUOTA DSQUOTA Permission UserName GroupName
/ 0 2017-02-13 10:39 1970-01-01 08:00 0 0 0 9223372036854775807 -1 drwxr-xr-x root supergroup
/dir0 0 2017-02-13 10:39 1970-01-01 08:00 0 0 0 -1 -1 drwxr-xr-x root supergroup
/dir0/file0 1 2017-02-13 10:39 2017-02-13 10:39 134217728 1 1 0 0 -rw-r--r-- root supergroup
/dir0/file1 1 2017-02-13 10:39 2017-02-13 10:39 134217728 1 1 0 0 -rw-r--r-- root supergroup
/dir0/file2 1 2017-02-13 10:39 2017-02-13 10:39 134217728 1 1 0 0 -rw-r--r-- root supergroup
Options
Flag | Description |
---|---|
-i |
--inputFile input file |
-o |
--outputFile output file |
-p |
--processor processor |
-addr address |
Specify the address(host:port) to listen. (localhost:5978 by default). This option is used with Web processor. |
-maxSize size |
Specify the range [0, maxSize] of file sizes to be analyzed in bytes (128GB by default). This option is used with FileDistribution processor. |
-step size |
Specify the granularity of the distribution in bytes (2MB by default). This option is used with FileDistribution processor. |
-format |
Format the output result in a human-readable fashion rather than a number of bytes. (false by default). This option is used with FileDistribution processor. |
-delimiter arg |
Delimiting string to use with Delimited processor. |
-t |
--temp temporary dir |
-h |
--help |
分析結果
離線fsimage查看器 可以輕松收集有關 hdfs 名稱空間的大量數據。然后,可以使用這些信息探索文件系統使用模式,或者查找符合任意條件的特定文件,以及其他類型的名稱空間分析。
oiv_legacy Command
由於基於 protocolbuffer 的 fsimage (HDFS-5698)引入了內部布局變化,如果希望在沒有大量內存的情況下進行處理或使用這些處理器,可以使用 oiv _ legacy 命令(與 Hadoop 2.3中的 oiv 相同)。
用法
-
設置 dfs.namenode.legacy-oiv-image。在檢查點期間,將其命名空間保存為舊的 fsimage 格式。
-
對舊格式 fsimage 使用 oiv _ legacy 命令。
bash$ bin/hdfs oiv_legacy -i fsimage_old -o output
Options
Flag | Description |
---|---|
-i |
--inputFile input file |
-o |
--outputFile output file |
-p |
--processor processor |
-maxSize size |
Specify the range [0, maxSize] of file sizes to be analyzed in bytes (128GB by default). This option is used with FileDistribution processor. |
-step size |
Specify the granularity of the distribution in bytes (2MB by default). This option is used with FileDistribution processor. |
-format |
Format the output result in a human-readable fashion rather than a number of bytes. (false by default). This option is used with FileDistribution processor. |
-skipBlocks |
Do not enumerate individual blocks within files. This may save processing time and outfile file space on namespaces with very large files. The Ls processor reads the blocks to correctly determine file sizes and ignores this option. |
-printToScreen |
Pipe output of processor to console as well as specified file. On extremely large namespaces, this may increase processing time by an order of magnitude. |
-delimiter arg |
When used in conjunction with the Delimited processor, replaces the default tab delimiter with the string specified by arg. |
-h |
--help |