概念澄清与总体思路
在 Hadoop 中,负责资源管理与调度的组件是 YARN 的 ResourceManager,它与 HDFS 协同工作但职责不同。实际配置时,需要同时完成:安装与环境变量、核心与 HDFS 基础配置、YARN 资源管理器配置、MapReduce 框架指向、启动与验证等步骤。
安装与基础配置
- 安装 Java 与 Hadoop,例如在 CentOS 上安装 OpenJDK 并解压 Hadoop 至目标目录(如 /usr/local/hadoop)。
- 配置环境变量(/etc/profile 或 ~/.bashrc):
export JAVA_HOME=/path/to/java
export HADOOP_HOME=/path/to/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
执行 source 使配置生效。
- 修改 Hadoop 配置目录 $HADOOP_HOME/etc/hadoop 下的关键文件:
- core-site.xml:设置默认文件系统,例如:
fs.defaultFShdfs://your-namenode-host:8020
- hdfs-site.xml:设置副本与数据目录,例如:
dfs.replication3
dfs.namenode.name.dir/path/to/namenode/data
dfs.datanode.data.dir/path/to/datanode/data
- yarn-site.xml:指定 ResourceManager 主机与 Shuffle 服务,例如:
yarn.resourcemanager.hostnameyour-resourcemanager-host
yarn.nodemanager.aux-servicesmapreduce_shuffle
yarn.nodemanager.aux-services.mapreduce.shuffle.classorg.apache.hadoop.mapred.ShuffleHandler
- mapred-site.xml:将 MapReduce 运行在 YARN 上,例如:
mapreduce.framework.nameyarn
以上为后续启用 ResourceManager 的必要前置配置。
ResourceManager 关键配置
- 指定调度器与资源边界(yarn-site.xml):
yarn.resourcemanager.scheduler.classorg.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler
yarn.scheduler.minimum-allocation-mb1024
yarn.scheduler.maximum-allocation-mb8192
yarn.scheduler.minimum-allocation-vcores1
yarn.scheduler.maximum-allocation-vcores4
yarn.nodemanager.resource.memory-mb4096
yarn.nodemanager.resource.cpu-vcores4
yarn.scheduler.capacity.maximum-am-resource-percent0.5
- 可选:启用日志聚合(便于排查),在 yarn-site.xml 增加:
yarn.log-aggregation-enabletrue
yarn.log-aggregation.retain-seconds604800
- 容量调度队列示例(capacity-scheduler.xml):
yarn.scheduler.capacity.root.queuesdefault,queue1,queue2
yarn.scheduler.capacity.root.default.capacity50
yarn.scheduler.capacity.root.queue1.capacity25
yarn.scheduler.capacity.root.queue2.capacity25
上述参数确保 ResourceManager 能正确调度资源并支持多队列管理。
启动与验证
- 首次启动前格式化 NameNode:
hdfs namenode -format
- 启动集群:
start-dfs.sh
start-yarn.sh
- 验证进程:
jps
应能看到 ResourceManager、NodeManager、NameNode、DataNode 等关键进程。
- 访问 Web UI:
- ResourceManager:http://:8088
- NameNode(HDFS):常见为 http://:9870(部分版本为 50070)
- 运行态检查:
hdfs dfsadmin -report
yarn node -list
以上步骤可快速确认 ResourceManager 与 HDFS 是否正常工作。
防火墙与端口
- 开放常用端口(以 firewalld 为例):
firewall-cmd --permanent --zone=public --add-port=8020/tcp # HDFS RPC
firewall-cmd --permanent --zone=public --add-port=8088/tcp # ResourceManager Web
firewall-cmd --permanent --zone=public --add-port=50070/tcp # NameNode Web(若使用 9870 则开放 9870)
firewall-cmd --permanent --zone=public --add-port=50090/tcp # SecondaryNameNode
firewall-cmd --reload
确保各节点与客户端可访问上述端口,避免访问异常。