聊聊 HDFS Balancer负载均衡器

简介: 聊聊 HDFS Balancer负载均衡器

1、背景

当我们的hadoop集群运行了一段时间之后,各个DataNode上的数据分布并不一定是均匀分布的。比如说: 我们向现有集群中添加了一个新的DataNode。

DataNode数据不均衡

2、什么是平衡

此处是我自己的一个简单的理解

所谓的平衡指的是 每个DataNode的利用率 与 集群的利用率 之间相差不超过给定的阈值百分比。此处的平衡 指的是各个DataNode之间的平衡,同一个DataNode之间的各个磁盘是不会平衡的。

2.1 每个DataNode的利用率计算

每个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]• 1.
• 2.
• 3.
• 4.
• 5.
• 6.
• 7.
• 8.
• 9.
• 10.
• 11.
• 12.
• 13.
• 14.
• 15.
• 16.
• 17.
• 18.
• 19.
• 20.
• 21.
• 22.
• 23.

参数

描述

threshold

磁盘容量的百分比。默认值为10%,表示上下浮动10%。

policy

平衡策略。

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 ~]$• 1.
• 2.
• 3.

当我们的集群负载需要调低这个值,当我们的集群负载较低时,可以适当调高这个值。

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 ~]$
相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
10月前
|
缓存 负载均衡 算法
【Spring Cloud系列】-负载均衡(Load Balancer,LB)
【Spring Cloud系列】-负载均衡(Load Balancer,LB)
268 1
hdfs Balancer工具使用
Balancer工具可以用来分析块的分布情况,并且可以重新分配DataNode中的数据。本文通过为您介绍如何使用Balancer工具以及Balancer的使用过程中的常见问题。
|
存储 分布式计算 Hadoop
深入浅出:Hadoop的start-balancer.sh与hdfs balancer分布式数据均衡
Hadoop的HDFS集群非常容易出现机器与机器之间磁盘利用率不平衡的情况,比如集群中添加新的数据节点。当HDFS出现不平衡状况的时候,将引发很多问题,比如:1、MR程序无法很好地利用本地计算的优势2、机器之间无法达到更好的网络带宽使用率,机器磁盘无法利用等等。
3289 0
|
存储 分布式计算 Hadoop
Hadoop2.7实战v1.0之start-balancer.sh与hdfs balancer数据均衡
Hadoop2.7实战v1.0之start-balancer.sh与hdfs balancer数据均衡【修正版】 适用场景: a.
3360 0
|
21天前
|
负载均衡 算法 应用服务中间件
面试题:Nginx有哪些负载均衡算法?Nginx位于七层网络结构中的哪一层?
字节跳动面试题:Nginx有哪些负载均衡算法?Nginx位于七层网络结构中的哪一层?
58 0
|
21天前
|
负载均衡 应用服务中间件 API
Nginx配置文件详解Nginx负载均衡Nginx静态配置Nginx反向代理
Nginx配置文件详解Nginx负载均衡Nginx静态配置Nginx反向代理
48 4
|
16天前
|
负载均衡 前端开发 应用服务中间件
Nginx+Tomcat负载均衡配置_nginx做tomcat的负载均衡成功,但tomcat的css文件400
Nginx+Tomcat负载均衡配置_nginx做tomcat的负载均衡成功,但tomcat的css文件400
|
16天前
|
负载均衡 前端开发 应用服务中间件
Nginx+Tomcat负载均衡配置_nginx做tomcat的负载均衡成功,但tomcat的css文件400(2)
Nginx+Tomcat负载均衡配置_nginx做tomcat的负载均衡成功,但tomcat的css文件400(2)
|
20天前
|
负载均衡 应用服务中间件 nginx
解决nginx配置负载均衡时invalid host in upstream报错
在Windows环境下,配置Nginx 1.11.5进行负载均衡时遇到问题,服务无法启动。错误日志显示“invalid host in upstream”。检查发现上游服务器列表中,192.168.29.128的主机地址无效。负载均衡配置中,两个服务器地址前误加了&quot;http://&quot;。修正方法是删除上游服务器列表和proxy_pass中的&quot;http://&quot;。问题解决后,Nginx服务应能正常启动。
61 4
解决nginx配置负载均衡时invalid host in upstream报错
|
21天前
|
负载均衡 网络协议 应用服务中间件
【亮剑】在Linux中构建高可用性和高性能网络服务的负载均衡工具HAProxy、Nginx和Keepalived。
【4月更文挑战第30天】本文介绍了在Linux中构建高可用性和高性能网络服务的负载均衡工具HAProxy、Nginx和Keepalived。HAProxy是一个高性能的开源TCP和HTTP负载均衡器,适合处理大量并发连接;Nginx是一个多功能Web服务器和反向代理,支持HTTP、HTTPS和TCP负载均衡,同时提供缓存和SSL功能;Keepalived用于监控和故障切换,通过VRRP实现IP热备份,保证服务连续性。文中详细阐述了如何配置这三个工具实现负载均衡,包括安装、配置文件修改和启动服务,为构建可靠的负载均衡系统提供了指导。