HDFS数据均衡篇

                                   作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

一.HDFS数据均衡概述

  随着时间的推移,HDFS存储中数据分布可能变得不平衡,某些DataNode上可能具有更多的数据块。在极端的情况下,在具有更多的节点上读取和写入过于频繁,而一些较少的节点则未被充分利用。

  当向集群添加新节点时,HDFS的数据分布也会失去平衡。Hadoop不会自动移动现有数据到新节点,以均衡集群Datanode中的数据分布。它只是开始使用新的DataNode来存储新数据。

  Hadoop不寻求实现完全均衡的集群。在具有连续数据流的集群中,这种状态很难实现。相反,当每个Datanode上的空间使用率与Hadoop集群总的空间使用率的差值小于特定百分比时,Hadoop认为集群是均衡的。此外,它还利用阈值为数据均衡提供灵活性。

  Hadoop提供了一个有用的工具,即均衡器,使用它能够重新均衡集群的快分布,因此所有DataNode都存储大致相等的数据量。

  温馨提示:
    在集群中定期运行HDFS均衡器是一个很好的做法。

 

二.HDFS数据不均衡的原因

  HDFS不能保证在集群中的DataNode之间均匀分配数据。例如,当向集群添加新节点时,所有新块都可以分配给该节点,从而使数据分布不均衡。

  当Namenode将数据块分配给Datanode时,它执行以下标准来决定哪些DataNode获得新的块:
    (1)在集群的DataNode上统一分布数据;
    (2)正在写该块的节点保留数据块的一个副本;
    (3)将其中一个副本放置在与写入块节点相同的机架上,以最小化跨机架网络I/O;
    (4)将副本跨机架进行复制,以支持冗余并在整个机架丢失后继续运行;

  当给定Datanode中的空间百分比越高于或低于该集群中Datanode所使用的平均空间百分比时,Hadoop会认为集群时均衡的。这个"略高于或者略低于"的标准有参数阈值定义。

 

三.运行均衡器以均衡HDFS数据

1>.HDFS均衡器原理

  HDFS均衡器是Hadoop提供的工具,使用该工具可以从过度使用的DataNodes移动数据块到利用不足的Datanode,从而均衡集群的DataNode数据。

  HDFS均衡器的原理如下图所示,最初Rack 1和Rack 2有数据块。新的机架(Rack 3)没有数据,而且只有新添加的数据才被放置在那里。

  这意味着添加节点导致集群数据不均衡。需要将现有DataNode的数据移动到新的没有数据的DataNode(或者添加新数据时将数据直接写入到新节点)。

  当运行均衡器时,Hadoop将数据块从现有位置移动到具有更多自由空间的节点,最终所有节点具有大致相同的空间使用率。

 

2>.运行均衡器的方式

可以通过"start-balancer.sh"脚本调用均衡器,也可以通过执行命令"hdfs balancer"来运行均衡器。下面是balancer命令的用法:

[root@hadoop101.yinzhengjie.com
~]# hdfs balancer --help Usage: hdfs balancer [-policy <policy>] the balancing policy: datanode or blockpool [-threshold <threshold>] Percentage of disk capacity [-exclude [-f <hosts-file> | <comma-separated list of hosts>]] Excludes the specified datanodes. [-include [-f <hosts-file> | <comma-separated list of hosts>]] Includes only the specified datanodes. [-source [-f <hosts-file> | <comma-separated list of hosts>]] Pick only the specified datanodes as source nodes. [-blockpools <comma-separated list of blockpool ids>] The balancer will only run on blockpools included in this list. [-idleiterations <idleiterations>] Number of consecutive idle iterations (-1 for Infinite) before exit. [-runDuringUpgrade] Whether to run the balancer during an ongoing HDFS upgrade.This is usually not desired since it will not affect used space on over-utilized machines. Generic options supported are: -conf <configuration file> specify an application configuration file -D <property=value> define a value for a given property -fs <file:///|hdfs://namenode:port> specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations. -jt <local|resourcemanager:port> specify a ResourceManager -files <file1,...> specify a comma-separated list of files to be copied to the map reduce cluster -libjars <jar1,...> specify a comma-separated list of jar files to be included in the classpath -archives <archive1,...> specify a comma-separated list of archives to be unarchived on the compute machines The general command line syntax is: command [genericOptions] [commandOptions] [root@hadoop101.yinzhengjie.com ~]#

3>.为均衡器设置适当的阈值

  threshold参数表示每个DataNode的HDFS使用率于集群的平均DFS利用率的偏差百分比。以任意一方式(更高或更低)超过该阈值将意味着该节点会被重新均衡。

  如下面的案例所示,可以运行不带任何参数的balancer命令,则此均衡器明朗了使用10%的默认阈值,这意味着均衡器通过将块从过度使用的节点移动到未充分使用的节点来均衡数据,直到每个Datanode的磁盘使用率不超过集群中平均磁盘使用率的正负10%。   有时,可能希望将阈值设置为不同的级别,例如,当集群中的可用空间变小,并且你希望将单个DataNode上使用的存储量保持在比默认的10%阈值更小的范围内时,可以这样指定阈值"hdfs balancer -threshold 5"
  当运行均衡器时,它会查看集群中的两个关键HDFS使用情况值:
    (1)平均DFS使用百分比:
        可以通过计算得到集群中使用的平均DFS百分比:"Average DFS Used = (DFS Used * 100) / Present Capacity"
    (2)节点使用的DFS百分比:
        此度量显示每个节点使用的DFS百分比。
[root@hadoop101.yinzhengjie.com ~]# hdfs balancer           #运行均衡器若不带任何参数的balancer命令,则使用默认阈值(10%)。
20/08/20 18:59:50 INFO balancer.Balancer: namenodes  = [hdfs://hadoop101.yinzhengjie.com:9000]
20/08/20 18:59:50 INFO balancer.Balancer: parameters = Balancer.BalancerParameters [BalancingPolicy.Node, threshold = 10.0, max idle iteration = 5, #excluded nodes = 0, #included nodes = 0,
 #source nodes = 0, #blockpools = 0, run during upgrade = false]20/08/20 18:59:50 INFO balancer.Balancer: included nodes = []
20/08/20 18:59:50 INFO balancer.Balancer: excluded nodes = []
20/08/20 18:59:50 INFO balancer.Balancer: source nodes = []
Time Stamp               Iteration#  Bytes Already Moved  Bytes Left To Move  Bytes Being Moved
20/08/20 18:59:51 INFO balancer.Balancer: dfs.balancer.movedWinWidth = 5400000 (default=5400000)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.balancer.moverThreads = 1000 (default=1000)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.balancer.dispatcherThreads = 200 (default=200)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.datanode.balance.max.concurrent.moves = 50 (default=50)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.balancer.getBlocks.size = 2147483648 (default=2147483648)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.balancer.getBlocks.min-block-size = 10485760 (default=10485760)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.balancer.max-size-to-move = 10737418240 (default=10737418240)
20/08/20 18:59:51 INFO balancer.Balancer: dfs.blocksize = 536870912 (default=134217728)
20/08/20 18:59:51 INFO net.NetworkTopology: Adding a new node: /rack001/172.200.6.102:50010
20/08/20 18:59:51 INFO net.NetworkTopology: Adding a new node: /rack002/172.200.6.104:50010
20/08/20 18:59:51 INFO net.NetworkTopology: Adding a new node: /rack002/172.200.6.103:50010
20/08/20 18:59:51 INFO balancer.Balancer: 0 over-utilized: []
20/08/20 18:59:51 INFO balancer.Balancer: 0 underutilized: []
The cluster is balanced. Exiting...
Aug 20, 2020 6:59:51 PM           0                  0 B                 0 B                0 B
Aug 20, 2020 6:59:51 PM  Balancing took 764.0 milliseconds
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs balancer           #运行均衡器若不带任何参数的balancer命令,则使用默认阈值(10%)。

相关文章:

  • 2021-08-29
  • 2020-02-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2021-11-11
猜你喜欢
  • 2022-02-22
  • 2021-06-08
  • 2022-12-23
  • 2021-10-16
  • 2021-12-11
  • 2021-10-09
  • 2022-01-27
相关资源
相似解决方案