HDFS镜像文件fsimage和编辑日志文件edits

镜像文件和编辑日志文件

1)概念

       namenode被格式化之后,将在/opt/module/hadoop-2.7.2/data/tmp/dfs/name/current目录中产生如下文件

edits_0000000000000000000
fsimage_0000000000000000000.md5
seen_txid
VERSION

(1)Fsimage文件:HDFS文件系统元数据的一个永久性的检查点,其中包含HDFS文件系统的所有目录和文件inode的序列化信息(id、类型、目录、所属用户、用户权限、时间戳……)。 

(2)Edits文件:存放HDFS文件系统的所有更新操作的路径,文件系统客户端执行的所有写操作首先会被记录到edits文件中。 

(3)seen_txid文件保存的是一个数字,就是最后一个edits_的数字

(4)每次Namenode启动的时候都会将fsimage文件读入内存,并从00001开始到seen_txid中记录的数字依次执行每个edits里面的更新操作,保证内存中的元数据信息是最新的、同步的,可以看成Namenode启动的时候就将fsimage和edits文件进行了合并。

2)oiv查看fsimage文件

(1)查看oiv和oev命令

[atguigu@hadoop102 current]$ hdfs
oiv                  apply the offline fsimage viewer to an fsimage
oev                  apply the offline edits viewer to an edits file

(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_0000000000000000025 -o /opt/module/hadoop-2.7.2/fsimage.xml 

[atguigu@hadoop102 current]$ cat /opt/module/hadoop-2.7.2/fsimage.xml

将显示的xml文件内容拷贝到eclipse中创建的xml文件中,并格式化。

3)oev查看edits文件

(1)基本语法

hdfs oev -p 文件类型 -i 编辑日志 -o 转换后文件输出路径

(2)案例实操

[atguigu@hadoop102 current]$ hdfs oev -p XML -i edits_0000000000000000012-0000000000000000013 -o /opt/module/hadoop-2.7.2/edits.xml
[atguigu@hadoop102 current]$ cat /opt/module/hadoop-2.7.2/edits.xml

将显示的xml文件内容拷贝到eclipse中创建的xml文件中,并格式化。

滚动编辑日志

正常情况HDFS文件系统有更新操作时,就会滚动编辑日志。也可以用命令强制滚动编辑日志。

1)滚动编辑日志(前提必须启动集群)

[atguigu@hadoop102 current]$ hdfs dfsadmin -rollEdits

2)镜像文件什么时候产生

Namenode启动时加载镜像文件和编辑日志

 

posted @ 2019-07-19 19:51  猫不夜行  阅读(1644)  评论(0编辑  收藏  举报