Linux里Hadoop资源怎样分配
导读:Linux下Hadoop资源分配实践指南 一 核心架构与分配流程 在 Linux + Hadoop 环境中,资源分配由 YARN 统一负责:客户端提交作业后由 ResourceManager 分配资源,NodeManager 在节点上创建...
Linux下Hadoop资源分配实践指南
一 核心架构与分配流程
- 在 Linux + Hadoop 环境中,资源分配由 YARN 统一负责:客户端提交作业后由 ResourceManager 分配资源,NodeManager 在节点上创建容器运行任务,ApplicationMaster 负责向 RM 申请并管理本作业所需容器,NM 持续上报资源使用,作业完成后释放容器。该流程决定了从集群到作业的资源请求、分配、调度与回收的闭环。
二 节点级资源总量配置
- 在每个工作节点上,先在 yarn-site.xml 声明该节点可提供给 YARN 的总内存与总 vCPU,并设置容器分配的最小/最大值,确保调度器能按需切分资源。
- 示例(单节点总内存 16 GB、总 vCPU 8,可按需放大):
<
configuration>
<
!-- 节点可分配的物理内存总量 -->
<
property>
<
name>
yarn.nodemanager.resource.memory-mb<
/name>
<
value>
16384<
/value>
<
/property>
<
!-- 节点可分配的虚拟CPU核心总数 -->
<
property>
<
name>
yarn.nodemanager.resource.cpu-vcores<
/name>
<
value>
8<
/value>
<
/property>
<
!-- 单个容器可申请的最小/最大内存 -->
<
property>
<
name>
yarn.scheduler.minimum-allocation-mb<
/name>
<
value>
1024<
/value>
<
/property>
<
property>
<
name>
yarn.scheduler.maximum-allocation-mb<
/name>
<
value>
8192<
/value>
<
/property>
<
!-- 可选:控制AM占用集群资源的上限 -->
<
property>
<
name>
yarn.scheduler.capacity.maximum-am-resource-percent<
/name>
<
value>
0.5<
/value>
<
/property>
<
/configuration>
- 提示:调度器粒度受最小/最大容器限制;例如最小 1 GB、最大 8 GB 时,无法申请 9 GB 容器;同时应保留少量内存给操作系统与守护进程,避免 OOM。
三 队列与调度器分配
- 通过 Capacity Scheduler 或 Fair Scheduler 将集群资源按业务划分到多个队列,实现部门/项目/优先级的隔离与配额管理。
- Capacity Scheduler 示例(根队列下两个业务队列,容量各 50%):
<
configuration>
<
property>
<
name>
yarn.scheduler.capacity.root.queues<
/name>
<
value>
queueA,queueB<
/value>
<
/property>
<
property>
<
name>
yarn.scheduler.capacity.root.queueA.capacity<
/name>
<
value>
50<
/value>
<
/property>
<
property>
<
name>
yarn.scheduler.capacity.root.queueB.capacity<
/name>
<
value>
50<
/value>
<
/property>
<
/configuration>
- 也可切换到 Fair Scheduler,在 fair-scheduler.xml 中定义队列与权重/配额,并在 yarn-site.xml 指定调度器类与配置文件路径。队列化分配有助于避免单一作业占满集群,提升整体吞吐与公平性。
四 作业级内存与CPU分配
- 在 mapred-site.xml 为 Map/Reduce 任务设定容器内存与 JVM 堆,以及容器所需 vCPU;同时合理设置 Reduce 任务数量以匹配资源与数据倾斜情况。
- 示例(每个 Map/Reduce 容器 4 GB 内存,堆 3.2 GB,各 1 vCPU;Reduce 数量依据数据量与并发度调节):
<
configuration>
<
property>
<
name>
mapreduce.framework.name<
/name>
<
value>
yarn<
/value>
<
/property>
<
!-- 容器内存 -->
<
property>
<
name>
mapreduce.map.memory.mb<
/name>
<
value>
4096<
/value>
<
/property>
<
property>
<
name>
mapreduce.reduce.memory.mb<
/name>
<
value>
4096<
/value>
<
/property>
<
!-- JVM 堆(建议略小于容器内存,留出堆外开销) -->
<
property>
<
name>
mapreduce.map.java.opts<
/name>
<
value>
-Xmx3200m<
/value>
<
/property>
<
property>
<
name>
mapreduce.reduce.java.opts<
/name>
<
value>
-Xmx3200m<
/value>
<
/property>
<
!-- 容器 vCPU -->
<
property>
<
name>
mapreduce.map.cpu.vcores<
/name>
<
value>
1<
/value>
<
/property>
<
property>
<
name>
mapreduce.reduce.cpu.vcores<
/name>
<
value>
1<
/value>
<
/property>
<
!-- Reduce 数量(可按数据量与并发度调整) -->
<
property>
<
name>
mapreduce.job.reduces<
/name>
<
value>
4<
/value>
<
/property>
<
/configuration>
- 计算要点:容器内存应 ≥ JVM 堆 + 堆外(如 Direct Memory、线程栈、本地缓存);同节点上并行容器数 ≈ floor(节点总内存 / 容器内存),并受 yarn.scheduler.minimum-allocation-mb/maximum-allocation-mb 与 cpu-vcores 约束。
五 验证与运维要点
- 服务与连通性检查:启动后用 jps 确认 ResourceManager/NodeManager/NameNode/DataNode/JobHistoryServer 进程就绪;通过 ResourceManager Web UI(默认 8088) 与 NameNode Web UI(常见 50070) 查看资源与作业状态;命令行可用 yarn application -list、hdfs dfsadmin -report 辅助排查。
- 操作系统与JVM基础优化:适度提升 ulimit -n(如 65536)、优化 TCP 队列与端口范围、为关键进程设置合适的 JVM 堆与 GC 策略(如 G1GC),可显著降低连接拥塞与 GC 停顿对吞吐的影响。
- 数据布局与I/O:结合访问模式调整 HDFS 块大小(如 256 MB/512 MB) 与 副本数(默认 3),并启用 数据压缩(如 Snappy/LZO) 与 数据本地化 策略,减少网络与磁盘开销,提升作业稳定性与性能。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: Linux里Hadoop资源怎样分配
本文地址: https://pptw.com/jishu/748983.html
