集群搭建--yarn的资源队列的配置

本文详细介绍了如何配置YARN的资源队列,包括设置队列层级、分配资源比例和权限控制。通过实例展示了如何在yarn-site.xml和capacity-scheduler.xml中进行具体配置,以及如何提交Spark程序到指定的YARN队列。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

yarn的资源队列配置

一、目标配置

root
------liu_default[20%]
------liu_1[80%]
 	  |---liu_1.a01[50%]
      |---liu_1.a02[50%]

在这里插入图片描述
在这里插入图片描述

二、配置两个文件yarn-site.xml 和 capacity-scheduler.xml

yarn-site.xml

<property>
                <name>yarn.resourcemanager.scheduler.class</name>
                <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
</property>

capacity-scheduler.xml

<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>

  <property>
    <name>yarn.scheduler.capacity.maximum-applications</name>
    <value>10000</value>
    <description>
      Maximum number of applications that can be pending and running.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
    <value>0.1</value>
    <description>
      Maximum percent of resources in the cluster which can be used to run 
      application masters i.e. controls number of concurrent running
      applications.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.resource-calculator</name>
    <value>org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator</value>
    <description>
      The ResourceCalculator implementation to be used to compare 
      Resources in the scheduler.
      The default i.e. DefaultResourceCalculator only uses Memory while
      DominantResourceCalculator uses dominant-resource to compare 
      multi-dimensional resources such as Memory, CPU etc.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.queues</name>
    <value>liu_default,liu_1</value>
    <description>
      The queues at the this level (root is the root queue).
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.liu_default.capacity</name>
    <value>20</value>
    <description>Default queue target capacity.</description>
  </property>


  <property>
    <name>yarn.scheduler.capacity.root.liu_default.user-limit-factor</name>
    <value>1</value>
    <description>
      Default queue user limit a percentage from 0.0 to 1.0.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.liu_default.maximum-capacity</name>
    <value>80</value>
    <description>
      The maximum capacity of the default queue. 
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.liu_default.state</name>
    <value>RUNNING</value>
    <description>
      The state of the default queue. State can be one of RUNNING or STOPPED.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.liu_default.acl_submit_applications</name>
    <value>*</value>
    <description>
      The ACL of who can submit jobs to the default queue.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.liu_default.acl_administer_queue</name>
    <value>*</value>
    <description>
      The ACL of who can administer jobs on the default queue.
    </description>
  </property>

  
  <property>
      <name>yarn.scheduler.capacity.root.liu_1.capacity</name>
      <value>80</value>
      <description>Default queue target capacity.</description>
  </property>
  <property>
      <name>yarn.scheduler.capacity.root.liu_1.user-limit-factor</name>
      <value>1</value>
      <description>Default queue user limit a percentage from 0.0 to 1.0.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.maximum-capacity</name>
      <value>80</value>
      <description>The maximum capacity of the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.state</name>
      <value>RUNNING</value>
      <description>The state of the default queue. State can be one of RUNNING or STOPPED.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.acl_submit_applications</name>
      <value>*</value>
      <description>The ACL of who can submit jobs to the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.acl_administer_queue</name>
      <value>*</value>
      <description>The ACL of who can administer jobs on the default queue.</description>
  </property>

  <!-- liu_1 -->
  <property>
    <name>yarn.scheduler.capacity.root.liu_1.queues</name>
    <value>a01,a02</value>
    <description>
      The queues at the this level (root is the root queue).
    </description>
  </property>
  
    <!-- a01-->
   <property>
      <name>yarn.scheduler.capacity.root.liu_1.a01.capacity</name>
      <value>50</value>
      <description>Default queue target capacity.</description>
  </property>
  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a01.user-limit-factor</name>
      <value>1</value>
      <description>Default queue user limit a percentage from 0.0 to 1.0.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a01.maximum-capacity</name>
      <value>80</value>
      <description>The maximum capacity of the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a01.state</name>
      <value>RUNNING</value>
      <description>The state of the default queue. State can be one of RUNNING or STOPPED.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a01.acl_submit_applications</name>
      <value>*</value>
      <description>The ACL of who can submit jobs to the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a01.acl_administer_queue</name>
      <value>*</value>
      <description>The ACL of who can administer jobs on the default queue.</description>
  </property>
  
  <!-- a02-->
     <property>
      <name>yarn.scheduler.capacity.root.liu_1.a02.capacity</name>
      <value>50</value>
      <description>Default queue target capacity.</description>
  </property>
  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a02.user-limit-factor</name>
      <value>1</value>
      <description>Default queue user limit a percentage from 0.0 to 1.0.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a02.maximum-capacity</name>
      <value>80</value>
      <description>The maximum capacity of the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a02.state</name>
      <value>RUNNING</value>
      <description>The state of the default queue. State can be one of RUNNING or STOPPED.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a02.acl_submit_applications</name>
      <value>*</value>
      <description>The ACL of who can submit jobs to the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.a02.acl_administer_queue</name>
      <value>*</value>
      <description>The ACL of who can administer jobs on the default queue.</description>
  </property>
  
  
  <property>
    <name>yarn.scheduler.capacity.node-locality-delay</name>
    <value>40</value>
    <description>
      Number of missed scheduling opportunities after which the CapacityScheduler 
      attempts to schedule rack-local containers. 
      Typically this should be set to number of nodes in the cluster, By default is setting 
      approximately number of nodes in one rack which is 40.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.queue-mappings</name>
    <value></value>
    <description>
      A list of mappings that will be used to assign jobs to queues
      The syntax for this list is [u|g]:[name]:[queue_name][,next mapping]*
      Typically this list will be used to map users to queues,
      for example, u:%user:%user maps all users to queues with the same name
      as the user.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.queue-mappings-override.enable</name>
    <value>false</value>
    <description>
      If a queue mapping is present, will it override the value specified
      by the user? This can be used by administrators to place jobs in queues
      that are different than the one specified by the user.
      The default is false.
    </description>
  </property> 

</configuration>

重启 yarn

stop-yarn.sh     #停止
start-yarn.sh    #启动

三、提交spark程序到指定的yarn上

 spark-submit --master  yarn-cluster --queue liu_default --class org.apache.spark.examples.SparkPi examples/jars/spark-examples_2.11-2.4.0.jar  1

在这里插入图片描述

四、附上hadoop权威指南配置的方法

capacity-scheduler.xml

<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>

  <property>
    <name>yarn.scheduler.capacity.maximum-applications</name>
    <value>10000</value>
    <description>
      Maximum number of applications that can be pending and running.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
    <value>0.1</value>
    <description>
      Maximum percent of resources in the cluster which can be used to run 
      application masters i.e. controls number of concurrent running
      applications.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.resource-calculator</name>
    <value>org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator</value>
    <description>
      The ResourceCalculator implementation to be used to compare 
      Resources in the scheduler.
      The default i.e. DefaultResourceCalculator only uses Memory while
      DominantResourceCalculator uses dominant-resource to compare 
      multi-dimensional resources such as Memory, CPU etc.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.queues</name>
    <value>prod,dev</value>
    <description>
      The queues at the this level (root is the root queue).
    </description>
  </property>
  
  <property>
    <name>yarn.scheduler.capacity.root.dev.queues</name>
	<value>eng,science</value>
  </property>
  
  <property>
    <name>yarn.scheduler.capacity.root.prod.capacity</name>
    <value>40</value>
    <description>prod queue target capacity.</description>
  </property>
  
    <property>
    <name>yarn.scheduler.capacity.root.dev.capacity</name>
    <value>60</value>
    <description>prod queue target capacity.</description>
  </property>
  
    <!-- prod -->
  <property>
    <name>yarn.scheduler.capacity.root.prod.user-limit-factor</name>
    <value>1</value>
    <description>
      prod queue user limit a percentage from 0.0 to 1.0.
    </description>
  </property>
  
  <property>
    <name>yarn.scheduler.capacity.root.prod.maximum-capacity</name>
    <value>80</value>
    <description>
      The maximum capacity of the prod queue. 
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.prod.state</name>
    <value>RUNNING</value>
    <description>
      The state of the default queue. State can be one of RUNNING or STOPPED.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.prod.acl_submit_applications</name>
    <value>*</value>
    <description>
      The ACL of who can submit jobs to the default queue.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.prod.acl_administer_queue</name>
    <value>*</value>
    <description>
      The ACL of who can administer jobs on the default queue.
    </description>
  </property>

  <!-- dev -->
  <property>
    <name>yarn.scheduler.capacity.root.dev.user-limit-factor</name>
    <value>1</value>
    <description>
      dev queue user limit a percentage from 0.0 to 1.0.
    </description>
  </property>
  

  <property>
    <name>yarn.scheduler.capacity.root.dev.maximum-capacity</name>
    <value>80</value>
    <description>
      The maximum capacity of the dev queue. 
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.dev.state</name>
    <value>RUNNING</value>
    <description>
      The state of the default queue. State can be one of RUNNING or STOPPED.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.dev.acl_submit_applications</name>
    <value>*</value>
    <description>
      The ACL of who can submit jobs to the default queue.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.dev.acl_administer_queue</name>
    <value>*</value>
    <description>
      The ACL of who can administer jobs on the default queue.
    </description>
  </property>
  
  
  <property>
    <name>yarn.scheduler.capacity.root.dev.eng.capacity</name>
    <value>50</value>
  </property>

    <property>
    <name>yarn.scheduler.capacity.root.dev.science.capacity</name>
    <value>50</value>
  </property>
  
 

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.acl_submit_applications</name>
      <value>*</value>
      <description>The ACL of who can submit jobs to the default queue.</description>
  </property>

  <property>
      <name>yarn.scheduler.capacity.root.liu_1.acl_administer_queue</name>
      <value>*</value>
      <description>The ACL of who can administer jobs on the default queue.</description>
  </property>


  
  
  
  
  <property>
    <name>yarn.scheduler.capacity.node-locality-delay</name>
    <value>40</value>
    <description>
      Number of missed scheduling opportunities after which the CapacityScheduler 
      attempts to schedule rack-local containers. 
      Typically this should be set to number of nodes in the cluster, By default is setting 
      approximately number of nodes in one rack which is 40.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.queue-mappings</name>
    <value></value>
    <description>
      A list of mappings that will be used to assign jobs to queues
      The syntax for this list is [u|g]:[name]:[queue_name][,next mapping]*
      Typically this list will be used to map users to queues,
      for example, u:%user:%user maps all users to queues with the same name
      as the user.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.queue-mappings-override.enable</name>
    <value>false</value>
    <description>
      If a queue mapping is present, will it override the value specified
      by the user? This can be used by administrators to place jobs in queues
      that are different than the one specified by the user.
      The default is false.
    </description>
  </property> 

</configuration>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值