何为数据平衡

使数据尽可能均匀的分布到所有DataNode。\
分三种:

  • 节点间平衡
  • 节点内磁盘平衡
  • 机架平衡

    为何需要数据平衡

    数据平衡的使用

  1. hdfs balancer
  1. hdfs diskbalancer

start-balancer.sh

配置

  • dfs.balancer.moverThreads/dispatcherThreads:
  • dfs.datanode.balance.max.concurrent.moves
  • dfs.balancer.max-size-to-move
  • dfs.datanode.balance.bandwidthPerSec

数据平衡的原理

节点均衡、机架均衡、磁盘均衡。
HDFS集群非常容易出现机器与机器之间磁盘利用率不平衡的情况。例如:当集群内新增、删除节点,或者某个节点机器内硬盘存储达到饱和值。当数据不平衡时,Map任务可能会分配到没有存储数据的机器,这将导致网络带宽的消耗,也无法很好的进行本地计算。
image.png

  1. Rebalancing Server(均衡服务)要求NN生成DN的数据分布分析报告,获取每个DN磁盘使用情况。
  2. Rebalancing Server汇总需要迁移的数据分布情况,计算数据块路线图。
  3. Proxy Source Data Node复制一个数据块,复制到目标DataNode,删除原始数据块。
  4. 目标DataNode向Proxy Source Data Node 确认完成。
  5. Proxy Source Data Node 向 Rebalancing Server确认本次数据块完成。继续下一块。

    DataNode分组

    Over、Above、Below、Under。Over和Above向Below和Under迁移数据。
    image.png

脚本与配置

  1. #启动数据均衡,默认阈值为 10%
  2. ${HADOOP_HOME}/bin/start-balancer.sh
  3. #启动数据均衡,阈值 5%
  4. ${HADOOP_HOME}/bin/start-balancer.sh threshold 5
  5. #停止数据均衡
  6. ${HADOOP_HOME}/bin/stop-balancer.sh

数据平衡占用带宽限制默认1048576(1MB/s)
hdfs-site.xml

  1. <property>
  2. <name>dfs.balance.bandwidthPerSec</name>
  3. <value>1048576</value>
  4. <description> Specifies the maximum bandwidth that each datanode can utilize for the balancing purpose in term of the number of bytes per second. </description>
  5. </property>