【Yarn】配置公平调度器

目录

添加如下属性到yarn-site.xml

添加配置文件fair-scheduler.xml

将新的配置同步到集群所有节点,重启Yarn

创建相应的用户进行测试

提交任务

查看任务


  • 添加如下属性到yarn-site.xml

<!--  指定使用fairScheduler的调度方式  -->
<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>/export/servers/hadoop-2.6.0-cdh5.14.0/etc/hadoop/fair-scheduler.xml</value>
</property>
 
<!-- 是否启用资源抢占,如果启用,那么当该队列资源使用
yarn.scheduler.fair.preemption.cluster-utilization-threshold 这么多比例的时候,就从其他空闲队列抢占资源
  -->
<property>
       <name>yarn.scheduler.fair.preemption</name>
       <value>true</value>
</property>
 
<property>
       <name>yarn.scheduler.fair.preemption.cluster-utilization-threshold</name>
       <value>0.8f</value>
</property>
 
<!-- 默认提交到default队列  -->
<property>
       <name>yarn.scheduler.fair.user-as-default-queue</name>
       <value>true</value>
</property>
 
<!-- 如果提交一个任务没有到任何的队列,是否允许创建一个新的队列,设置false不允许  -->
<property>
       <name>yarn.scheduler.fair.allow-undeclared-pools</name>
       <value>false</value>
</property>

 

  • 添加配置文件fair-scheduler.xml

<?xml version="1.0"?>
<allocations>
<!-- users max running apps  -->
<userMaxAppsDefault>30</userMaxAppsDefault>
<!-- 定义队列  -->
<queue name="root">
         <minResources>512mb,4vcores</minResources>
         <maxResources>102400mb,100vcores</maxResources>
         <maxRunningApps>100</maxRunningApps>
         <weight>1.0</weight>
         <schedulingMode>fair</schedulingMode>
         <aclSubmitApps> </aclSubmitApps>
         <aclAdministerApps> </aclAdministerApps>
 
         <queue name="default">
                   <minResources>512mb,4vcores</minResources>
                   <maxResources>30720mb,30vcores</maxResources>
                   <maxRunningApps>100</maxRunningApps>
                   <schedulingMode>fair</schedulingMode>
                   <weight>1.0</weight>
                   <!--  所有的任务如果不指定任务队列,都提交到default队列里面来 -->
                   <aclSubmitApps>*</aclSubmitApps>
         </queue>
 
<!--
 
weight
资源池权重
 
aclSubmitApps
允许提交任务的用户名和组;
格式为: 用户名 用户组
 
当有多个用户时候,格式为:用户名1,用户名2 用户名1所属组,用户名2所属组
 
aclAdministerApps
允许管理任务的用户名和组;
 
格式同上。
 -->
         <queue name="hadoop">
                   <minResources>512mb,4vcores</minResources>
                   <maxResources>20480mb,20vcores</maxResources>
                   <maxRunningApps>100</maxRunningApps>
                   <schedulingMode>fair</schedulingMode>
                   <weight>2.0</weight>
                   <aclSubmitApps>hadoop hadoop</aclSubmitApps>
                   <aclAdministerApps>hadoop hadoop</aclAdministerApps>
         </queue>
 
         <queue name="develop">
                   <minResources>512mb,4vcores</minResources>
                   <maxResources>20480mb,20vcores</maxResources>
                   <maxRunningApps>100</maxRunningApps>
                   <schedulingMode>fair</schedulingMode>
                   <weight>1</weight>
                   <aclSubmitApps>develop develop</aclSubmitApps>
                   <aclAdministerApps>develop develop</aclAdministerApps>
         </queue>
 
         <queue name="test1">
                   <minResources>512mb,4vcores</minResources>
                   <maxResources>20480mb,20vcores</maxResources>
                   <maxRunningApps>100</maxRunningApps>
                   <schedulingMode>fair</schedulingMode>
                   <weight>1.5</weight>
                   <aclSubmitApps>test1,hadoop,develop test1</aclSubmitApps>
                   <aclAdministerApps>test1 group_businessC,supergroup</aclAdministerApps>
         </queue>
</queue>
</allocations>

 

  • 将新的配置同步到集群所有节点,重启Yarn

同步:

scp yarn-site.xml  fair-scheduler.xml node02:$PWD
scp yarn-site.xml  fair-scheduler.xml node03:$PWD

 

重启Yarn:

stop-yarn.sh
start-yarn.sh

 

  • 创建相应的用户进行测试

useradd hadoop
passwd hadoop
groupadd supergroup
usermod -a -G supergroup hadoop    修改用户所属的附加群主
su - root -s /bin/bash -c "hdfs dfsadmin -refreshUserToGroupsMappings"
刷新用户组信息
su hadoop  切换用户

 

  • 提交任务

hadoop jar /export/servers/hadoop-2.6.0-cdh5.14.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0-cdh5.14.0.jar pi 10 20

 

  • 查看任务

http://192.168.100.201:8088/cluster/scheduler

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章