Hdfs介绍
HDFS是Hadoop Distribute FIle System的简称,是Hadoop分部式文件系统。作为最底层的分布式服务而存在。
架构
采用master/slave架构。
一般一个HDFS集群是一个NameNode和一定数目的DataNode组成。
分块存储
在物理上是分块存储(block)的,在hadoop2.x版本中默认大小是128M。
HDFS是设计成使用一次写入,多次读出的场景,且不支持文件的修改。
hdfs命令行使用
查看文件名称和文件夹名称
hdfs dfs -ls [-R]
创建目录
hdfs dfs -mkdir [-p]
从当前位置移动到哪
hdfs dfs -moveFromLocal
移动到当前位置
hdfs dfs -moveToLocal [crc]
上传到哪
hdfs dfs -put …
查看内容
hdfs dfs -cat URI[URI…]
删除文件
hdfs dfs -rm [-f] [-r|-R] [-skipTrash] URI [URI …]
给权限
hdfs dfs -chmod [-R] <MODE[,MODE]… | OCTALMODE> URI [URI …]
清空回收站
hdfs dfs -expunge
Hdfs中NameNode与DataNode总结
NameNode
1、存储元数据
2、元数据保存在内存中
3、保存文件、block/DataNode之间的映射关系
DataNode
1.存储文件内容
2、文件内容保存在磁盘
3、维护了Block id到DataNode本地文件的映射关系
SecondaryNameNode如何辅助管理Fsimage与Edits文件
1、secondaryNameNode通知NameNode切换editlog
2、secondaryNameNode从NameNode中获得FSimage和editlog(通过http方式)
3、secondaryNameNode将FSimage载入内容,然后开始合并editlog,合并之后成为新的fsinage
4、secondaryNameNode将新的fsimage发回给NameNode
5、NameNode用新的 fsimage替换旧的fsimage
使用文件系统获取数据
第一种
Configuration configuration =new Configuration();
FileSystem fileSystem=FileSystem.get(new URI(“hdfs://192.168.72.100:8020”).configuration);
System.out.println(fileSystem.toString());
第二种
Configuration configuration =new Configuration();
configuration.set(“fs.defaultFS”,“hdfs://192.168.72.100:8020”);
FIleSystem fileSystem=FileSystem.get(new URI(/).configuration);
第三种
Configuration configuration =new Configuration();
FileSystem fileSystem=FileSystem.new Instance(new URI(“hdfs://192.168.72.100:8020”).configuration);
第四种
Configuration configuration=new Configuration();
configuration.set(“fs.defaultFS”,“hdfs://192.168.72.100:8020”);
FileSystem fileSystem=FIleSystem.newInstance(configuration);