大資料技術之_04_Hadoop學習_01_HDFS_HDFS概述+HDFS的Shell操作(開發重點)+HDFS客戶端操作(開發重...
第1章 HDFS概述
1.1 HDFS產出背景及定義

其他檔案管理系統:

1.2 HDFS優缺點
優點

缺點

1.3 HDFS組成架構
1)NameNode(nn)和DataNode(dn)

2)Client和Secondary NameNode(2nn)

1.4 HDFS檔案塊大小(面試重點)

思考:為什麼塊的大小不能設定太小,也不能設定太大?

傳統硬碟HDD(Hard Disk Drive)傳輸速率:100MB/s
固態硬碟SSD(Solid State Drive)傳輸速率:500MB/s
混合硬碟HHD(Hybrid Harddrive)傳輸速率:300MB/s
PCIe固態硬碟SSD(Solid State Drive)傳輸速率:1500MB/s
第2章 HDFS的Shell操作(開發重點)
1、基本語法
bin/hadoop fs 具體命令 OR bin/hdfs dfs 具體命令
dfs是fs的實現類。
2、命令大全
[[atguigu@hadoop102 hadoop-2.7.2]$ bin/hadoop fs Usage: hadoop fs [generic options] [-appendToFile <localsrc> ... <dst>] [-cat [-ignoreCrc] <src> ...] [-checksum <src> ...] [-chgrp [-R] GROUP PATH...] [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] [-chown [-R] [OWNER][:[GROUP]] PATH...] [-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>] [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-count [-q] [-h] <path> ...] [-cp [-f] [-p | -p[topax]] <src> ... <dst>] [-createSnapshot <snapshotDir> [<snapshotName>]] [-deleteSnapshot <snapshotDir> <snapshotName>] [-df [-h] [<path> ...]] [-du [-s] [-h] <path> ...] [-expunge] [-find <path> ... <expression> ...] [-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-getfacl [-R] <path>] [-getfattr [-R] {-n name | -d} [-e en] <path>] [-getmerge [-nl] <src> <localdst>] [-help [cmd ...]] [-ls [-d] [-h] [-R] [<path> ...]] [-mkdir [-p] <path> ...] [-moveFromLocal <localsrc> ... <dst>] [-moveToLocal <src> <localdst>] [-mv <src> ... <dst>] [-put [-f] [-p] [-l] <localsrc> ... <dst>] [-renameSnapshot <snapshotDir> <oldName> <newName>] [-rm [-f] [-r|-R] [-skipTrash] <src> ...] [-rmdir [--ignore-fail-on-non-empty] <dir> ...] [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]] [-setfattr {-n name [-v value] | -x name} <path>] [-setrep [-R] [-w] <rep> <path> ...] [-stat [format] <path> ...] [-tail [-f] <file>] [-test -[defsz] <path>] [-text [-ignoreCrc] <src> ...] [-touchz <path> ...] [-truncate [-w] <length> <path> ...] [-usage [cmd ...]] Generic options supported are -conf <configuration file>specify an application configuration file -D <property=value>use value for given property -fs <local|namenode:port>specify a namenode -jt <local|resourcemanager:port>specify a ResourceManager -files <comma separated list of files>specify comma separated files to be copied to the map reduce cluster -libjars <comma separated list of jars>specify comma separated jar files to include in the classpath. -archives <comma separated list of archives>specify comma separated archives to be unarchived on the compute machines. The general command line syntax is bin/hadoop command [genericOptions] [commandOptions] [atguigu@hadoop102 hadoop-2.7.2]$
3.常用命令實操
(0)啟動Hadoop叢集(方便後續的測試)
[atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh [atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh
(1)-help:輸出這個命令引數
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -help rm
(2)-ls: 顯示目錄資訊
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -ls /
(3)-mkdir:在HDFS上建立目錄
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir -p /sanguo/shuguo/
(4)-moveFromLocal:從本地系統中剪下貼上檔案到HDFS上(本地系統中不存在該檔案)
[atguigu@hadoop102 hadoop-2.7.2]$ touch kongming.txt [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -moveFromLocal ./kongming.txt /sanguo/shuguo/
(5)-appendToFile:追加一個檔案到已經存在的檔案末尾
[atguigu@hadoop102 hadoop-2.7.2]$ touch liubei.txt [atguigu@hadoop102 hadoop-2.7.2]$ vim liubei.txt 輸入 san gu mao lu [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -appendToFile liubei.txt /sanguo/shuguo/kongming.txt
(6)-cat:顯示檔案內容
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -cat /sanguo/shuguo/kongming.txt
(7)-chgrp 、-chmod、-chown:跟Linux檔案系統中的用法一樣,修改檔案所屬許可權
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -chmod 666 /sanguo/shuguo/kongming.txt [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -chown atguigu:atguigu /sanguo/shuguo/kongming.txt
(8)-copyFromLocal:從本地檔案系統中拷貝檔案到HDFS路徑中去(本地系統中還存在該檔案)
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyFromLocal README.txt /
(9)-copyToLocal:從HDFS拷貝到本地系統中
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyToLocal /sanguo/shuguo/kongming.txt ./
(10)-cp:從HDFS的一個路徑拷貝到HDFS的另一個路徑(檔案還在舊的HDFS中)
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -cp /sanguo/shuguo/kongming.txt /zhuge.txt
(11)-mv:在HDFS目錄中移動檔案(檔案不在舊的HDFS中,在新的HDFS中)
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /zhuge.txt /sanguo/shuguo/
(12)-get:等同於copyToLocal,就是從HDFS下載檔案到本地系統中
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -get /sanguo/shuguo/kongming.txt ./
(13)-getmerge:合併下載多個檔案,比如HDFS的目錄 /user/atguigu/test/ 下有多個檔案:log.1,log.2,log.3,……
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -getmerge /sanguo/shuguo/* ./zaiyiqi.txt
(14)-put:等同於copyFromLocal,就是從本地檔案系統中拷貝檔案到HDFS路徑中去
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -put ./zaiyiqi.txt /sanguo/shuguo/
(15)-tail:顯示一個檔案的末尾幾行(因為日誌檔案一般是在檔案的末尾不斷地追加,即監控新產生的資料變化)
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -tail /sanguo/shuguo/kongming.txt
(16)-rm:刪除檔案或資料夾
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /sanguo/shuguo/zaiyiqi.txt
(17)-rmdir:刪除空目錄
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir /test [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rmdir /test
(18)-du:統計資料夾的大小資訊
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du -s -h /user/atguigu/test/ 2.7 K/user/atguigu/test [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du -h /user/atguigu/test/ 1.3 K/user/atguigu/test/README.txt 1.4 K/user/atguigu/test/zaiyiqi.txt
(19)-setrep:設定HDFS中檔案的副本數量
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -setrep 10 /kongming.txt
HDFS副本數量

這裡設定的副本數只是記錄在NameNode的元資料中,是否真的會有這麼多副本,還得看DataNode的數量。因為目前只有3臺裝置,最多也就3個副本,只有節點數的增加到10臺時,副本數才能達到10。
第3章 HDFS客戶端操作(開發重點)
3.1 HDFS客戶端環境準備
1、根據自己電腦的作業系統拷貝對應的編譯後的hadoop jar包到非中文路徑(例如:D:\Develop\hadoop-2.7.2),如下圖所示。

2、配置HADOOP_HOME環境變數,如下圖所示:

3、配置Path環境變數,如下圖所示:

4、建立一個Maven工程HdfsClientDemo
5、匯入相應的依賴座標+日誌新增
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>jdk.tools</groupId> <artifactId>jdk.tools</artifactId> <version>1.8</version> <scope>system</scope> <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath> </dependency> </dependencies>
注意:如果Eclipse/Idea打印不出日誌,在控制檯上只顯示
1.log4j:WARN No appenders could be found for logger (org.apache.hadoop.util.Shell). 2.log4j:WARN Please initialize the log4j system properly. 3.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
需要在專案的src/main/resources目錄下,新建一個檔案,命名為“log4j.properties”,在檔案中填入以下內容:
log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.logfile=org.apache.log4j.FileAppender log4j.appender.logfile.File=target/spring.log log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
6、建立包名:com.atguigu.hdfs
7、建立HdfsClient類
public class HdfsClient { /** * 測試建立多級資料夾:在hdfs系統上建立多級資料夾 */ @Test public void testMkdirs() throws IOException, InterruptedException, URISyntaxException { // 1、獲取hdfs檔案系統物件 Configuration configuration = new Configuration(); // 配置在叢集上執行 configuration.set("fs.defaultFS", "hdfs://hadoop102:9000"); FileSystem fs = FileSystem.get(configuration); // 2 、建立目錄 fs.mkdirs(new Path("/0529/dashen")); // 3 、關閉資源 fs.close(); } }
8、執行程式
執行時需要配置使用者名稱稱,右鍵 -> Run Configurations,如下圖所示:

客戶端去操作HDFS時,是有一個使用者身份的。預設情況下,HDFS客戶端API會從JVM中獲取一個引數來作為自己的使用者身份:-DHADOOP_USER_NAME=atguigu,atguigu為使用者名稱稱。
9、另一種【配置在叢集上執行】的方式,可以不用手動配置使用者名稱稱
public class HdfsClient { /** * 測試建立多級資料夾:在hdfs系統上建立多級資料夾 */ @Test public void testMkdirs() throws IOException, InterruptedException, URISyntaxException { // 1、 獲取hdfs檔案系統物件 Configuration configuration = new Configuration(); // 配置在叢集上執行 // configuration.set("fs.defaultFS", "hdfs://hadoop102:9000"); // FileSystem fs = FileSystem.get(configuration); FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2 、建立目錄 fs.mkdirs(new Path("/0529/dashen")); // 3 、關閉資源 fs.close(); } }
3.2 HDFS的API操作
3.2.1 HDFS檔案上傳(測試引數優先順序)
1、編寫原始碼
/** * 測試檔案上傳:從本地系統上傳檔案至hdfs檔案系統上 */ @Test public void testCopyFromLocalFile() throws IOException, InterruptedException, URISyntaxException { Configuration configuration = new Configuration(); // 1、獲取hdfs檔案系統 FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); configuration.set("dfs.replication", "2"); // 2、本地系統執行上傳檔案操作 fs.copyFromLocalFile(new Path("D:/temp/atguigu/0529/banzhang.txt"), new Path("/banzhang.txt")); // 3、關閉資源 fs.close(); }
2、在/HdfsClientDemo/src/main/resources/目錄下新建hdfs-site.xml檔案,檔案內容如下,然後再次執行上傳檔案操作
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>dfs.replication</name> <!-- 設定副本的個數 --> <value>1</value> </property> </configuration>
3.引數優先順序
引數優先順序排序:(1)客戶端程式碼中設定的值 >(2)ClassPath下的使用者自定義配置檔案設定的值 >(3)hdfs伺服器的預設配置的值

效果如下圖所示:

3.2.2 HDFS檔案下載
示例程式碼如下:
/** * 測試檔案下載:將hdfs檔案系統上的檔案下載到本地系統上 */ @Test public void testCopyToLocalFile() throws IOException, InterruptedException, URISyntaxException { Configuration configuration = new Configuration(); // 1、獲取hdfs檔案系統物件 FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、執行下載檔案操作 // fs.copyToLocalFile(new Path("/banhua.txt"), new Path("D:/temp/atguigu/0529/banhua.txt")); // boolean delSrc 指是否將原始檔刪除,預設值是false,表示不刪除原始檔 // Path src 指要下載的檔案路徑 // Path dst 指將檔案下載到的路徑 // boolean useRawLocalFileSystem 是否開啟檔案校驗,即是否生成 .xxx.crc 檢驗檔案,預設值是false,表示生成檢驗檔案 fs.copyToLocalFile(false, new Path("/bancao.txt"), new Path("D:/temp/atguigu/0529/bancao.txt"), true); // 3、關閉資源 fs.close(); }
3.2.3 HDFS資料夾刪除
示例程式碼如下:
/** * 測試[資料夾/檔案]刪除:將hdfs檔案系統上的[資料夾/檔案]刪除 */ @Test public void testDelete() throws IOException, InterruptedException, URISyntaxException { Configuration configuration = new Configuration(); // 1、獲取hdfs檔案系統物件 FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、執行刪除檔案操作 // boolean recursive 指的是遞迴的意思,設定成true,表示遞迴刪除資料夾 fs.delete(new Path("/0529/"), true); // 3、關閉資源 fs.close(); }
3.2.4 HDFS檔名更改
示例程式碼如下:
/** * 檔名更改:將hdfs檔案系統上的檔案更改名稱 */ @Test public void testRename() throws IOException, InterruptedException, URISyntaxException { Configuration configuration = new Configuration(); // 1、獲取hdfs檔案系統物件 FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、執行檔名更改操作 fs.rename(new Path("/banzhang.txt"), new Path("/yanjing.txt")); // 3、關閉資源 fs.close(); }
3.2.5 HDFS檔案詳情檢視
檢視檔名稱、許可權、長度、塊資訊
示例程式碼如下:
/** * 檢視檔案詳情 */ @Test public void testListFiles() throws IOException, InterruptedException, URISyntaxException { Configuration configuration = new Configuration(); // 1、獲取hdfs檔案系統物件 FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、獲取檔案詳情 RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true); while (listFiles.hasNext()) { LocatedFileStatus fileStatus = listFiles.next(); // 輸出詳情 System.out.println(fileStatus.getPath().getName()); // 檔名稱 System.out.println(fileStatus.getPermission()); // 許可權 System.out.println(fileStatus.getLen()); // 長度 System.out.println(fileStatus.getGroup()); // 分組 // 獲取儲存的塊資訊 BlockLocation[] blockLocations = fileStatus.getBlockLocations(); for (BlockLocation blockLocation : blockLocations) { // 獲取塊儲存的主機節點 String[] hosts = blockLocation.getHosts(); for (String host : hosts) { System.out.println(host); } } System.out.println("---------------------"); } // 3、關閉資源 fs.close(); }
3.2.6 HDFS檔案和資料夾判斷
示例程式碼如下:
/** * 判斷是檔案還是資料夾 */ @Test public void testListStatus() throws IOException, InterruptedException, URISyntaxException { Configuration configuration = new Configuration(); // 1、獲取hdfs檔案系統物件 FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、判斷是檔案還是資料夾 FileStatus[] listStatus= fs.listStatus(new Path("/")); for (FileStatus fileStatus : listStatus) { // 如果是檔案 if (fileStatus.isFile()) { System.out.println("f:" + fileStatus.getPath().getName()); } else { System.out.println("d:" + fileStatus.getPath().getName()); } } // 3、關閉資源 fs.close(); }
3.3 HDFS的I/O流操作(自定義框架使用)
上面我們學的API操作HDFS系統都是框架封裝好的。那麼如果我們想自己實現上述API的操作該怎麼實現呢?
我們可以採用IO流的方式實現資料的上傳和下載。
3.3.1 HDFS檔案上傳
1、需求:把本地 D:\temp\atguigu\0529\
上的banhua.txt檔案上傳到HDFS根目錄
2、編寫程式碼
/** * 把本地 D:\temp\atguigu\0529\ 上的banhua.txt檔案上傳到HDFS根目錄 */ @Test public void putFileToHDFS() throws IOException, InterruptedException, URISyntaxException { // 1、獲取hdfs檔案系統物件 Configuration configuration = new Configuration(); FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、建立輸入流 FileInputStream fis = new FileInputStream(new File("D:/temp/atguigu/0529/banhua.txt")); // 3、建立輸出流 FSDataOutputStream fos = fs.create(new Path("/banzhang.txt")); // 4、流對拷 IOUtils.copyBytes(fis, fos, configuration); // 5、關閉資源 IOUtils.closeStream(fos); IOUtils.closeStream(fis); fs.close(); }
3.3.2 HDFS檔案下載
1、需求:從HDFS上下載banhua.txt檔案到本地 D:\temp\atguigu\0529\
上
2、編寫程式碼
* 從HDFS上下載banhua.txt檔案到本地 D:\temp\atguigu\0529\ 上 */ @Test public void getFileFromHDFS() throws IOException, InterruptedException, URISyntaxException { // 1、獲取hdfs檔案系統物件 Configuration configuration = new Configuration(); FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、建立輸入流 FSDataInputStream fis = fs.open(new Path("/banhua.txt")); // 3、建立輸出流 FileOutputStream fos = new FileOutputStream(new File("D:/temp/atguigu/0529/banhua.txt")); // 4、流對拷 IOUtils.copyBytes(fis, fos, configuration); // 5、關閉資源 IOUtils.closeStream(fos); IOUtils.closeStream(fis); fs.close(); }
3.3.3 定位檔案讀取
1、需求:分塊讀取HDFS上的大檔案,比如根目錄下的/hadoop-2.7.2.tar.gz
2、編寫程式碼
(1)下載第一塊
/** * 分塊讀取HDFS上的大檔案,比如根目錄下的/hadoop-2.7.2.tar.gz,下載第一塊 */ @Test public void readFileSeek1() throws IOException, InterruptedException, URISyntaxException { // 1、獲取hdfs檔案系統物件 Configuration configuration = new Configuration(); FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、獲取輸入流 FSDataInputStream fis = fs.open(new Path("/hadoop-2.7.2.tar.gz")); // 3、建立輸出流 FileOutputStream fos = new FileOutputStream(new File("D:/temp/atguigu/0529/hadoop-2.7.2.tar.gz.part1")); // 4、流的對拷 byte[] buf = new byte[1024]; for (int i = 0; i < 1024 * 128; i++) { fis.read(buf); fos.write(buf); } // 5、關閉資源 IOUtils.closeStream(fis); IOUtils.closeStream(fos); fs.close(); }
(2)下載第二塊
/** * 分塊讀取HDFS上的大檔案,比如根目錄下的/hadoop-2.7.2.tar.gz,下載第二塊 */ @Test public void readFileSeek2() throws IOException, InterruptedException, URISyntaxException { // 1、獲取hdfs檔案系統物件 Configuration configuration = new Configuration(); FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu"); // 2、獲取輸入流 FSDataInputStream fis = fs.open(new Path("/hadoop-2.7.2.tar.gz")); // 3、定位輸入資料位置 fis.seek(1024*1024*128); // 4、建立輸出流 FileOutputStream fos = new FileOutputStream(new File("D:/temp/atguigu/0529/hadoop-2.7.2.tar.gz.part2")); // 5、流的對拷 IOUtils.copyBytes(fis, fos, configuration); // 6、關閉資源 IOUtils.closeStream(fis); IOUtils.closeStream(fos); fs.close(); }
(3)合併檔案
在Window命令視窗中進入到目錄 D:\temp\atguigu\0529\,然後執行如下命令,對資料進行合併
type hadoop-2.7.2.tar.gz.part2 >> hadoop-2.7.2.tar.gz.part1
合併完成後,將hadoop-2.7.2.tar.gz.part1重新命名為hadoop-2.7.2.tar.gz。解壓發現該tar包非常完整。
第4章 HDFS的資料流(面試重點)
4.1 HDFS寫資料流程
4.1.1 剖析檔案寫入
HDFS寫資料流程,如下圖所示。

詳解如下:
- 1)客戶端通過Distributed FileSystem模組向NameNode請求上傳檔案,NameNode檢查目標檔案是否已存在,父目錄是否存在。
- 2)NameNode返回是否可以上傳。
- 3)客戶端請求第一個Block上傳到哪幾個DataNode伺服器上。
- 4)NameNode返回3個DataNode節點,分別為dn1、dn2、dn3。
- 5)客戶端通過FSDataOutputStream模組請求dn1上傳資料,dn1收到請求會繼續呼叫dn2,然後dn2呼叫dn3,將這個通訊管道建立完成。
- 6)dn1、dn2、dn3逐級應答客戶端。
- 7)客戶端開始往dn1上傳第一個Block(先從磁碟讀取資料放到一個本地記憶體快取),以Packet為單位,dn1收到一個Packet就會傳給dn2,dn2傳給dn3;dn1每傳一個packet會放入一個應答佇列等待應答。
- 8)當一個Block傳輸完成之後,客戶端再次請求NameNode上傳第二個Block的伺服器。(重複執行3-7步)。
4.1.2 網路拓撲-節點距離計算
在HDFS寫資料的過程中,NameNode會選擇距離待上傳資料最近距離的DataNode接收資料。那麼這個最近距離怎麼計算呢?
節點距離:
兩個節點到達最近的共同祖先的距離總和。
網路拓撲概念:

例如,假設有資料中心d1機架r1中的節點n1。該節點可以表示為/d1/r1/n1。利用這種標記,這裡給出四種距離描述,如上圖所示。
大家算一算每兩個節點之間的距離,如下圖所示。

4.1.3 機架感知(副本儲存節點選擇)
1、官方ip地址
機架感知說明:http://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html#Data_Replication
For the common case, when the replication factor is three, HDFS’s placement policy is to put one replica on one node in the local rack, another on a different node in the local rack, and the last on a different node in a different rack. This policy cuts the inter-rack write traffic which generally improves write performance. The chance of rack failure is far less than that of node failure; this policy does not impact data reliability and availability guarantees. However, it does reduce the aggregate network bandwidth used when reading data since a block is placed in only two unique racks rather than three. With this policy, the replicas of a file do not evenly distribute across the racks. One third of replicas are on one node, two thirds of replicas are on one rack, and the other third are evenly distributed across the remaining racks. This policy improves write performance without compromising data reliability or read performance.
翻譯如下:
對於常見情況,當複製因子為3時,HDFS的放置策略是將一個副本放在本地機架中的一個節點上,另一個放在本地機架中的另一個節點上,將最後一個放在另一個機架中的另一個節點上。此策略可以減少機架間寫入流量,從而提高寫入效能。機架故障的可能性遠小於節點故障的可能性; 此策略不會影響資料可靠性和可用性保證。但是,它確實減少了讀取資料時使用的聚合網路頻寬,因為塊只放在兩個唯一的機架而不是三個。使用此策略時,檔案的副本不會均勻分佈在機架上。三分之一的副本位於一個節點上,三分之二的副本位於一個機架上,另外三個副本均勻分佈在剩餘的機架上。
2、Hadoop2.7.2副本節點選擇

4.2 HDFS讀資料流程
HDFS的讀資料流程,如下圖所示。

詳解如下:
- 1)客戶端通過Distributed FileSystem向NameNode請求下載檔案,NameNode通過查詢元資料,找到檔案塊所在的DataNode地址。
- 2)挑選一臺DataNode(就近原則,然後隨機)伺服器,請求讀取資料。
- 3)DataNode開始傳輸資料給客戶端(從磁盤裡面讀取資料輸入流,以Packet為單位來做校驗)。
- 4)客戶端以Packet為單位接收,先在本地快取,然後寫入目標檔案。
第5章 NameNode和SecondaryNameNode(面試開發重點)
5.1 NN和2NN工作機制
思考:
NameNode中的元資料是儲存在哪裡的?
因此產生在磁碟中備份元資料的FsImage。
這樣又會帶來新的問題,當在記憶體中的元資料更新時,如果同時更新FsImage,就會導致效率過低,但如果不更新,就會發生一致性問題,一旦NameNode節點斷電,就會產生資料丟失。 因此,引入Edits檔案(只進行追加操作,效率很高)。每當元資料有更新或者新增元資料時,修改記憶體中的元資料並追加到Edits中。
這樣,一旦NameNode節點斷電,可以通過FsImage和Edits的合併,合成元資料。
因此,引入一個新的節點SecondaryNamenode,專門用於FsImage和Edits的合併。
NN和2NN工作機制,如下圖所示。

詳解如下:
1、第一階段:NameNode啟動
(1)第一次啟動NameNode格式化後,建立Fsimage和Edits檔案。如果不是第一次啟動,直接載入編輯日誌和映象檔案到記憶體。
(2)客戶端對元資料進行增刪改的請求。
(3)NameNode先記錄操作日誌,更新滾動日誌。
(4)NameNode然後在記憶體中對資料進行增刪改。
2、第二階段:Secondary NameNode工作
(1)Secondary NameNode詢問NameNode是否需要CheckPoint。直接帶回NameNode是否檢查結果。
(2)Secondary NameNode請求執行CheckPoint。
(3)NameNode滾動正在寫的Edits日誌。
(4)將滾動前的編輯日誌和映象檔案拷貝到Secondary NameNode。
(5)Secondary NameNode載入編輯日誌和映象檔案到記憶體,併合並。
(6)生成新的映象檔案fsimage.chkpoint。
(7)拷貝fsimage.chkpoint到NameNode。
(8)NameNode將fsimage.chkpoint重新命名成fsimage。
NN和2NN工作機制詳解:
Fsimage:NameNode記憶體中元資料序列化後形成的檔案。
Edits:記錄客戶端更新元資料資訊的每一步操作(可通過Edits運算出元資料)。
NameNode啟動時,先滾動Edits並生成一個空的edits.inprogress,然後載入Edits和Fsimage到記憶體中,此時NameNode記憶體就持有最新的元資料資訊。Client開始對NameNode傳送元資料的增刪改的請求,這些請求的操作首先會被記錄到edits.inprogress中(查詢元資料的操作不會被記錄在Edits中,因為查詢操作不會更改元資料資訊),如果此時NameNode掛掉,重啟後會從Edits中讀取元資料的資訊。然後,NameNode會在記憶體中執行元資料的增刪改的操作。
由於Edits中記錄的操作會越來越多,Edits檔案會越來越大,導致NameNode在啟動載入Edits時會很慢,所以需要對Edits和Fsimage進行合併(所謂合併,就是將Edits和Fsimage載入到記憶體中,照著Edits中的操作一步步執行,最終形成新的Fsimage)。SecondaryNameNode的作用就是幫助NameNode進行Edits和Fsimage的合併工作。
SecondaryNameNode首先會詢問NameNode是否需要CheckPoint(觸發CheckPoint需要滿足兩個條件中的任意一個,定時時間到和Edits中資料寫滿了)。直接帶回NameNode是否檢查結果。SecondaryNameNode執行CheckPoint操作,首先會讓NameNode滾動Edits並生成一個空的edits.inprogress,滾動Edits的目的是給Edits打個標記,以後所有新的操作都寫入edits.inprogress,其他未合併的Edits和Fsimage會拷貝到SecondaryNameNode的本地,然後將拷貝的Edits和Fsimage載入到記憶體中進行合併,生成fsimage.chkpoint,然後將fsimage.chkpoint拷貝給NameNode,重新命名為Fsimage後替換掉原來的Fsimage。NameNode在啟動時就只需要載入之前未合併的Edits和Fsimage即可,因為合併過的Edits中的元資料資訊已經被記錄在Fsimage中。
5.2 Fsimage和Edits解析
1、概念

2、oiv檢視Fsimage檔案
(1)檢視oiv和oev命令
[atguigu@hadoop102 current]$ hdfs Usage: hdfs [--config confdir] [--loglevel loglevel] COMMAND where COMMAND is one of: dfsrun a filesystem command on the file systems supported in Hadoop. classpathprints the classpath namenode -formatformat the DFS filesystem secondarynamenoderun the DFS secondary namenode namenoderun the DFS namenode journalnoderun the DFS journalnode zkfcrun the ZK Failover Controller daemon datanoderun a DFS datanode dfsadminrun a DFS admin client haadminrun a DFS HA admin client fsckrun a DFS filesystem checking utility balancerrun a cluster balancing utility jmxgetget JMX exported values from NameNode or DataNode. moverrun a utility to move block replicas across storage types oivapply the offline fsimage viewer to an fsimage oiv_legacyapply the offline fsimage viewer to an legacy fsimage oevapply the offline edits viewer to an edits file fetchdtfetch a delegation token from the NameNode getconfget config values from configuration groupsget the groups which users belong to snapshotDiffdiff two snapshots of a directory or diff the current directory contents with a snapshot lsSnapshottableDirlist all snapshottable dirs owned by the current user Use -help to see options portmaprun a portmap service nfs3run an NFS version 3 gateway cacheadminconfigure the HDFS cache cryptoconfigure HDFS encryption zones storagepolicieslist/get/set block storage policies versionprint the version Most commands print help when invoked w/o parameters. [atguigu@hadoop102 current]$
(2)基本語法
hdfs oiv -p 檔案型別 -i 映象檔案 -o 轉換後文件輸出路徑
(3)案例實操
[atguigu@hadoop102 current]$ pwd /opt/module/hadoop-2.7.2/data/tmp/dfs/name/current [atguigu@hadoop102 current]$ hdfs oiv -p XML -i fsimage_0000000000000000124 -o fsimage.xml [atguigu@hadoop102 current]$ cat fsimage.xml
將顯示的xml檔案內容拷貝到Eclipse中建立的xml檔案中,並格式化。部分顯示結果如下。
<inode> <id>16385</id> <type>DIRECTORY</type> <name></name> <mtime>1549193480818</mtime> <permission>atguigu:supergroup:rwxr-xr-x</permission> <nsquota>9223372036854775807</nsquota> <dsquota>-1</dsquota> </inode> <inode> <id>16386</id> <type>FILE</type> <name>wc.input</name> <replication>3</replication> <mtime>1549109263472</mtime> <atime>1549191451377</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741825</id> <genstamp>1001</genstamp> <numBytes>43</numBytes> </block> </blocks> </inode> <inode> <id>16394</id> <type>FILE</type> <name>kongming.txt</name> <replication>10</replication> <mtime>1549172409335</mtime> <atime>1549172409063</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741832</id> <genstamp>1009</genstamp> <numBytes>28</numBytes> </block> </blocks> </inode> <inode> <id>16398</id> <type>FILE</type> <name>yanjing.txt</name> <replication>3</replication> <mtime>1549182842815</mtime> <atime>1549191453687</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741833</id> <genstamp>1010</genstamp> <numBytes>29</numBytes> </block> </blocks> </inode> <inode> <id>16399</id> <type>FILE</type> <name>banhua.txt</name> <replication>1</replication> <mtime>1549183347279</mtime> <atime>1549191440485</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741834</id> <genstamp>1011</genstamp> <numBytes>29</numBytes> </block> </blocks> </inode> <inode> <id>16400</id> <type>FILE</type> <name>bancao.txt</name> <replication>2</replication> <mtime>1549183571406</mtime> <atime>1549191438143</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741835</id> <genstamp>1012</genstamp> <numBytes>29</numBytes> </block> </blocks> </inode> <inode> <id>16401</id> <type>FILE</type> <name>banzhang.txt</name> <replication>1</replication> <mtime>1549192955364</mtime> <atime>1549192955243</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741836</id> <genstamp>1013</genstamp> <numBytes>12</numBytes> </block> </blocks> </inode> <inode> <id>16402</id> <type>FILE</type> <name>hadoop-2.7.2.tar.gz</name> <replication>3</replication> <mtime>1549193480811</mtime> <atime>1549193471067</atime> <perferredBlockSize>134217728</perferredBlockSize> <permission>atguigu:supergroup:rw-r--r--</permission> <blocks> <block> <id>1073741837</id> <genstamp>1014</genstamp> <numBytes>134217728</numBytes> </block> <block> <id>1073741838</id> <genstamp>1015</genstamp> <numBytes>63439959</numBytes> </block> </blocks> </inode>
思考:
可以看出,Fsimage中沒有記錄塊所對應DataNode,為什麼?
答:是因為在叢集啟動後,要求DataNode上報資料塊資訊,並間隔一段時間後再次上報。所以我們要先啟動叢集。
3、oev檢視Edits檔案
(1)基本語法
hdfs oev -p 檔案型別 -i 編輯日誌 -o 轉換後文件輸出路徑
(2)案例實操
[atguigu@hadoop102 current]$ hdfs oev -p XML -i edits_0000000000000000103-0000000000000000108 -o edits.xml [atguigu@hadoop102 current]$ cat edits.xml
將顯示的xml檔案內容拷貝到Eclipse中建立的xml檔案中,並格式化。顯示結果如下。
<?xml version="1.0" encoding="UTF-8"?> <EDITS> <EDITS_VERSION>-63</EDITS_VERSION> <RECORD> <OPCODE>OP_START_LOG_SEGMENT</OPCODE> <DATA> <TXID>103</TXID> </DATA> </RECORD> <RECORD> <OPCODE>OP_TIMES</OPCODE> <DATA> <TXID>104</TXID> <LENGTH>0</LENGTH> <PATH>/bancao.txt</PATH> <MTIME>-1</MTIME> <ATIME>1549191438143</ATIME> </DATA> </RECORD> <RECORD> <OPCODE>OP_TIMES</OPCODE> <DATA> <TXID>105</TXID> <LENGTH>0</LENGTH> <PATH>/banhua.txt</PATH> <MTIME>-1</MTIME> <ATIME>1549191440485</ATIME> </DATA> </RECORD> <RECORD> <OPCODE>OP_TIMES</OPCODE> <DATA> <TXID>106</TXID> <LENGTH>0</LENGTH> <PATH>/wc.input</PATH> <MTIME>-1</MTIME> <ATIME>1549191451377</ATIME> </DATA> </RECORD> <RECORD> <OPCODE>OP_TIMES</OPCODE> <DATA> <TXID>107</TXID> <LENGTH>0</LENGTH> <PATH>/yanjing.txt</PATH> <MTIME>-1</MTIME> <ATIME>1549191453687</ATIME> </DATA> </RECORD> <RECORD> <OPCODE>OP_END_LOG_SEGMENT</OPCODE> <DATA> <TXID>108</TXID> </DATA> </RECORD> </EDITS>
思考:
NameNode如何確定下次開機啟動的時候合併哪些Edits?
答:根據 seen_txid
裡面記錄最新的 Fsimage(映象檔案)
的值去合併 Edits(編輯日誌)
。
5.3 CheckPoint時間設定
(1)通常情況下,SecondaryNameNode每隔一小時執行一次。
[hdfs-default.xml]
<property> <name>dfs.namenode.checkpoint.period</name> <value>3600</value> <description>SecondaryNameNode每隔一小時執行一次</description> </property>
(2)當操作次數達到1百萬時,SecondaryNameNode執行一次。
<property> <name>dfs.namenode.checkpoint.txns</name> <value>1000000</value> <description>操作動作次數</description> </property>
(3)一分鐘檢查一次操作次數。
<property> <name>dfs.namenode.checkpoint.check.period</name> <value>60</value> <description>1分鐘檢查一次操作次數</description> </property >
該檔案截圖如下:

5.4 NameNode故障處理(開發重點:偏運維)
NameNode故障後,可以採用如下兩種方法恢復資料。
方法一:將SecondaryNameNode中資料拷貝到NameNode儲存資料的目錄。
1、kill -9 NameNode程序
2、刪除NameNode儲存的資料目錄中的資料(目錄位置:/opt/module/hadoop-2.7.2/data/tmp/dfs/name/)
[atguigu@hadoop102 hadoop-2.7.2]$ rm -rf /opt/module/hadoop-2.7.2/data/tmp/dfs/name/*
3、拷貝SecondaryNameNode中資料到原NameNode儲存資料目錄
[atguigu@hadoop102 name]$ pwd /opt/module/hadoop-2.7.2/data/tmp/dfs/name [atguigu@hadoop102 name]$ scp -r atguigu@hadoop104:/opt/module/hadoop-2.7.2/data/tmp/dfs/namesecondary/* ./
4、重新啟動NameNode
[atguigu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start namenode
方法二:使用 -importCheckpoint
選項啟動NameNode守護程序,從而將SecondaryNameNode中資料拷貝到NameNode目錄中。
1、修改hdfs-site.xml中的內容,新增如下,然後分發到其他節點
[atguigu@hadoop102 hadoop-2.7.2]$ vim etc/hadoop/hdfs-site.xml <property> <name>dfs.namenode.checkpoint.period</name> <value>120</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>/opt/module/hadoop-2.7.2/data/tmp/dfs/name/</value> </property> [atguigu@hadoop102 hadoop-2.7.2]$ xsync etc/hadoop/
2、kill -9 NameNode程序
3、刪除NameNode儲存的資料目錄中的資料(目錄位置:/opt/module/hadoop-2.7.2/data/tmp/dfs/name/)
[atguigu@hadoop102 hadoop-2.7.2]$ rm -rf /opt/module/hadoop-2.7.2/data/tmp/dfs/name/*
4、如果SecondaryNameNode不和NameNode在一個主機節點上,需要將 SecondaryNameNode儲存資料的目錄namesecondary
拷貝到 NameNode儲存資料的平級目錄name
,並刪除in_use.lock檔案
[atguigu@hadoop102 dfs]$ pwd /opt/module/hadoop-2.7.2/data/tmp/dfs [atguigu@hadoop102 dfs]$ ll 總用量 8 drwx------. 3 atguigu atguigu 4096 2月4 10:37 data drwxrwxr-x. 2 atguigu atguigu 4096 2月4 10:59 name [atguigu@hadoop102 dfs]$ scp -r atguigu@hadoop104:/opt/module/hadoop-2.7.2/data/tmp/dfs/namesecondary/ ./ [atguigu@hadoop102 dfs]$ ll 總用量 12 drwx------. 3 atguigu atguigu 4096 2月4 10:37 data drwxrwxr-x. 2 atguigu atguigu 4096 2月4 10:59 name drwxrwxr-x. 3 atguigu atguigu 4096 2月4 11:04 namesecondary [atguigu@hadoop102 dfs]$ [atguigu@hadoop102 dfs]$ rm -rf namesecondary/in_use.lock
5、匯入檢查點資料(設定的是2分鐘,等待一會ctrl+c結束掉)
[atguigu@hadoop102 hadoop-2.7.2]$ bin/hdfs namenode -importCheckpoint
6、啟動NameNode
[atguigu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start namenode
方式二比方式一要檢查的東西多一些,方式一比較直接。
5.5 叢集安全模式
1、概述

2、基本語法
叢集處於安全模式,不能執行重要操作(寫操作)。叢集啟動完成後,自動退出安全模式。
(1)bin/hdfs dfsadmin -safemode get (功能描述:[檢視/獲取]安全模式狀態)
(2)bin/hdfs dfsadmin -safemode enter (功能描述:[進入/開啟]安全模式狀態)
(3)bin/hdfs dfsadmin -safemode leave (功能描述:[離開]安全模式狀態)
(4)bin/hdfs dfsadmin -safemode wait (功能描述:[等待]安全模式狀態)
演示如下圖所示:

3、案例
模擬等待安全模式
(1)檢視當前模式
(2)先進入安全模式
(3)建立並執行下面的指令碼
在/opt/module/hadoop-2.7.2路徑上,編輯一個指令碼safemode.sh
[atguigu@hadoop102 hadoop-2.7.2]$ bin/hdfs dfsadmin -safemode get Safe mode is OFF [atguigu@hadoop102 hadoop-2.7.2]$ bin/hdfs dfsadmin -safemode enter Safe mode is ON [atguigu@hadoop102 hadoop-2.7.2]$ touch safemode.sh [atguigu@hadoop102 hadoop-2.7.2]$ vim safemode.sh [atguigu@hadoop102 hadoop-2.7.2]$ cat safemode.sh #!/bin/bash hdfs dfsadmin -safemode wait hdfs dfs -put /opt/module/hadoop-2.7.2/README.txt / [atguigu@hadoop102 hadoop-2.7.2]$ bash ./safemode.sh
(4)再開啟一個視窗,執行該指令碼
[atguigu@hadoop102 hadoop-2.7.2]$ bin/hdfs dfsadmin -safemode leave
(5)觀察
(a)再觀察上一個視窗
Safe mode is OFF
(b)HDFS叢集上已經有上傳的資料了。
5.6 NameNode多目錄配置
1、NameNode的本地目錄可以配置成多個,且每個目錄存放內容相同,增加了可靠性。
2、具體配置如下:
(1)在hdfs-site.xml檔案中增加如下內容,儲存退出後,然後進行分發操作
[atguigu@hadoop102 hadoop-2.7.2]$ vim etc/hadoop/hdfs-site.xml <property> <name>dfs.namenode.name.dir</name> <value>file:///${hadoop.tmp.dir}/dfs/name1,file:///${hadoop.tmp.dir}/dfs/name2</value> </property> [atguigu@hadoop102 hadoop-2.7.2]$ xsync etc/hadoop/
(2)停止叢集,刪除data和logs中所有資料。
[atguigu@hadoop102 hadoop-2.7.2]$ sbin/stop-dfs.sh關閉全部 NameNode 和 DataNode [atguigu@hadoop103 hadoop-2.7.2]$ sbin/stop-yarn.sh關閉全部 ResourceManager 和 NodeManager [atguigu@hadoop102 hadoop-2.7.2]$ rm -rf data/ logs/ [atguigu@hadoop103 hadoop-2.7.2]$ rm -rf data/ logs/ [atguigu@hadoop104 hadoop-2.7.2]$ rm -rf data/ logs/
(3)格式化叢集並啟動。
[atguigu@hadoop102 hadoop-2.7.2]$ bin/hdfs namenode –format [atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh開啟全部 NameNode 和 DataNode
(4)檢視結果
[atguigu@hadoop102 dfs]$ ll 總用量 8 drwxrwxr-x. 3 atguigu atguigu 4096 2月4 12:50 name1 drwxrwxr-x. 3 atguigu atguigu 4096 2月4 12:50 name2 [atguigu@hadoop102 dfs]$ cd name1/ [atguigu@hadoop102 name1]$ cd current/ [atguigu@hadoop102 current]$ ll 總用量 16 -rw-rw-r--. 1 atguigu atguigu 354 2月4 12:50 fsimage_0000000000000000000 -rw-rw-r--. 1 atguigu atguigu62 2月4 12:50 fsimage_0000000000000000000.md5 -rw-rw-r--. 1 atguigu atguigu2 2月4 12:50 seen_txid -rw-rw-r--. 1 atguigu atguigu 205 2月4 12:50 VERSION [atguigu@hadoop102 current]$ cd .. [atguigu@hadoop102 name1]$ cd .. [atguigu@hadoop102 dfs]$ cd name2/ [atguigu@hadoop102 name2]$ cd current/ [atguigu@hadoop102 current]$ ll 總用量 16 -rw-rw-r--. 1 atguigu atguigu 354 2月4 12:50 fsimage_0000000000000000000 -rw-rw-r--. 1 atguigu atguigu62 2月4 12:50 fsimage_0000000000000000000.md5 -rw-rw-r--. 1 atguigu atguigu2 2月4 12:50 seen_txid -rw-rw-r--. 1 atguigu atguigu 205 2月4 12:50 VERSION [atguigu@hadoop102 current]$ cd .. [atguigu@hadoop102 name2]$ cd .. [atguigu@hadoop102 dfs]$ ll 總用量 12 drwx------. 3 atguigu atguigu 4096 2月4 12:53 data drwxrwxr-x. 3 atguigu atguigu 4096 2月4 12:53 name1 drwxrwxr-x. 3 atguigu atguigu 4096 2月4 12:53 name2 [atguigu@hadoop102 dfs]$ ll name1/current/ 總用量 1052 -rw-rw-r--. 1 atguigu atguigu42 2月4 12:54 edits_0000000000000000001-0000000000000000002 -rw-rw-r--. 1 atguigu atguigu 1048576 2月4 12:55 edits_inprogress_0000000000000000003 -rw-rw-r--. 1 atguigu atguigu354 2月4 12:50 fsimage_0000000000000000000 -rw-rw-r--. 1 atguigu atguigu62 2月4 12:50 fsimage_0000000000000000000.md5 -rw-rw-r--. 1 atguigu atguigu354 2月4 12:54 fsimage_0000000000000000002 -rw-rw-r--. 1 atguigu atguigu62 2月4 12:54 fsimage_0000000000000000002.md5 -rw-rw-r--. 1 atguigu atguigu2 2月4 12:54 seen_txid -rw-rw-r--. 1 atguigu atguigu205 2月4 12:50 VERSION [atguigu@hadoop102 dfs]$ ll name2/current/ 總用量 1052 -rw-rw-r--. 1 atguigu atguigu42 2月4 12:54 edits_0000000000000000001-0000000000000000002 -rw-rw-r--. 1 atguigu atguigu 1048576 2月4 12:55 edits_inprogress_0000000000000000003 -rw-rw-r--. 1 atguigu atguigu354 2月4 12:50 fsimage_0000000000000000000 -rw-rw-r--. 1 atguigu atguigu62 2月4 12:50 fsimage_0000000000000000000.md5 -rw-rw-r--. 1 atguigu atguigu354 2月4 12:54 fsimage_0000000000000000002 -rw-rw-r--. 1 atguigu atguigu62 2月4 12:54 fsimage_0000000000000000002.md5 -rw-rw-r--. 1 atguigu atguigu2 2月4 12:54 seen_txid -rw-rw-r--. 1 atguigu atguigu205 2月4 12:50 VERSION [atguigu@hadoop102 dfs]$