大数据学习笔记-Yarn(二)

  1. Yarn WebUI服务

1.1 yarn wenUI

服务,http://RMHOST:8088

打开页面,以列表的形式展示处于各种状态的各种程序

以下参数指定UI地址

UI 页面的参数介绍(图片来源黑马程序员教程)

1.2 Job HistoryServer服务

仅存储已经完成的Mapredyce应用程序的作业历史信息,当启用JHS服务时,建议开启日志聚合功能。

配置

<!--mapred-site中添加配置-->
<property>
        <name>mapreduce.jobhistory.address</name>
        <value>node1.itcast.cn:10020</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>node1.itcast.cn:19888</value>
    </property>
<!--yarn-site中添加配置-->
<property>
        <name>yarn.log-aggregation-enable</name>
        <value>true</value>
    </property>
    <property>
        <name>yarn.nodemanager.remote-app-log-dir</name>
        <value>/app-logs</value>
    </property>
    <property>
        <name>yarn.log.server.url</name>
        <value>http://node1.itcast.cn:19888/jobhistory/logs</value>
    </property>

服务启动

mapred --daemon start historyserver

历史服务页面

1.3TimeLineServer

:由于Job History Server仅对MapReduce应用程序提供历史信息服务,其他程序的历史信息自己提供,如Spark自己提供的org.apache.spark.deploy.history.HistoryServer来解决应用历史信息。

为了解决这个问题Yarn新增了Timeline Server组件,以通用的方式存储和检索应用程序当前和历史信息.

到目前,有V1、V1.5和V2共三个版本,V1仅限于写入器/读取器和存储的单个实例,无法很好地扩展到小型群集之外;V2还处于alpha状态,所以在本章以V1.5

配置

<!-- 设置是否开启/使用Yarn Timeline服务 -->
<property>
    <name>yarn.timeline-service.enabled</name>
    <value>true</value>
</property>
<!-- 设置RM是否发布信息到Timeline服务器 -->
<property>
    <name>yarn.resourcemanager.system-metrics-publisher.enabled</name>
    <value>true</value>
</property>
<!-- 设置是否从Timeline history-service中获取常规信息,如果为否,则是通过RM获取 -->
<property>
    <name>yarn.timeline-service.generic-application-history.enabled</name>
    <value>true</value>
</property>
<!-- 设置Timeline Service Web App的主机名 -->
<property>
    <name>yarn.timeline-service.hostname</name>
    <value>node1.itcast.cn</value>
</property>
<!-- 设置http是否允许CORS(跨域资源共享,Cross-Origin Resource Sharing) -->
<property>
    <name>yarn.timeline-service.http-cross-origin.enabled</name>
    <value>true</value>
</property>

启动服务

yarn --daemon start timelineserver

访问地址

http://node1:8188

  1. YARN操作维护命令

Yarn给用户提供了一个脚本命令,位置${HADOOP_HOME}/bin/yarn

  1. 不带任何参数的yarn命令,会给出提示

  1. 官网指导地址https://hadoop.apache.org/docs/r3.1.4/hadoop-yarn/hadoop-yarn-site/YarnCommands.html

2.1 User用户命令

application使用方式

yarn application [option]

相关操作

# 仅显示状态为SUBMITTED、ACCEPTED、RUNNING应用
yarn application -list
# 查看状态为all 的application列表
yarn application -list -appStates ALL
# 杀死某一个Application
yarn application -kill [application_id]
# 移动一个Application到default队列
yarn application -movetoqueue application_1573364048641_0004 -queue default

jar使用方式

yarn jar xxx.jar [mainClass] args

相关操作

# 执行jar包到yarn上
yarn jar hadoop-mapreduce-examples-3.1.4.jar pi 2 2

applicationtempt使用方式

# attempt理解为尝试,一个app应用内部的一次尝试执行过程(AM Task)
yarn applicationattempt[option]

相关操作

# 查看某个应用所有的attempt
yarn applicationattempt -list application_1614179148030_0001
# 标记applicationattempt失败
yarn applicationattempt -fail appattempt_1573364048641_0004_000001
#查看具体某一个applicationattemp的报告
yarn applicationattempt -status appattempt_1614179148030_0001_000001

container使用方式

yarn container [options]

相关操作

# 查看某一个applicationattempt下所有的container
yarn container -list appattempt_1614179148030_0001_000001
#

logs使用方式

yarn logs -applicationId <application ID> [options]

queue使用方式

# 查看队列状态
yarn queue [options]

node使用方式

yarn node [options]

version使用方式

yarn version

2.2 Admin管理员命令

  • 管理员命令

resourcemanager|nodemanager使用方式

# 针对RM的操作命令
yarn resourcemanager [options]

相关操作

#启动某个节点的resourcemanager
yarn resourcemanager
#启动某个节点的nodemanager
yarn nodemanager
# 格式化resourcemanager的RMStateStore
yarn resourcemanager -format-state-store
#删除RMStateStore中的Application
yarn resourcemanager -remove-application-from-state-store <appId>

proxyserver使用方式

#启动某个节点的proxyserver,使用代理的原因是为了减少通过YARN进行基于Web的攻击的可能性。
yarn proxyserver

需要在yarn-site中提前配置

<property>
    <name>yarn.web-proxy.address</name>
    <value>node3.btks.cn:8089</value>
</property>

daemonlog使用方式

yarn daemonlog -getlevel <host:httpport> <classname>
yarn daemonlog -setlevel <host:httpport> <classname> <level>

具体操作

#查看帮助
yarn daemonlog --help
#查看RMAppImpl的日志级别
yarn daemonlog -getlevel \ 
node1.btks.cn:8088 org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl
#设置RMAppImpl的日志级别
yarn daemonlog -setlevel \ 
node1.btks.cn:8088 org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl DEBUG

rmadmin使用方式

yarn rmadmin [options]

具体操作

#重新加载mapred-queues配置文件
yarn rmadmin -refreshQueues
#刷新ResourceManager的主机信息
yarn rmadmin -refreshNodes
#在ResourceManager上刷新NodeManager的资源
yarn rmadmin -refreshNodesResources
#刷新超级用户代理组映射
yarn rmadmin -refreshSuperUserGroupsConfiguration
#刷新ACL以管理ResourceManager:
yarn rmadmin -refreshAdminAcls
#获取ResourceManager服务的Active/Standby状态
yarn rmadmin -getAllServiceState
#ResourceManager服务执行健康检查,如果检查失败,RMAdmin工具将使用非零退出码退出。
yarn rmadmin -checkHealth rm1
yarn rmadmin -checkHealth rm2

timelineserver使用方式

yarn timelineserver
#启动时间轴服务 通常使用下面的命令启动
yarn-daemon.sh start timelineserver
# 更常用
yarn --daemon start timelineserver
  1. YARN资源管理与隔离

管理两种资源memory和cpu资源,资源管理由Resourcemanager和NodeManager共同完成。

资源调度分配:Resourcenamager

资源隔离:NodeManager

3.1Memory资源

Yarn允许用户配置每个节点上可用的物理内存资源;

核心配置参数

#参数一:yarn.nodemanager.resource.memory-mb
该节点上YARN可使用的物理内存总量,默认是8192(MB);
如果设置为-1,并且yarn.nodemanager.resource.detect-hardware-capabilities为true时,将会自动计算操作系统内存进行设置。
#参数二:yarn.nodemanager.vmem-pmem-ratio
任务每使用1MB物理内存,最多可使用虚拟内存量,默认是2:1
#参数三:yarn.nodemanager.pmem-check-enabled
是否启动一个线程检查每个任务正使用的物理内存量,如果任务超出分配值,则直接将其杀掉,默认是true。
#参数四:yarn.nodemanager.vmem-check-enabled
是否启动一个线程检查每个任务正使用的虚拟内存量,如果任务超出分配值,则直接将其杀掉,默认是true。
#参数五:yarn.scheduler.minimum-allocation-mb
单个任务可申请的最少物理内存量,默认是1024(MB),如果一个任务申请的物理内存量少于该值,则该对应的值改为这个数。
#参数六:yarn.scheduler.maximum-allocation-mb
单个任务可申请的最多物理内存量,默认是8192(MB)。

YARN采用了线程监控的方法判断任务是否超量使用内存,一旦超过,则之间将其杀死。Yarn未提供Cgroups内存隔离机制。

3.2CPU资源

CPU资源的组织方式仍在探索中,当前只是非常粗粒度的实现方式

CPU被划分成虚拟CPU(CPU virtual Core),此处的虚拟CPU是YARN引入的概念

核心参数配置

#参数一:yarn.nodemanager.resource.cpu-vcores
该节点上YARN可使用的虚拟CPU个数,默认是8,注意,目前推荐将该值设值为与物理CPU核数数目相同。如果你的节点CPU核数不够8个,则需要调减小这个值。
如果设置为-1,并且yarn.nodemanager.resource.detect-hardware-capabilities为true时,将会自动计算操作系统CPU核数进行设置。
#参数二:yarn.scheduler.minimum-allocation-vcores
单个任务可申请的最小虚拟CPU个数,默认是1,如果一个任务申请的CPU个数少于该数,则该对应的值改为这个数。
#参数三:yarn.scheduler.maximum-allocation-vcores
单个任务可申请的最多虚拟CPU个数,默认是4。
  1. YARN资源调度器Scheduler

资源是有限的,并且在繁忙的集群上,应用程序通常需要等待某些请求的到满足。

YARN调度程序的工作就是定义一些策略为应用程序分配资源

YARN负责应用资源分配的就是Scheduler,它是RseourceManager的核心组件之一

没有最佳,只有适合的

三种调度器

  • FIFOScheduler(先进先出调度器)、

  • Capacity Scheduler(容量调度器)、

  • Fair Scheduler(公平调度器)。

Apache版本YARN默认使用 Capacity Scheduler

如果需要使用其他调度器,可以在yarn-site中的yarn.resourcemanager.scheduler.class配置。

工作队列是从不同客户端收到的各种任务的集合

Yarn默认只有一个可用于提交任务的队列,队列树的结构。

在YARN中,层级有队列组织方法,它们构成一个树结构,且根队列叫做root

FIFOScheduler(先进先出调度器)

Hadoop1.x中的JobTracher原有的调度器实现

先提交的应用先运行,不考虑优先级和范围,适用于负载较低的小规模集群

拥有宇哥控制全局的队列queue,默认queue名称为default

优势:无需配置、先到先得、易于执行

劣势:任务优先级不会变高,大任务阻塞

配置

<property>
    <name>yarn.resourcemanager.scheduler.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler</value>
</property>

Capacity Scheduler容量调度

允许多个组织共享整个集群资源,是Apache Hadoop3.x默认调度策略

通过为每个组织分配专门的队列,然后再为每个队列分配一定的集群资源

队列内部采用先进先出

一个个队列有独立的资源,队列的结构和资源是可以配置,在队列的基础上可以划分子队列,子队列在父队列的基础上再分配资源。

特性优势

  • 层次化的队列设计:更容易合理分配和限制资源使用

  • 容量保证:每个队列设定容量占比,每个队列不会占用整个集群资源

  • 安全:每个队列有严格的访问控制

  • 弹性分配:空闲的资源可以分配

  • 多租户使用:多个用户可以共享同一个集群

  • 操作性:动态修改队列容量

  • 基于用户、组的队列映射

默认配置

Hadoop3.x默认调度策略就是Capacity,官方自带默认配置HADOOP_CONF/capacity-scheduler.xml

默认全局只有一个队列default,占集群整体容量的100%

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

相关配置参数

核心就是队列的分配和使用,修改HADOOP_CONF/capacity_scheduler.xml文件可以配置队列

示例(树形结构)

<property>
    <name>yarn.scheduler.capacity.root.queues</name>
    <value>a,b,c</value>
</property>
<property>
    <name>yarn.scheduler.capacity.root.a.queues</name>
    <value>a1,a2</value>
</property>
<property>
   <name>yarn.scheduler.capacity.root.b.queues</name>
    <value>b1,b2</value>
</property>

队列属性

官方自带的配置

<!--
  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>
    <!-- 集群中最大可运行AM资源的占比,可用于控制并发运行的程序个数 -->
  <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>
  <!-- 队列树组织结构配置 -->
  <!-- yarn.scheduler.capacity.<queue-path>.queues -->
  <property>
    <name>yarn.scheduler.capacity.root.queues</name>
    <value>default</value>
    <description>
      The queues at the this level (root is the root queue).
    </description>
  </property>
    
    <!-- 队列的资源容量占比(百分比):同一层的所有队列加起来必须是100%。 -->
    <!-- yarn.scheduler.capacity.<queue-path>.capacity -->
  <property>
    <name>yarn.scheduler.capacity.root.default.capacity</name>
    <value>100</value>
    <description>Default queue target capacity.</description>
  </property>
    <!--     每个用户最多使用的队列资源占比 -->
  <property>
    <name>yarn.scheduler.capacity.root.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.default.maximum-capacity</name>
    <value>100</value>
    <description>
      The maximum capacity of the default queue. 
    </description>
  </property>
    
    <!-- 设置队列的状态,如果为STOPPED,则新任务不会提交该队列 -->
  <property>
    <name>yarn.scheduler.capacity.root.default.state</name>
    <value>RUNNING</value>
    <description>
      The state of the default queue. State can be one of RUNNING or STOPPED.
    </description>
  </property>
<!--     访问控制列表ACL:控制谁可以向该队列提交任务 -->
  <property>
    <name>yarn.scheduler.capacity.root.default.acl_submit_applications</name>
    <value>*</value>
    <description>
      The ACL of who can submit jobs to the default queue.
    </description>
  </property>
<!--     设置队列的管理员的ACL控制 -->
  <property>
    <name>yarn.scheduler.capacity.root.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.default.acl_application_max_priority</name>
    <value>*</value>
    <description>
      The ACL of who can submit applications with configured priority.
      For e.g, [user={name} group={name} max_priority={priority} default_priority={priority}]
    </description>
  </property>

   <property>
     <name>yarn.scheduler.capacity.root.default.maximum-application-lifetime
     </name>
     <value>-1</value>
     <description>
        Maximum lifetime of an application which is submitted to a queue
        in seconds. Any value less than or equal to zero will be considered as
        disabled.
        This will be a hard time limit for all applications in this
        queue. If positive value is configured then any application submitted
        to this queue will be killed after exceeds the configured lifetime.
        User can also specify lifetime per application basis in
        application submission context. But user lifetime will be
        overridden if it exceeds queue maximum lifetime. It is point-in-time
        configuration.
        Note : Configuring too low value will result in killing application
        sooner. This feature is applicable only for leaf queue.
     </description>
   </property>

   <property>
     <name>yarn.scheduler.capacity.root.default.default-application-lifetime
     </name>
     <value>-1</value>
     <description>
        Default lifetime of an application which is submitted to a queue
        in seconds. Any value less than or equal to zero will be considered as
        disabled.
        If the user has not submitted application with lifetime value then this
        value will be taken. It is point-in-time configuration.
        Note : Default lifetime can't exceed maximum lifetime. This feature is
        applicable only for leaf 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.
      When setting this parameter, the size of the cluster should be taken into account.
      We use 40 as the default value, which is approximately the number of nodes in one rack.
      Note, if this value is -1, the locality constraint in the container request
      will be ignored, which disables the delay scheduling.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.rack-locality-additional-delay</name>
    <value>-1</value>
    <description>
      Number of additional missed scheduling opportunities over the node-locality-delay
      ones, after which the CapacityScheduler attempts to schedule off-switch containers,
      instead of rack-local ones.
      Example: with node-locality-delay=40 and rack-locality-delay=20, the scheduler will
      attempt rack-local assignments after 40 missed opportunities, and off-switch assignments
      after 40+20=60 missed opportunities.
      When setting this parameter, the size of the cluster should be taken into account.
      We use -1 as the default value, which disables this feature. In this case, the number
      of missed opportunities for assigning off-switch containers is calculated based on
      the number of containers and unique locations specified in the resource request,
      as well as the size of the cluster.
    </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>

  <property>
    <name>yarn.scheduler.capacity.per-node-heartbeat.maximum-offswitch-assignments</name>
    <value>1</value>
    <description>
      Controls the number of OFF_SWITCH assignments allowed
      during a node's heartbeat. Increasing this value can improve
      scheduling rate for OFF_SWITCH containers. Lower values reduce
      "clumping" of applications on particular nodes. The default is 1.
      Legal values are 1-MAX_INT. This config is refreshable.
    </description>
  </property>


  <property>
    <name>yarn.scheduler.capacity.application.fail-fast</name>
    <value>false</value>
    <description>
      Whether RM should fail during recovery if previous applications'
      queue is no longer valid.
    </description>
  </property>

  <property>
    <name>yarn.scheduler.capacity.workflow-priority-mappings</name>
    <value></value>
    <description>
      A list of mappings that will be used to override application priority.
      The syntax for this list is
      [workflowId]:[full_queue_name]:[priority][,next mapping]*
      where an application submitted (or mapped to) queue "full_queue_name"
      and workflowId "workflowId" (as specified in application submission
      context) will be given priority "priority".
    </description>
  </property>

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

</configuration>

案例配置


<configuration>
    <!-- root下分为两个队列,分别为prod和dev -->  
    <property>
        <name>yarn.scheduler.capacity.root.queues</name>
        <value>prod,dev</value> 
    </property>
    <!-- dev继续分为两个队列,分别为eng和science -->      
    <property>
        <name>yarn.scheduler.capacity.root.dev.queues</name>
        <value>eng,science</value> 
    </property>
    <!-- 设置prod队列40% -->      
    <property>
        <name>yarn.scheduler.capacity.root.prod.capacity</name>
        <value>40</value>
    </property> 
    <!-- 设置dev队列60% -->  
    <property>
        <name>yarn.scheduler.capacity.root.dev.capacity</name>
        <value>60</value> 
    </property>
    <!-- 设置dev队列可使用的资源上限为75% -->  
    <property>
        <name>yarn.scheduler.capacity.root.dev.maximum-capacity</name>
        <value>75</value> 
    </property>
    <!-- 设置eng队列50% -->    
    <property>
        <name>yarn.scheduler.capacity.root.dev.eng.capacity</name>
        <value>50</value> 
    </property>
    <!-- 设置science队列50% -->   
    <property>
        <name>yarn.scheduler.capacity.root.dev.science.capacity</name>
        <value>50</value>
    </property>
</configuration>

同步配置文件到其他节点

[root@node1 hadoop]# pwd
/export/server/hadoop-3.1.4/etc/hadoop
[root@node1 hadoop]# scp capacity-scheduler.xml root@node2:$PWD
capacity-scheduler.xml                     100% 1105     1.1MB/s   00:00    
[root@node1 hadoop]# scp capacity-scheduler.xml root@node3:$PWD

重启yarn

stop-yarn.sh
start-yarn.sh

提交作业,指定队列

 yarn jar hadoop-mapreduce-examples-3.1.4.jar pi -Dmapreduce.job.queuename=prod 2 2

不指定队列,直接提交程序(报错)

Fair Scheduler

Fair Scheduler 叫做公平调度器,提供了yarn应用程序公平的共享大型集群中资源的一种方式。为所有的应用分配公平的资源。

多个队列之间允许资源共享和抢占,用户之间公平的共享,根据任务动态调整

所有用户可以共享一个名为default的队列,可以提交指定队列

优势:

  • 分层队列,队列可以按层次结构排列划分资源,并可以配置权重以按特定比例共享集群

  • 基于用户或组的队列映射:可以根据提交任务的用户名或组来分配队列。如果任务指定了一个队列,则在该队列中提交任务

  • 资源抢占:根据应用的配置,抢占和分配资源可以是友好的或是强制的。默认不启用资源抢占

  • 保证最小配额

  • 允许资源共享

  • 不限制运行数量

开启设置

yarn-site.xml 添加配置

<!--  指定使用fairScheduler的调度方式  -->
<property>
    <name>yarn.resourcemanager.scheduler.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<!--  指定fair资源分配配置文件路径  -->
<property>
    <name>yarn.scheduler.fair.allocation.file</name>
    <value>/export/server/hadoop-3.1.4/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>

<!-- 设置成true,当任务中未指定队列的时候,将以用户名作为队列名。
     这个配置就实现了根据用户名自动分配队列。  -->
<property>
    <name>yarn.scheduler.fair.user-as-default-queue</name>
    <value>true</value>
</property>

<!-- 是否允许创建未定义的队列。
     如果设置成true,yarn将会自动创建任务中指定的未定义过的队列。
     设置成false之后,任务中指定的未定义的队列将无效,该任务会被分配到default资源池中。
     如果在分配文件中给出了队列放置策略queuePlacementPolicy ,则将忽略此属性。  -->
<property>
    <name>yarn.scheduler.fair.allow-undeclared-pools</name>
    <value>false</value>
</property>

fair-scheduler.xml,每隔10s加载一次,动态加载,官方参考链接

https://hadoop.apache.org/docs/r3.1.4/hadoop-yarn/hadoop-yarn-site/FairScheduler.html#Properties_that_can_be_placed_in_yarn-site.xml

官网参考翻译

<?xml version="1.0"?>
<allocations>
  <queue name="sample_queue">
    <minResources>10000 mb,0vcores</minResources>
    <maxResources>90000 mb,0vcores</maxResources>
    <maxRunningApps>50</maxRunningApps>
    <maxAMShare>0.1</maxAMShare>
    <!-- 权重,对公平的定义,当有空闲资源时,根据权重分配空闲资源 -->
    <weight>2.0</weight>
    <!-- 设置该队列的调度策略 fair支持在队列级别就是调度策略覆盖 -->
    <schedulingPolicy>fair</schedulingPolicy> 
    <queue name="sample_sub_queue">
      <aclSubmitApps>charlie</aclSubmitApps>
      <minResources>5000 mb,0vcores</minResources>
    </queue>
    <queue name="sample_reservable_queue">
      <reservation></reservation>
    </queue>
  </queue>

  <queueMaxAMShareDefault>0.5</queueMaxAMShareDefault>
  <queueMaxResourcesDefault>40000 mb,0vcores</queueMaxResourcesDefault>

  <!-- Queue 'secondary_group_queue' is a parent queue and may have
       user queues under it -->
  <queue name="secondary_group_queue" type="parent">
  <weight>3.0</weight>
  <maxChildResources>4096 mb,4vcores</maxChildResources>
  </queue>

  <user name="sample_user">
    <maxRunningApps>30</maxRunningApps>
  </user>
  <userMaxAppsDefault>5</userMaxAppsDefault>
  <!-- 应用存放队列策略规则,每个规则会被逐个尝试,直到匹配成功 -->
  <!-- 每条规则接受`create`参数,用于表明该规则是否能够创建新队列。
  `create`默认值为true;如果设置为false并且Rule要放置app到一个allocations file没有配置的队列,那么继续应用下一个Rule; -->
  <queuePlacementPolicy>
    <!-- 应用放到它指定的队列中 -->
    <rule name="specified" /> 
    <!-- 以用户所在的Unix组名命名的队列中 -->
    <rule name="primaryGroup" create="false" />
    <!-- 该应用程序将以用户名放在嵌套规则建议的队列下的队列中。 -->
    <rule name="nestedUserQueue">
        <rule name="secondaryGroupExistingQueue" create="false" />
    </rule>
    <!-- 当前面所有规则不满足时,则触发`default`规则,把应用放在sample_queue队列中 -->
    <rule name="default" queue="sample_queue"/>
  </queuePlacementPolicy>
  
  <!-- 
    可以不配置`queuePlacementPolicy`规则,调度器则默认采用如下规则:
    叫做除非队列被准备定义指定,否则就会用户名作为队列名创建队列
      <queuePlacementPolicy>
        <rule name="specified" /> 
        <rule name="user" /> 
      </queuePlacementPolicy>  
  -->
  
</allocations>

案例-多租户隔离

第一步编辑yarn-site.xml

<?xml version="1.0"?>
<!--
  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>

<!-- yarn之前的配置属性不需要修改 -->

<!--  指定使用fairScheduler的调度方式  -->
<property>
    <name>yarn.resourcemanager.scheduler.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<!--  指定fair资源分配配置文件路径  -->
<property>
    <name>yarn.scheduler.fair.allocation.file</name>
    <value>/export/server/hadoop-3.1.4/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>

<!-- 设置成true,当任务中未指定队列的时候,将以用户名作为队列名。
     这个配置就实现了根据用户名自动分配队列。  -->
<property>
    <name>yarn.scheduler.fair.user-as-default-queue</name>
    <value>true</value>
</property>

<!-- 是否允许创建未定义的队列。
     如果设置成true,yarn将会自动创建任务中指定的未定义过的队列。
     设置成false之后,任务中指定的未定义的队列将无效,该任务会被分配到default资源池中。
     如果在分配文件中给出了队列放置策略queuePlacementPolicy ,则将忽略此属性。  -->
<property>
    <name>yarn.scheduler.fair.allow-undeclared-pools</name>
    <value>false</value>
</property>
</configuration>

第二步,配置fair-scheduler

<?xml version="1.0"?>
<allocations>
    <!-- 设置每个用户提交运行应用的最大数量为30 -->
    <userMaxAppsDefault>30</userMaxAppsDefault>

    <!-- 定义队列,所有队列都是root的子队列  -->
    <queue name="root">
        <aclSubmitApps> </aclSubmitApps>
        <aclAdministerApps> </aclAdministerApps>
    
        <queue name="hadoop">
            <minResources>512mb,4vcores</minResources>
            <maxResources>20480mb,20vcores</maxResources>
            <maxRunningApps>100</maxRunningApps>
            <schedulingMode>fair</schedulingMode>
            <weight>2.0</weight>
            <!-- 可以将应用程序提交到队列的用户和/或组的列表。 -->
            <!-- 格式为:用户名 用户组 -->
            <!-- 多个用户时:user1,user2 group1,group2 -->
            <aclSubmitApps>hadoop hadoop</aclSubmitApps>
            <!-- 允许管理任务的用户名和组,格式同上 -->
            <aclAdministerApps>hadoop hadoop</aclAdministerApps>
        </queue>
    
        <queue name="spark">
            <minResources>512mb,4vcores</minResources>
            <maxResources>20480mb,20vcores</maxResources>
            <maxRunningApps>100</maxRunningApps>
            <schedulingMode>fair</schedulingMode>
            <weight>1.0</weight>
            <aclSubmitApps>spark spark</aclSubmitApps>
            <aclAdministerApps>spark spark</aclAdministerApps>
        </queue>
    
        <queue name="develop">
            <minResources>512mb,4vcores</minResources>
            <maxResources>20480mb,20vcores</maxResources>
            <maxRunningApps>100</maxRunningApps>
            <schedulingMode>fifo</schedulingMode>
            <weight>1.5</weight>
            <aclSubmitApps>hadoop,develop,spark</aclSubmitApps>
            <aclAdministerApps>hadoop,develop,spark</aclAdministerApps>
        </queue>
        
        <!--  所有的任务如果不指定任务队列,都提交到default队列里面来 -->
        <queue name="default">
            <minResources>512mb,4vcores</minResources>
            <maxResources>30720mb,30vcores</maxResources>
            <maxRunningApps>100</maxRunningApps>
            <schedulingMode>fair</schedulingMode>
            <weight>1.0</weight>
            <aclSubmitApps>*</aclSubmitApps>
        </queue>
    </queue>
</allocations>

第三步:配置资源同步到其他机器

scp yarn-site.xml fair-scheduler.xml  root@node2:$PWD
scp yarn-site.xml fair-scheduler.xml  root@node3:$PWD

第四步:重启yarn

stop-yarn.sh
start-yarn.sh

查看

验证

准备工作

#创建一个普通用户
useradd hadoop
passwd hadoop
#创建supergroup用户组
groupadd supergroup
#将用户添加到用户组
usermod -a -G supergroup hadoop
#将用户信息同步到hadoop上面
hdfs dfsadmin -refreshUserToGroupsMappings

用hadoop用户提交程序

 cd /export/server/hadoop-3.1.4/share/hadoop/mapreduce
 yarn jar hadoop-mapreduce-examples-3.1.4.jar  pi 2 2

提示:实验完毕之后删除以上设置

  1. YARN核心配置参数

给定了很多默认参数,官方

https://hadoop.apache.org/docs/r3.1.4/hadoop-yarn/hadoop-yarn-common/yarn-default.xml

注意版本

5.1 RM核心参数

调度器类型请求线程数据量

# 设置YARN使用调度器,默认值:(不同版本YARN,值不一样)
yarn.resourcemanager.scheduler.class
#Apache 版本 YARN ,默认值为容量调度器;
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler
#CDH 版本 YARN ,默认值为公平调度器; 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler#ResourceManager
处理调度器请求的线程数量,默认50,如果YARN运行任务Job比较多,可以将值调整大一下。
yarn.resourcemanager.scheduler.client.thread-count

5.2 NM核心参数

yarn.nodemanager.resource.detect-hardware-capabilities
#是否让yarn自己检测硬件进行配置,默认false,如果设置为true,那么就会自动探测NodeManager所在主机的内存和CPU。
yarn.nodemanager.resource.count-logical-processors-as-cores
#是否将虚拟核数当作CPU核数,默认false。
yarn.nodemanager.resource.pcores-vcores-multiplier
#确定如何将physcal核心转换为vcore的乘数。vcore的数量将计算为CPU数量*乘数。
yarn.nodemanager.resource.memory-mb
#NodeManager可以使用内存,默认8192M
yarn.nodemanager.resource.system-reserved-memory-mb
保留给非YARN进程的物理内存量(以MB为单位)。
yarn.nodemanager.resource.cpu-vcores
#NodeManager使用CPU核数,默认8个。
参数:yarn.nodemanager.pmem-check-enabled,是否开启container物理内存检查限制,默认打开;
参数:yarn.nodemanager.vmem-check-enabled,是否开启container虚拟内存检查限制,默认打开;
参数:yarn.nodemanager.vmem-pmem-ratio,虚拟内存物理内存比例,默认2.1;

5.3 Container核心参数

参数一:yarn.scheduler.minimum-allocation-mb  
#可申请容器的最少物理内存量,默认是1024(MB),如果一个任务申请的物理内存量少于该值,则该对应的值改为这个数。
参数二:yarn.scheduler.maximum-allocation-mb
#可申请的最多物理内存量,默认是8192(MB)。高于此值的内存请求将引发InvalidResourceRequestException。
参数三:yarn.scheduler.minimum-allocation-vcores 
#可申请的最小虚拟CPU个数,默认是1,如果一个任务申请的CPU个数少于该数,则该对应的值改为这个数。
参数四:yarn.scheduler.maximum-allocation-vcores 
#单个任务可申请的最多虚拟CPU个数,默认是4。高于此值的请求将引发InvalidResourceRequestException。

6、YARN Resource资源配置

6.1什么叫做资源配置

管理CPU和内存,支持可扩展的资源模型,YARN跟踪所有节点,通过定义可以包含任意可扩展的countable资源(运行时消耗,运行完回收),yarn支持使用“资源配置文件”

6.2 跟资源配置相关的参数

相关的配置参数放在三个文件中yarn-site.xml,resource-type.xml,node-resource.xml,推荐分开放,也可都放在yarn-site.xml中

资源文件配置yarn-site.xml

<property>
    <name>yarn.resource-types</name>
    <value>resource1,resource2</value>
    <description>
        The resources to be used for scheduling. 
Use resource-types.xml to specify details about the individual resource types.
    </description>
</property>

ResourceManager 配置resource-type

<configuration>
    <property>
        <name>yarn.resource-types</name>
        <value>resource1, resource2</value>
    </property>

    <property>
        <name>yarn.resource-types.resource1.units</name>
        <value>G</value>
    </property>
    <property>
        <name>yarn.resource-types.resource2.minimum-allocation</name>
        <value>1</value>
    </property>
    <property>
        <name>yarn.resource-types.resource2.maximum-allocation</name>
        <value>1024</value>
    </property>
</configuration>

NodeManager配置node-resource

<configuration>
    <property>
        <name>yarn.nodemanager.resource-type.resource1</name>
        <value>5G</value>
    </property>
    <property>
        <name>yarn.nodemanager.resource-type.resource2</name>
        <value>2m</value>
    </property>
</configuration>

6.3配置模板 YARN资源模型

mapreduce使用redource mapreduce像yarn申请AM容器,MapTask容器,ReduceTask容器

对每一种容器类型,都够一组对应的属性可用于设置请求的资源

yarn.app.mapreduce.am.resource.memory-mb  
#将应用程序主容器请求的内存设置为以MB为单位的值。默认为1536。 
yarn.app.mapreduce.am.resource.vcores  
#将应用程序 master container 请求的CPU设置为该值。默认为1。
yarn.app.mapreduce.am.resource.<resource>  
#将应用程序 master container 的<resource>请求的数量设置为该值。
mapreduce.map.resource.memory-mb
#将所有 map master container 请求的内存设置为以MB为单位的值。默认为1024。
mapreduce.map.resource.vcores
#将所有映射 map master container 请求的CPU设置为该值。默认为1。
mapreduce.map.resource.<resource>
#将所有 map master container 的<resource>请求的数量设置为该值。
mapreduce.reduce.resource.memory-mb
#将所有educe task container请求的内存设置为以MB为单位的值。默认为1024。
mapreduce.reduce.resource.<resource>
#将所有educe task container 的<resource>请求的数量设置为该值。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天码村

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值