目录
1.多资源队列配置
1)启用公平调度器
公平调度器的使用由属性yarn.resourcemanager.scheduler.class的设置决定,YARN默认使用的是容量调度器,如果要使用公平调度器,需要将yarn-site.xml文件中的yarn.resourcemanager.scheduler.class设置为公平调度器的完全限定名,其核心配置如下。
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<property>
<name>yarn.scheduler.fair.allocation.file</name>
<value>/home/hadoop1/app/hadoop/etc/hadoop/conf/fair-scheduler.xml</value>
<!--指定Fair Scheduler 具体配置文件位置-->
</property>
2)队列配置
通过一个名为fair-scheduler.xml 的配置文件对公平调度器进行配置,该文件位于yarn.scheduler.fair.allocation.file 属性配置的路径下,其核心配置如下。
<?xml version="1.0"?>
<allocations>
<queue name="root">
<schedulingPolicy>fair</schedulingPolicy>
<aclSubmitApps>*</aclSubmitApps>
<aclAdministerApps>*</aclAdministerApps>
<queue name="default">
<minResources>1024mb, 1vcores</minResources>
<maxResources>4096mb, 4vcores</maxResources>
</queue>
<queue name="offline">
<minResources>1024mb, 1vcores</minResources>
<maxResources>2048mb, 2vcores</maxResources>
<maxRunningApps>50</maxRunningApps>
</queue>
<queue name="realtime">
<minResources>1024mb, 1vcores</minResources>
<maxResources>2048mb, 2vcores</maxResources>
<maxRunningApps>50</maxRunningApps>
</queue>
</queue>
</allocations>
2.指定队列提交任务
首先重启yarn集群,然后以Hadoop自带的wordcount为例,使用公平调度器将mapreduce应用提交到root.offline队列中运行,具体操作如下。
bin/yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.10.1.jar wordcount -Dmapreduce.job.queuename=root.offline /test/words.log /test/output4
<--输出路径随意,只要不存在即可-->
执行命令后发现任务卡在了Running Job 那里,检查问题发现是设置的队列资源过小,将资源调大即可,具体操作为将offline队列的maxResource变为4096mb。
<queue name="offline">
<minResources>1024mb, 1vcores</minResources>
<maxResources>4096mb, 2vcores</maxResources>
<maxRunningApps>50</maxRunningApps>
</queue>
更改配置后重启yarn集群,重新运行任务成功。