HDFS介绍基本操作

什么是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:\
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 关于Mongodb的全面总结 MongoDB的内部构造《MongoDB The Definitive Guide》...
    中v中阅读 32,038评论 2 89
  • HDFS是Hadoop Distribute File System 的简称,也就是Hadoop的一个分布式文件系...
    大佛爱读书阅读 887评论 0 0
  • 一、目标 HDFS 全称hadoop分布式文件系统,其最主要的作用是作为 Hadoop 生态中各系统的存储服务。 ...
    Alukar阅读 2,566评论 1 18
  • 文/蕲安 这天下已经开始乱了。 去年初春,陈七郎陈怀瑾带着家眷从颍川搬到金陵躲难,安顿好以后已是秋末。陈怀瑾是天下...
    蕲安阅读 1,074评论 8 19
  • 概述 通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此...
    升云手札阅读 271评论 0 2