1、背景
当咱们的 hadoop 集群运行了一段时间之后,各个 DataNode
上的 数据分布
并不肯定
是均匀分布
的。比如说: 咱们向现有集群中增加了一个新的 DataNode。
2、什么是均衡
此处是我本人的一个简略的了解
所谓的均衡指的是 每个 DataNode 的利用率
与 集群的利用率
之间相差不超过给定的阈值百分比。 此处的均衡 指的是各个 DataNode 之间的均衡,同一个 DataNode 之间的各个磁盘是不会均衡的。
2.1 每个 DataNode 的利用率计算
DataNode 的利用率 =
dfs 已用的空间 / 调配给 dfs 的空间。
留神: 调配给 dfs 的空间
不是磁盘的总空间。
2.2 集群的利用率
集群的利用率 =
各 datanode dfs 已应用的空间 / 各 datanode 总空间
2.3 均衡
假如均衡的 阈值
是 5%,集群的利用率是 37.5
,那么每个节点的利用率在 32.5%
到42.5%
之间都认为是平衡的。也就是说,极其状况下,DataNode 的利用率最大相差10%
。
3、hdfs balancer 语法
[hadoopdeploy@hadoop01 ~]$ 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.
[-asService] Run as a long running service.
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]
参数 | 形容 |
---|---|
threshold | 磁盘容量的百分比。默认值为 10%,示意高低浮动 10%。 |
policy | 均衡策略。<br/> datanode(默认):当每一个 DataNode 是均衡的时候,集群就是均衡的。 blockpool:当每一个 DataNode 中的 blockpool 是均衡的,集群就是均衡的。 |
exclude | 不参加均衡的 DataNode 节点 |
include | 参加均衡的 DataNode 节点 |
source | 仅选取指定的数据节点作为源节点 |
blockpools | Balancer 仅在指定的 blockpools 中运行 |
idleiterations | 退出前的间断闲暇迭代次数(- 1 示意有限) |
-runDuringUpgrade | 是否在正在进行的 HDFS 降级过程中运行平衡器。通常不须要这样做,因为这不会影响适度应用的计算机上的已用空间。 |
-asService | 作为长期运行的服务运行 |
4、运行一个简略的 balance 案例
4.1 设置均衡数据传输带宽
[hadoopdeploy@hadoop01 ~]$ hdfs dfsadmin -setBalancerBandwidth 10485760
Balancer bandwidth is set to 10485760
[hadoopdeploy@hadoop01 ~]$
当咱们的集群负载须要调低这个值,当咱们的集群负载较低时,能够适当调高这个值。
4.2 执行 banalce
[hadoopdeploy@hadoop01 ~]$ hdfs balancer -policy datanode -threshold 5
2023-03-26 14:10:09,785 INFO balancer.Balancer: Using a threshold of 5.0
2023-03-26 14:10:09,786 INFO balancer.Balancer: namenodes = [hdfs://hadoop01:8020]
2023-03-26 14:10:09,786 INFO balancer.Balancer: parameters = Balancer.BalancerParameters [BalancingPolicy.Node, threshold = 5.0, max idle iteration = 5, #excluded nodes = 0, #included nodes = 0, #source nodes = 0, #blockpools = 0, run during upgrade = false]
2023-03-26 14:10:09,786 INFO balancer.Balancer: included nodes = []
2023-03-26 14:10:09,786 INFO balancer.Balancer: excluded nodes = []
2023-03-26 14:10:09,786 INFO balancer.Balancer: source nodes = []
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved NameNode
2023-03-26 14:10:09,787 INFO balancer.NameNodeConnector: getBlocks calls for hdfs://hadoop01:8020 will be rate-limited to 20 per second
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.namenode.get-blocks.max-qps = 20 (default=20)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.balancer.movedWinWidth = 5400000 (default=5400000)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.balancer.moverThreads = 1000 (default=1000)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.balancer.dispatcherThreads = 200 (default=200)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.balancer.getBlocks.size = 2147483648 (default=2147483648)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.balancer.getBlocks.min-block-size = 10485760 (default=10485760)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.datanode.balance.max.concurrent.moves = 100 (default=100)
2023-03-26 14:10:10,392 INFO balancer.Balancer: dfs.datanode.balance.bandwidthPerSec = 104857600 (default=104857600)
2023-03-26 14:10:10,395 INFO balancer.Balancer: dfs.balancer.max-size-to-move = 10737418240 (default=10737418240)
2023-03-26 14:10:10,395 INFO balancer.Balancer: dfs.blocksize = 134217728 (default=134217728)
2023-03-26 14:10:10,401 INFO net.NetworkTopology: Adding a new node: /default-rack/192.168.121.141:9866
2023-03-26 14:10:10,401 INFO net.NetworkTopology: Adding a new node: /default-rack/192.168.121.140:9866
2023-03-26 14:10:10,401 INFO net.NetworkTopology: Adding a new node: /default-rack/192.168.121.142:9866
2023-03-26 14:10:10,402 INFO balancer.Balancer: 0 over-utilized: []
2023-03-26 14:10:10,402 INFO balancer.Balancer: 0 underutilized: []
2023-3-26 14:10:10 0 0 B 0 B 0 B 0 hdfs://hadoop01:8020
The cluster is balanced. Exiting...
2023-3-26 14:10:10 Balancing took 810.0 milliseconds
[hadoopdeploy@hadoop01 ~]$
5、参考文档
1、https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/HdfsUserGuide.html#Balancer
2、https://help.aliyun.com/document_detail/449686.html