什么是HDFS
Hadoop Distribute File System 的简称,也就是Hadoop的一个分布式文件系统。
存储在大数据场景下的弊端
- 文件太大,打击存储成本太高
- ~ 单机读取速度太慢
- 单机存储损耗太大
HDFS的特性
- 适用于超大文件
- 一次写入多次读取
- 杨勇硬件
- 数据冗余, 硬件容错
HDFS不适用的场景
- 低时延的数据访问
- 小文件的存储
HDFS中元数据(文件的基本信息)存储在namenode的内存中,而namenode为单点,小文件数量大到一定程度,namenode内存就吃不消了 - 多文件写入,修改
HDFS基本架构
HDFS基本机制
- block
- 磁盘数据块 ,块是文件的抽象存储单元, HDFS里面的数据都是以块的形式存储和调用
- HDFS的block大小远大于磁盘块而且是磁盘块的整数倍, 默认是64MB(根据磁盘发展趋势)
- namenode,datanode
- namenode是管理节点,存放文件的元数据
- datanode负责数据块的检索和存储
- 网络拓扑
- data center(数据中心)
- Rack(机架)
- Node(把机器抽象出来就是节点)
- 同一个Rack连接到同一个交换机
HDFS数据读取流程
client -> NameNode --------------Secondary NameNode
- 发起请求
- 返回元数据
- 读取block
- 拼接文件返回client
写入
- 文件拆分
- 返回合适的DN
- 写入block
- 复制
- 返回到NameNode
副本放置机制
心跳机制
HDFS常用shell命令
//查看所有的命令
> hadoop fs -rm -r /hadoop_fils
-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...] :
List the contents that match the specified file pattern. If path is not
specified, the contents of /user/<currentUser> will be listed. For a directory a
list of its direct children is returned (unless -d option is specified).
Directory entries are of the form:
permissions - userId groupId sizeOfDirectory(in bytes)
modificationDate(yyyy-MM-dd HH:mm) directoryName
and file entries are of the form:
permissions numberOfReplicas userId groupId sizeOfFile(in bytes)
modificationDate(yyyy-MM-dd HH:mm) fileName
-C Display the paths of files and directories only.
-d Directories are listed as plain files.
-h Formats the sizes of files in a human-readable fashion
rather than a number of bytes.
-q Print ? instead of non-printable characters.
-R Recursively list the contents of directories.
-t Sort files by modification time (most recent first).
-S Sort files by size.
-r Reverse the order of the sort.
-u Use time of last access instead of modification for
display and sorting.
- 新建文件夹
> hadoop fs -mkdir /aaa
- 导入文件
> hadoop fs -put D:\word.json /aaa
- 删除文件夹
> hadoop fs -rm -r /aaa
- 查看文件夹下的内容
> hadoop fs -ls /aaa
Found 1 items
-rw-r--r-- 1 silen supergroup 27354320 2018-11-29 23:16 /aaa/word.json
- 常见操作
- 查看文件内容 -cat
- -cp 文件复制
- -mv 文件移动
- -appendToFile 文件追加
- -tail 查看文件末尾是否追加成功
- -mkdir -p创建过个目录
- 导出文件
> hadoop fs -get /aaa/word.json D:\