EMR入门学习之HDFS的运维操作(十三)

  • 2019 年 11 月 22 日
  • 笔记

一、查看HDFS文件系统健康状况

前言

HDFS是分布式文件系统。HDFS支持fsck命令来检查系统中的各种不一致状况。我们可以使用fsck 来查看当前文件系统的状态。该命令提供了若干选项,不同选项完成不同的功能。

登录EMR集群的Master节点,我们通过ps aux | grep namenode 可以看到HDFS的超级用户是Hadoop。

所以我们在Master节点su hadoop,执行hdfs fsck -h输出如下:

Usage: hdfs fsck  [-list-corruptfileblocks | [-move | -delete | -openforwrite] [-files [-blocks [-locations | -racks]]]] [-includeSnapshots] [-storagepolicies] [-blockId ]    start checking from this path   -move move corrupted files to /lost+found   -delete delete corrupted files   -files print out files being checked   -openforwrite print out files opened for write   -includeSnapshots include snapshot data if the given path indicates a snapshottable directory or there are snapshottable directories under it   -list-corruptfileblocks print out list of missing blocks and files they belong to   -blocks print out block report   -locations print out locations for every block   -racks print out network topology for data-node locations   -storagepolicies print out storage policy summary for the blocks   -blockId print out which file this blockId belongs to, locations (nodes, racks) of this block, and other diagnostics info (under replicated, corrupted or not, etc)

参数

说明

<path>

检查的起始目录

-move

将损坏的文件移到到/lost+found

-delete

删除损坏的文件

-files

打印出所有被检查的文件

-openforwrite

打印出正在写的文件

-list-corruptfileblocks

print out list of missing blocks and files they belong to

-blocks

打印出block报告

-locations

打印出每个block的位置

-racks

打印出datanode的网络拓扑结构

默认情况下,fsck会忽略正在写的文件,使用-openforwrite可以汇报这种文件

注意事项:当输入的 在namenode中文件数量大的时候,要慎重使用fsck命令,会对hdfs系统造成较大性能影响。 通常,推荐在文件系统负载低峰期时候执行该命令,作健康检查。

操作

示例1:对整个文件系统进行监控检查

hdfs fsck /

示例2:将某个目录中损坏的文件删除

示例3:打印被检查的文件信息

二、HA集群查看NameNode状态

前言

在运维HDFS集群,或排查问题的过程中,我们需要确定某个NameNode节点的服务状态。HDFS提供了haadmin工具来查看该信息。

操作命令

同样在Master节点hadoop用户下,使用hdfs haadmin -getAllServiceState 如下:

或者使用hdfs haadmin -getServiceState nn1 如下

则NameNode nn1 是active 状态,则输出active;否则,输出standby。

HA集群切换NameNode

操作命令

示例:hdfs haadmin -failover nn1 nn2

输出: Failover to NameNode at *.*.*.* successful

三、hdfs dfsadmin

hdfs 使用情况,节点信息查询

前言

HDFS是分布式文件系统。HDFS支持使用dfsadmin来查看各个节点的情况,以及集群存储使用情况。

操作命令

hdfs dfsadmin -report [-live] [-dead] [-decommissioning] 

说明

打印 hdfs文件系统的信息和各节点的统计信息. 如果加上可选参数,则只打印对应状态的节点信息。 比如,hdfs dfsadmin -report -live, 只打印存活的节点信息。

hdfs 添加/删除/更新节点

前言

需要添加/删除一些节点, (不建议手动操作,如果需要扩缩容,请通过emr中控台提供的操作接口来操作)

操作命令

hdfs dfsadmin -refreshNodes

说明

刷新节点。 重新读取 hosts 和exclude 文件,更新哪些datanode可以连接到NameNode,以及哪些datanode应该是decommissioned或recommissioned。

具体操作

  1. 需要退役的机器列表加入dfs.hosts.exclude文件
  2. hadoop dfsadmin -refreshNodes
  3. 等待一段时间,这些datanode的状态由in service->Decommission
  4. dfs.hosts文件剔除这批datanode
  5. hadoop dfsadmin -refreshNodes

四、HDFS集群数据均衡操作

前言

随着时间推移,运行中的HDFS集群数据节点datanode负载的数据量越来越不均衡。这将破坏数据本地性特征,导致部分数据节点异常繁忙,影响整个集群性能。

命令介绍

hdfs balancer  [-threshold <threshold>]  [-policy <policy>]  [-exclude [-f <hosts-file> | <comma-separated list of hosts>]]  [-include [-f <hosts-file> | <comma-separated list of hosts>]]  [-idleiterations <idleiterations>]

参数

说明

-policy  <policy>

策略取值: datanode, blockpool 。表示balancing将基于datanode级别;“blockpool”只能在Federation架构下有效,balancer级别为“blockpool”表示每个datanode上每个blockpool的blocks个数分布均衡。建议保持默认。

-threshold  <threshold>

磁盘容量百分比,当参与数据均衡的节点之间容量占比差值小于该值时,均衡操作停止。

-exclude -f  <hosts-file> |  <comma-separated list of hosts>

排除某些节点参与数据均衡操作。

-include -f  <hosts-file> |  <comma-separated list of hosts>

指定某些节点参与数据均衡操作。

-idleiterations  <iterations>

最大迭代次数,默认值5

注意:因为涉及到数据迁移,迁移速度通过hdfs-site.xml 文件中的dfs.datanode.balance.bandwidthPerSec指定,单位字节/sec。