目录
一、问题原因
阿里云事件磁盘损坏后,使用新磁盘进行了替换,或者当发现hdfs容量不够需要扩展空间时,由运维管理人员陆陆续续为 datanode 节点增加了多块磁盘,并将这些磁盘挂载到了不同目录比如 /mnt/disk1, /mnt/disk2;此后由大数据系统管理人员配置 hdfs 使用了这些新的磁盘上的目录 (比如配置 dfs.datanode.data.dir=/mnt/disk1/dfs/data,/mnt/disk2/dfs/data,/mnt/disk3/dfs/data),并重启了 hdfs 服务使配置生效。
但是hdfs经过上述配置更改并重启生效之后,只有新增加的hdfs文件才会存储在新增加的目录下,已经存在的hdfs历史文件,其对应的底层数据是不会从原有目录移动到新增目录的。
即使使用了命令 hdfs balancer 来在集群内重新分布 hdfs 文件,由于该命令只会在不同host之间移动数据,也就是主要做的是 host 节点级别的负载均衡,上述单节点中多磁盘之间的负载不均衡问题,也不会由太大缓解。
二、diskbalancer介绍
三、diskbalancer实战
需求:磁盘 /disk2是新挂的 ,需要将一台服务器的 4块磁盘 做数据平衡。
3.1 生成plan json文件
首先要确保datanode的配置dfs.disk.balancer.enabled为true
hdfs-site.xml配置
<property>
<name>dfs.disk.balancer.enabled</name>
<value>true</value>
</property>
通过-plan生成plan:
hdfs diskbalancer -plan winner-reid-datanode07 -maxerror 5 -bandwidth 50 -thresholdpercentage 5
参数介绍:
- -bandwidth 平衡带宽,单位mb/s,默认10
- -maxerror 错误重试次数,默认5
- -thresholdpercentage 平衡阈值,默认10,即磁盘占用率大小相差<=10%则认为是平衡的
- -out 执行计划json输出路径,注意为hdfs路径,且路径需要为空
生成文件位于 hdfs
查看生成的winner-reid-datanode07.plan.json 文件内容
{
"volumesetplans": [{
"@class": "org.apache.hadoop.hdfs.server.diskbalancer.planner.movestep",
"sourcevolume": {
"path": "/disk4/",
"capacity": 5853616278016,
"storagetype": "disk",
"used": 1886035164776,
"reserved": 0,
"uuid": "ds-4073f74c-51fb-4aa1-8088-e5fce28913d4",
"failed": false,
"volumedatadensity": 9.999999999998899e-5,
"skip": false,
"transient": false,
"readonly": false
},
"destinationvolume": {
"path": "/disk2/",
"capacity": 5853616278016,
"storagetype": "disk",
"used": 1366782103125,
"reserved": 0,
"uuid": "ds-afbaacc6-adfd-4248-ab65-d83ae998ef0b",
"failed": false,
"volumedatadensity": 0.08879999999999999,
"skip": false,
"transient": false,
"readonly": false
},
"idealstorage": 0.3222,
"bytestomove": 537372946394,
"volumesetid": "234e991a-d7b1-4398-b84d-f665984fc40c",
"maxdiskerrors": 5,
"bandwidth": 5
}, {
"@class": "org.apache.hadoop.hdfs.server.diskbalancer.planner.movestep",
"sourcevolume": {
"path": "/disk1/",
"capacity": 5853616278016,
"storagetype": "disk",
"used": 1886035164776,
"reserved": 0,
"uuid": "ds-aaa27e2a-27bd-4d2f-9465-0760826404e1",
"failed": false,
"volumedatadensity": 9.999999999998899e-5,
"skip": false,
"transient": false,
"readonly": false
},
"destinationvolume": {
"path": "/disk2/",
"capacity": 5853616278016,
"storagetype": "disk",
"used": 1366782103125,
"reserved": 0,
"uuid": "ds-afbaacc6-adfd-4248-ab65-d83ae998ef0b",
"failed": false,
"volumedatadensity": 0.08879999999999999,
"skip": false,
"transient": false,
"readonly": false
},
"idealstorage": 0.3222,
"bytestomove": 524120732056,
"volumesetid": "234e991a-d7b1-4398-b84d-f665984fc40c",
"maxdiskerrors": 5,
"bandwidth": 5
}],
"nodename": "winner-reid-datanode07",
"nodeuuid": "e6f30cb6-2bf5-4eb9-a5ab-4eb2b39ab3d7",
"port": 8010,
"timestamp": 1715934031482
}
3.2 执行plan json文件
通过-execute执行plan阶段生成的plan文件:
hdfs diskbalancer -execute /system/diskbalancer/2024-may-17-16-00-04/winner-reid-datanode07.plan.json
查询指定datanode磁盘balance的状况
hdfs diskbalancer -query winner-reid-datanode07
看到plan_under_progress 表示正在平衡,plan_done 表示完成
如下开始disk banlance
如下已完成disk banlance
取消指定datanode的磁盘均衡
hdfs diskbalancer -cancel xx.json
发表评论