hadoop balance官网介绍:
HDFS data might not always be be placed uniformly across the DataNode. One common reason is addition of new DataNodes to an existing cluster. While placing new blocks (data for a file is stored as a series of blocks), NameNode considers various parameters before choosing the DataNodes to receive these blocks. Some of the considerations are:
Policy to keep one of the replicas of a block on the same node as the node that is writing the block.
Need to spread different replicas of a block across the racks so that cluster can survive loss of whole rack.
One of the replicas is usually placed on the same rack as the node writing to the file so that cross-rack network I/O is reduced.
Spread HDFS data uniformly across the DataNodes in the cluster.
Due to multiple competing considerations, data might not be uniformly placed across the DataNodes. HDFS provides a tool for administrators that analyzes block placement and rebalanaces data across the DataNode. A brief administrator’s guide for balancer is available at HADOOP-1652
翻译:
HDFS数据可能并不总是均匀地放置在DataNode上。一个常见原因是向现有集群添加了新的DataNode。放置新块时(文件的数据存储为一系列块),NameNode在选择接收这些块的DataNode之前会考虑各种参数。一些考虑因素是:
将块中的一个副本保留在与写入块的节点相同的节点上的策略。
需要在机架上传播块的不同副本,以便群集可以在整个机架丢失时存活。
其中一个副本通常与写入文件的节点放在同一个机架上,以便减少跨机架网络I / O.
在群集中的DataNode上统一传播HDFS数据。
由于多个竞争考虑因素,数据可能无法统一放置在DataNode上。HDFS为管理员提供了一种工具,可以分析数据块的块放置和重新平衡数据。有关平衡器的简要管理员指南,请访问HADOOP-1652
也就是说:在线上的hadoop集群运维过程中,hadoop的balance工具通常用于平衡hadoop集群中各datanode中的文件块分布,以避免出现部分datanode磁盘占用率高的问题(这问题也很有可能导致该节点CPU使用率较其他服务器高)。
hadoop balance工具的用法:
To start:
bin/start-balancer.sh [-threshold <threshold>]
Example: bin/ start-balancer.sh
start the balancer with a default threshold of 10%
bin/ start-balancer.sh -threshold 5
start the balancer with a threshold of 5%
To stop:
bin/ stop-balancer.sh
官方参数介绍:
用法:
hdfs平衡器 [-threshold <threshold>] [-policy <policy>] [-exclude [-f <hosts-file> | <以逗号分隔的主机列表>]] [-include [-f <hosts-file> | <以逗号分隔的主机列表>]] [-idleiterations <idleiterations>]
命令选项 描述 -policy <policy> datanode(默认值):如果每个datanode均衡,则群集是平衡的。
blockpool:如果每个datanode中的每个块池都是平衡的,则群集是平衡的。-threshold <threshold> 磁盘容量的百分比。这会覆盖默认阈值。 -exclude -f <hosts-file> | <以逗号分隔的主机列表> 排除指定的数据节点被平衡器平衡。 -include -f <hosts-file> | <以逗号分隔的主机列表> 仅包括由平衡器平衡的指定数据节点。 -idleiterations <iterations> 退出前的最大空闲迭代次数。这会覆盖默认的空闲状态(5)。
默认使用的datanode policy,用的时候一般设置一下 threshold 就行,这个参数是触发进行balance的阈值,默认是10,意思是集群中datanode空间使用率差了10%就开始balance。
平衡速度优化:
下面简单介绍一下优化Hadoop Balancer平衡的速度涉及到的几个重要参数
1. dfs.datanode.max.transfer.threads
修改dfs.datanode.max.transfer.threads=4096 (如果运行HBase的话建议为16384),指定用于在DataNode间传输block数据的最大线程数,老版本的对应参数为dfs.datanode.max.xcievers。
2. dfs.datanode.balance.bandwidthPerSec
修改dfs.datanode.balance.bandwidthPerSec=52428800,指定DataNode用于balancer的带宽为50MB,这个根据情况而定,如果交换机性能好点的,完全可以设定100MB,单位是Byte,如果机器的网卡和交换机的带宽有限,可以适当降低该速度,比如10MB,默认是1048576(1MB)。
hdfs dfsadmin-setBalancerBandwidth 52428800
线上场景:
Hadoop生产环境上,HDFS分配非常不均匀,而且有的DataNode节点的磁盘使用率几乎100%了,导致一些作业报错。后来公司采取Hadoop balancer来对数据进行平衡操作,但是数据量太大,高达50T作业,所以采用Hadoop balancer方法进行平衡,需要的时间太长。
做法:
调整hadoop halancer的参数,比如线程数,带宽等,效果都没有那么明显,毕竟数据量太大。后面考虑到他们的数据副本为3,所以可以考虑将一些DataNode磁盘利用率太高的节点先下线操作(必须逐个节点操作,不可同时下线多个节点,防止数据丢失),即Decommission Datanode。完成下线后,再进行格式化数据磁盘操作,然后再将此DataNode添加到集群中,这样新的数据就会较快地同步过来。
最后,我们补充点Decommission Datanode相关知识。
Decommission Datanode主要有两个步骤:
1. 在Namenode上,把需要Decommission的Datanode的机器名加入到dfs.hosts.exclude(该配置项在hdfs-site.xml)所指定文件中,也就是告诉Namenode哪些Datanode要被Decommission。
把需要Decommission的节点写到文件/etc/hadoop/conf/dfs.exclude中去。
<property>
<name>dfs.hosts.exclude</name>
<value>/etc/hadoop/conf/dfs_decommission.exclude</value>
</property>
2. 用如下命令启动Decommission
#hdfs dfsadmin -refreshNodes
Decommission Datanode的时候需要保证在该Datanode移除以后,HDFS上的文件还能满足replica factor的最低要求。
比如,一个只有3个Datanode的HDFS集群,文件默认replica factor(dfs.replication参数设置)是3,那么移除任何一个Datanode都会导致某些文件不能满足replica factor的最低要求。当试图移除一个Datanode的时候,会一直处在Decommissioning的状态,因为它找不到别的机器来迁移它的数据了。这个问题通常容易出现在小集群上。
一个解决办法就是临时把相应文件的replica factor调低。
1. 用如下命令来查看HDFS中所有文件的replica factor
#hdfsfsck / -files -blocks
其中repl=1表示该文件的该block的replica factor为1。通过这个命令就可以找到那些replica factor比较高的文件了。
2 . 调整文件的replicafactor
我们需要注意的是,replica factor是文件的属性,而不是集群的属性,也就是说同一个集群中的文件可以有不同的replica factor。因此,我们需要针对文件修改replica factor。对应的命令是:
#hdfs dfs -setrep [-R] [-w] <rep><path>
其中
-
-R表示recursive,可以对一个目录及其子目录设置replica factor,即是否使用递归
-
-w表示等待复制完成,可能需要等待很长时间
-
<rep>表示需要设置的replica factor的值
-
<path>表示需要设置的replica factor的文件或目录路径
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
用人品去感动别人,用改变去影响别人,用状态去燃烧别人,用行动去带动别人,用阳光去照耀别人,用坚持去赢得别人,要求自己每天都去做与目标有关的事情,哪怕每天只进步一点点,坚持下来你就是最优秀卓越的!欢迎大家加入大数据交流群:725967421 一起交流,一起进步!!
--------------------------------------------------------------------------------------------------------------------------------------------------------------------