[关闭]
@zqbinggong 2018-06-16T12:19:40.000000Z 字数 6194 阅读 850

管理Hadoop

MapReduce基础
MapReduce应用开发
YARN

hadoop 《权威指南》

! All pictures are screenshots from the book 'Hadoop: The Definitive Guide, Fourth Edititon, by Tom White(O'Reilly).Copyright©2015TomWhite, 978-1-491-90163-2'


Hadoop守护进程的关键属性


HDFS

此处输入图片的描述

dfs.namenode.name.dir

  1. 典型配置

    1. <property>
    2. <name>dfs.datanode.data.dir</name>
    3. <value>/disk1/hdfs/data,/disk2/hdfs/data</value>
    4. </property>
  2. 该属性指定一系列目录来供namenode存储永久性的文件系统元数据(编辑日志和文件系统映像),通常将nanenode元数据写入一两个本地磁盘和一个远程磁盘(如NFS挂载的目录)之中

  3. 注意辅助namenode只是定期保存namenode的检查点,而不维护namenode的最新备份

dfs.datanode.data.dir

  1. 典型配置

    1. <property>
    2. <name>dfs.namenode.checkpoint.dir</name>
    3. <value>/disk1/hdfs/namesecondary,/disk2/hdfs/namesecondary</value>
    4. </property>
  2. 指定datanodde存储数据块的目录列表,此处指定多个目录列表不是为了冗余备份(namenode是此目的),而是为了使datanode循环地在各个目录中写数据;因而为了提高性能,最好为每一个本地磁盘指定一个存储目录,而且这样一来,数据块跨硬盘分布,可以使得针对不同数据块地读操作可以并发执行,提高读取性能

dfs.namenode.checkpoint.dir

  1. 典型配置

    1. <property>
    2. <name>dfs.namenode.checkpoint.dir</name>
    3. <value>/disk1/hdfs/namesecondary,/disk2/hdfs/namesecondary</value>
    4. </property>
  2. 为辅助namenode指定存储文件系统检查点地目录(同namenode,多个目录使为了冗余备份)

YARN

shuffle句柄(handlers)

YARN没有tasktraver,它依赖于shuffle句柄将map任务地输出送给reduce任务

内存设置

  1. yarn不会立即指定一个节点上运行的map和reduce slots的最大数量,想法,它允许应用程序为一个任务请求任意规模的内存,因此在一个特定节点上运行的任务数量取决于这些任务对内存的需求量,而不是固定的slots数量
  2. 每个Hadoop守护进程使用1000mb内存,因而需要2000mb内存来运行一个datanode和一个节点管理器

HDFS

永久性数据结构

—— namenode、辅助namanode和datanode等HDFS组件如何在磁盘上组织永久性数据

namenode的目录结构

  1. ${dfs.namenode.name.dir}/
  2. ├── current
  3. ├── VERSION
  4. ├── edits_0000000000000000001-0000000000000000019
  5. ├── edits_inprogress_0000000000000000020
  6. ├── fsimage_0000000000000000000
  7. ├── fsimage_0000000000000000000.md5
  8. ├── fsimage_0000000000000000019
  9. ├── fsimage_0000000000000000019.md5
  10. └── seen_txid
  11. └── in_use.lock
  1. VERSION: 包含正在运行的hdfs额度版本信息

    1. #Mon Sep 29 09:54:36 BST 2014
    2. namespaceID=1342387246 //文件系统命名空间的唯一标识符,namenode首次格式化时产生
    3. clusterID=CID-01b5c398-959c-4ea8-aae6-1e0d9bd8b142//将hdfs集群作为一个整体的唯一标识符(对联邦hdfs很重要)
    4. cTime=0 //namenode存储系统的创建时间
    5. storageType=NAME_NODE
    6. blockpoolID=BP-526805057-127.0.0.1-1411980876842//数据块池的唯一标识符,数据块池包含了由一个namenode管理的命名空间中的所有文件
    7. layoutVersion=-57 //负整数,描述hdfs持久性数据结构的版本,布局变更,值递减,并且hdfs需要升级
  2. in_use.lock:锁文件,供namenode使用来为存储目录加锁,从而避免其他namenode实例同时使用同一个存储目录的情况

文件系统镜像和编辑日志

这一部分设计到namenode和文件系统客户端之间的交互,后者会改变数据,前者需根据改变来更改元数据

  1. 文件系统客户端在执行写操作时(如移动或者创建文件),这些事物先被记录到编辑日志中,当编辑日志发被修改时,相关元数据信息会同步被更新(namenode在内存中维护文件系统的元数据)

    • 编辑日志,体现为磁盘上的多个文件(edits开头的文件,后缀指示出该文件所包含事务的ID)
  2. fsimage文件

    • 恢复namenode需要执行编辑日志中的事务,当编辑日志过大时会使得nanenode的重启较慢,解决方案就是运行辅助namenode,为主namenode内存中的文件系统元数据创建检查点,即fsimage文件
    • fsimage文件,文件系统元数据的一个完整的永久性检查点(后缀表示最后一个事务),由于该文件较大,因而不会在每一个写操作完成后都去更新该文件
    • 当namenode发生故障,最近的fsimage文件被加载进内存以重构元数据的最近状态,再从相关点开始向前执行编辑日志记录的事务(这是由于fsimage文件的更新方式所导致),不过此时需要执行的编辑文件较小甚至可能是空文件(步骤1中产生的新文件),因此可以快速启动
    • 创建过程
  1. The secondary asks the primary to roll its in-progress edits file, so new edits go to
    a new file. The primary also updates the seen_txid file in all its storage directories.
  2. The secondary retrieves the latest fsimage and edits files from the primary (using
    HTTP GET).
  3. The secondary loads fsimage into memory, applies each transaction from edits, then
    creates a new merged fsimage file.
  4. The secondary sends the new fsimage back to the primary (using HTTP PUT), and
    the primary saves it as a temporary .ckpt file.
  5. The primary renames the temporary fsimage file to make it available.

此处输入图片的描述

datanode的目录结构

  1. 该目录实在初始阶段自动创建的,不需要格式化
  2. 当目录(指的是数据块池目录?留待验证)中的文件到达一定数量(默认64)时,就创建一个子目录
  3. 同一个datanode上的每个磁盘上的块不会重复,只有不同的datanode之间块才会有重复

    ${dfs.datanode.data.dir}/
    ├── current
    │ ├── BP-526805057-127.0.0.1-1411980876842 //对应于namanode的VERSION文件中的数据块池ID
    │ │ └── current
    │ │ ├── VERSION
    │ │ ├── finalized
    │ │ │ ├── blk_1073741825
    │ │ │ ├── blk_1073741825_1001.meta
    │ │ │ ├── blk_1073741826
    │ │ │ └── blk_1073741826_1002.meta
    │ │ └── rbw
    │ └── VERSION
    └── in_use.lock

安全模式

日志审计

工具

  1. dfsadmin: 既可以查找hdfs状态信息,又可以在hdfs上执行管理操作
  2. fsck: 检查hdfs中文件的健康状况,也可以帮助用户轻松找到属于特定文件的数据块
  3. datanode块扫描器: 各个datanode运行一个块扫描器,定期检测本节点上的所有块,从而在客户端读取到坏块之前及时地检测和修复
  4. 均衡器: 是一个Hadoop守护进程,它通过将块从忙碌地datanode移到相对空闲地datanode从而重新分配块,移动时坚持块复本放置策略,将复本分散到不同地机架,从而降低数据损坏率

监控

监控的目标在于检测集群在什么是什么时候未能提供所期望地服务,主守护进程(主namenode,辅助namenode,资源管理器)时最需要监控的


维护

日常管理过程

  1. 元数据的备份: 若namenode的永久性元数据丢失,则整个文件系统将无法使用
  2. 数据备份: 关键在于为数据划分不同的优先级,那些无法重新生成的数据的优先级最高
    • distcp: 并行的文件复制功能可以将备份文件存储到其他的HDFS集群或其他Hadoop文件系统
    • 快照
  3. 文件系统检查:fsck
  4. 文件系统均衡器

委任和解除节点

即向集群中添加和移除节点,通常情况下,节点同时运行datanode和节点管理器,因而两者一般同时被委任和解除

委任新节点

The file (or files) specified by the dfs.hosts and yarn.resourcemanager.nodes.include-path properties is different from the slaves file. The former is used by the namenode and resource manager to determine which worker nodes may connect. The slaves file is used by the Hadoop control scripts to perform cluster- wide operations, such as cluster restarts. It is never used by the Hadoop daemons.

To add new nodes to the cluster:

  1. Add the network addresses of the new nodes to the include file.
  2. Update the namenode with the new set of permitted datanodes using this command:
    % hdfs dfsadmin -refreshNodes
  3. Update the resource manager with the new set of permitted node managers using:
    % yarn rmadmin -refreshNodes
  4. Update the slaves file with the new nodes, so that they are included in future oper‐ ations performed by the Hadoop control scripts.
  5. Start the new datanodes and node managers.
  6. Check that the new datanodes and node managers appear in the web UI.

解除旧节点

用户将拟退出的若干datanode告知namenode,Hadoop系统就在这些datanode停机前将数据复制到其他datanode
基本过程是委任新节点的反过程
此处输入图片的描述

To remove nodes from the cluster:

  1. Add the network addresses of the nodes to be decommissioned to the exclude file. Do not update the include file at this point.
  2. Update the namenode with the new set of permitted datanodes, using this command:
    % hdfs dfsadmin -refreshNodes
  3. Update the resource manager with the new set of permitted node managers using:
    % yarn rmadmin -refreshNodes
  4. Go to the web UI and check whether the admin state has changed to “Decommission In Progress” for the datanodes being decommissioned. They will start copying their blocks to other datanodes in the cluster.
  5. When all the datanodes report their state as “Decommissioned,” all the blocks have been replicated. Shut down the decommissioned nodes.
  6. Remove the nodes from the include file, and run:
    % hdfs dfsadmin -refreshNodes
    % yarn rmadmin -refreshNodes
  7. Remove the nodes from the slaves file.

升级

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注