草庐IT

Hadoop之Yarn篇

小唐同学(๑>؂<๑) 2023-12-26 原文

目录

​编辑

Yarn的工作机制: 

全流程作业:

Yarn的调度器与调度算法:

FIFO调度器(先进先出):

容量调度器(Capacity Scheduler):

容量调度器资源分配算法:

​编辑

 公平调度器(Fair Scheduler):

 Yarn的常用命令:

 yarn application查看任务

(1)列出所有Application:

(2)根据Application状态过滤:

(3)Kill掉Application:

yarn logs查看日志:

(1)查询Application日志:

(2)查询Container日志:

yarn applicationattempt查看尝试运行的任务

yarn container查看容器

(1)列出所有Container:

(2)打印Container状态:

***注:只有在任务跑的途中才能看到container的状态

yarn node查看节点状态:

列出所有节点:

yarn rmadmin更新配置

加载队列配置:

yarn queue查看队列:

打印队列信息:

 Yarn生产环境核心参数:

环境配置代码:

2.2.4 任务优先级

公平调度器案例


Yarn的工作机制: 

(其实主要为YARN与MapReduce的交互)

(0):   在linux中运行打包的Java程序  (wc.jar)程序的入口是main方法 

在程序的最后一行        job.waitForCompletion()会创建YarnRunner(本地创建---)

(1):   YarnRunner向集群(ResourceManger)申请Application(后边详讲作用)=

(2):   Application资源提交路径

(3):   提交job运行所需要的资源(Job.spilt   Job.xml   wc.jar  )(按照(2)中提供的路径进行上传)

(4)    资源提交完毕后,申请运行mrAppMaster (程序运行的老大)

(5)    将用户的请求初始化成一个Task (让后放入任务队列中---FIFO调度队列)

(6)    NodeManger领取Task任务

(7)    NodeManger创建容器,任何任务的执行都是在容器中执行的(容器中有cpu+ram--网络资               源),并且在容器中启动了一个MRAppmaster

(8)    MRAppmaster下载job资源到本地

(9)    MRAppmaster根据job资源(切片)申请运行MapTask容器

(10)  领取任务,创建MapTask容器(NodeManager)(cpu+ram+jar)

(11)  MRAppmaster 发送程序,启动脚本(MapTask)

(12)  MapTask运行结束后MRAppmaster得到信息,向RM申请两个容器,运行Reduce Task程序

 (13)  Reduce向Map获取相应分区的数据

(14)  程序结束后,MR会向RM注销自己(释放资源)

全流程作业:

主要了解HDFS,YARN,MapReduce三者之间的关系

Yarn的调度器与调度算法:

多个客户端向集群提交任务,任务多了集群会把任务放入到任务队列中进行管理。

Hadoop作业调度器主要有三种:FIFO、容量(Capacity Scheduler)和公平(Fair Scheduler)。Apache Hadoop3.1.3默认的资源调度器是Capacity Scheduler

CDH框架默认调度器是Fair Scheduler。

FIFO调度器(先进先出):

FIFO调度器(First In First Out):单队列,根据提交作业的先后顺序,进行先来先服务。

优点:简单易懂;

缺点:不支持多队列,生产环境很少使用;(在大数据中,体现大容量,高并发,不能满足)

容量调度器(Capacity Scheduler):

Capacity Scheduler是Yahoo开发的多用户调度器。(多个用户可以提交任务)

容量调度器资源分配算法:

 公平调度器(Fair Scheduler):

Fair Schedulere是Facebook开发的 多用户调度器。

     

缺额问题:

        

 

  

 

 Yarn的常用命令:

 yarn application查看任务

(1)列出所有Application:

yarn application -list    是查看mapreduce运行过程的状态

在测试中经常用下述命令,简单解释一下:

hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar wordcount /input /output
  • hadoop: Hadoop框架的命令行工具
  • jar: 运行MapReduce任务所需的Java可执行jar包
  • share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar: Hadoop自带的MapReduce示例程序的jar包,其中包括了一些常用的MapReduce任务的示例代码
  • wordcount: 示例程序中的一个任务,表示统计给定文本中每个单词出现的次数(

    wordcount是一个由Apache Hadoop社区提供的系统自带的示例MapReduce程序,用于统计给定文本中每个单词出现的次数。在Hadoop安装包中的hadoop-mapreduce-examples-*.jar文件中包含了wordcount等多个示例程序的源代码和二进制文件。

    使用wordcount示例程序可以帮助开发人员了解MapReduce编程的基本概念和实现方式,同时也可以作为一个基础模板,为开发定制化的MapReduce任务提供参考。因此,在学习和使用Hadoop MapReduce时,wordcount通常是第一个学习的示例程序之一。

  • /input: 待处理的输入文件或文件夹路径,输入文件可以是本地文件系统上的文件,也可以是HDFS上的文件
  • /output: 处理结果输出路径,输出结果将会写入HDFS上的这个路径中,如果该路径不存在,则会自动创建

因此,运行这个命令会在Hadoop集群上启动一个名为wordcount的MapReduce任务,统计/input路径下的文本中每个单词出现的次数,并将结果输出到/output路径中。

(2)根据Application状态过滤:

yarn application -list -appStates (所有状态:ALL、NEW、NEW_SAVING、SUBMITTED、ACCEPTED、RUNNING、FINISHED、FAILED、KILLED)

 yarn application -list -appStates FINISHED      是查看已经结束的任务

(3)Kill掉Application:

yarn application -kill   任务ID

在某个任务比较消耗时间的时候 需要杀死 启用此命令

yarn logs查看日志:

(1)查询Application日志:

yarn logs -applicationId <任务ID--应用程序>

(2)查询Container日志:

yarn logs -applicationId <ApplicationId> -containerId(容器) <ContainerId>

yarn applicationattempt查看尝试运行的任务

即查看正在运行的状态

yarn applicationattempt -list   任务ID

yarn container查看容器

(1)列出所有Container:

yarn container -list <ApplicationAttemptId>

(2)打印Container状态:

yarn container -status <ContainerId>

***注:只有在任务跑的途中才能看到container的状态

yarn node查看节点状态:

列出所有节点:

yarn node -list -all

yarn rmadmin更新配置

加载队列配置:

yarn rmadmin -refreshQueues

yarn queue查看队列:

打印队列信息:

yarn queue -status <QueueName>

(都有 default队列)

 Yarn生产环境核心参数:

环境配置代码:

将代码添加到yarn-site.xml文件下

让后进行分发

重置后要重启集群才能发挥作用

<!-- 选择调度器,默认容量 -->
<property>
	<description>The class to use as the resource scheduler.</description>
	<name>yarn.resourcemanager.scheduler.class</name>
	<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
</property>

<!-- ResourceManager处理调度器请求的线程数量,默认50;如果提交的任务数大于50,可以增加该值,但是不能超过3台 * 4线程 = 12线程(去除其他应用程序实际不能超过8) -->
<property>
	<description>Number of threads to handle scheduler interface.</description>
	<name>yarn.resourcemanager.scheduler.client.thread-count</name>
	<value>8</value>
</property>

<!-- 是否让yarn自动检测硬件进行配置,默认是false,如果该节点有很多其他应用程序,建议手动配置。如果该节点没有其他应用程序,可以采用自动 -->
<property>
	<description>Enable auto-detection of node capabilities such as
	memory and CPU.
	</description>
	<name>yarn.nodemanager.resource.detect-hardware-capabilities</name>
	<value>false</value>
</property>

<!-- 是否将虚拟核数当作CPU核数,默认是false,采用物理CPU核数 -->
<property>
	<description>Flag to determine if logical processors(such as
	hyperthreads) should be counted as cores. Only applicable on Linux
	when yarn.nodemanager.resource.cpu-vcores is set to -1 and
	yarn.nodemanager.resource.detect-hardware-capabilities is true.
	</description>
	<name>yarn.nodemanager.resource.count-logical-processors-as-cores</name>
	<value>false</value>
</property>

<!-- 虚拟核数和物理核数乘数,默认是1.0 -->
<property>
	<description>Multiplier to determine how to convert phyiscal cores to
	vcores. This value is used if yarn.nodemanager.resource.cpu-vcores
	is set to -1(which implies auto-calculate vcores) and
	yarn.nodemanager.resource.detect-hardware-capabilities is set to true. The	number of vcores will be calculated as	number of CPUs * multiplier.
	</description>
	<name>yarn.nodemanager.resource.pcores-vcores-multiplier</name>
	<value>1.0</value>
</property>

<!-- NodeManager使用内存数,默认8G,修改为4G内存 -->
<property>
	<description>Amount of physical memory, in MB, that can be allocated 
	for containers. If set to -1 and
	yarn.nodemanager.resource.detect-hardware-capabilities is true, it is
	automatically calculated(in case of Windows and Linux).
	In other cases, the default is 8192MB.
	</description>
	<name>yarn.nodemanager.resource.memory-mb</name>
	<value>4096</value>
</property>

<!-- nodemanager的CPU核数,不按照硬件环境自动设定时默认是8个,修改为4个 -->
<property>
	<description>Number of vcores that can be allocated
	for containers. This is used by the RM scheduler when allocating
	resources for containers. This is not used to limit the number of
	CPUs used by YARN containers. If it is set to -1 and
	yarn.nodemanager.resource.detect-hardware-capabilities is true, it is
	automatically determined from the hardware in case of Windows and Linux.
	In other cases, number of vcores is 8 by default.</description>
	<name>yarn.nodemanager.resource.cpu-vcores</name>
	<value>4</value>
</property>

<!-- 容器最小内存,默认1G -->
<property>
	<description>The minimum allocation for every container request at the RM	in MBs. Memory requests lower than this will be set to the value of this	property. Additionally, a node manager that is configured to have less memory	than this value will be shut down by the resource manager.
	</description>
	<name>yarn.scheduler.minimum-allocation-mb</name>
	<value>1024</value>
</property>

<!-- 容器最大内存,默认8G,修改为2G -->
<property>
	<description>The maximum allocation for every container request at the RM	in MBs. Memory requests higher than this will throw an	InvalidResourceRequestException.
	</description>
	<name>yarn.scheduler.maximum-allocation-mb</name>
	<value>2048</value>
</property>

<!-- 容器最小CPU核数,默认1个 -->
<property>
	<description>The minimum allocation for every container request at the RM	in terms of virtual CPU cores. Requests lower than this will be set to the	value of this property. Additionally, a node manager that is configured to	have fewer virtual cores than this value will be shut down by the resource	manager.
	</description>
	<name>yarn.scheduler.minimum-allocation-vcores</name>
	<value>1</value>
</property>

<!-- 容器最大CPU核数,默认4个,修改为2个 -->
<property>
	<description>The maximum allocation for every container request at the RM	in terms of virtual CPU cores. Requests higher than this will throw an
	InvalidResourceRequestException.</description>
	<name>yarn.scheduler.maximum-allocation-vcores</name>
	<value>2</value>
</property>

<!-- 虚拟内存检查,默认打开,修改为关闭 -->
<property>
	<description>Whether virtual memory limits will be enforced for
	containers.</description>
	<name>yarn.nodemanager.vmem-check-enabled</name>
	<value>false</value>
</property>

<!-- 虚拟内存和物理内存设置比例,默认2.1 -->
<property>
	<description>Ratio between virtual memory to physical memory when	setting memory limits for containers. Container allocations are	expressed in terms of physical memory, and virtual memory usage	is allowed to exceed this allocation by this ratio.
	</description>
	<name>yarn.nodemanager.vmem-pmem-ratio</name>
	<value>2.1</value>
</property>

2.2.4 任务优先级

容量调度器,支持任务优先级的配置,在资源紧张时,优先级高的任务将优先获取资源。默认情况,Yarn将所有任务的优先级限制为0,若想使用任务的优先级功能,须开放该限制。

  1. 修改yarn-site.xml文件,增加以下参数

<property>

    <name>yarn.cluster.max-application-priority</name>

    <value>5</value>

</property>

让后分发配置,重启yarn

公平调度器案例

公平调度器常用于中大厂,也默认有defaule队列

创建两个队列,分别是test和atguigu(以用户所属组命名)。期望实现以下效果:若用户提交任务时指定队列,则任务提交到指定队列运行若未指定队列,test用户提交的任务到root.group.test队列运行,atguigu提交的任务到root.group.atguigu队列运行(注:group为用户所属组)。

公平调度器的配置涉及到两个文件,一个是yarn-site.xml,另一个是公平调度器队列分配文件fair-scheduler.xml(文件名可自定义)。

有关Hadoop之Yarn篇的更多相关文章

  1. hadoop安装之保姆级教程(二)之YARN的配置 - 2

    1.1.1 YARN的介绍 为克服Hadoop1.0中HDFS和MapReduce存在的各种问题⽽提出的,针对Hadoop1.0中的MapReduce在扩展性和多框架⽀持⽅⾯的不⾜,提出了全新的资源管理框架YARN. ApacheYARN(YetanotherResourceNegotiator的缩写)是Hadoop集群的资源管理系统,负责为计算程序提供服务器计算资源,相当于⼀个分布式的操作系统平台,⽽MapReduce等计算程序则相当于运⾏于操作系统之上的应⽤程序。 YARN被引⼊Hadoop2,最初是为了改善MapReduce的实现,但是因为具有⾜够的通⽤性,同样可以⽀持其他的分布式计算模

  2. 大数据之Hadoop数据仓库Hive - 2

    目录:一、简介二、HQL的执行流程三、索引四、索引案例五、Hive常用DDL操作六、Hive常用DML操作七、查询结果插入到表八、更新和删除操作九、查询结果写出到文件系统十、HiveCLI和Beeline命令行的基本使用十一、Hive配置一、简介Hive是一个构建在Hadoop之上的数据仓库,它可以将结构化的数据文件映射成表,并提供类SQL查询功能,用于查询的SQL语句会被转化为MapReduce作业,然后提交到Hadoop上运行。特点:简单、容易上手(提供了类似sql的查询语言hql),使得精通sql但是不了解Java编程的人也能很好地进行大数据分析;灵活性高,可以自定义用户函数(UDF)和

  3. Ubuntu下Hadoop的单机安装 - 2

            云计算实验中要求我们在Linux系统安装Hadoop,故来做一个简单的记录。· 注:我的操作系统环境是Ubuntu-20.04.3,安装的JDK版本为jdk1.8.0_301,安装的Hadoop版本为hadoop2.7.1。(不确定其他版本是否会出现版本兼容问题)Hadoop安装步骤如下:        一、更新apt和安装vim编辑器        二、配置本机无密码登录SSH        三、安装JAVA环境        四、下载安装Hadoop        五、伪分布式搭建一、更新apt和安装vim编辑器1、更新aptsudoapt-getupdate2、安装vim

  4. flink on yarn - 2

    文章目录使用flinksqlclientonyarnsession模式Per-JobCluster模式flinkrunflinkrunapplication-tyarn-application配置任务退出时保留Checkpoint从外部checkpoint恢复应用资料使用安装完hadoop3.3.4之后,启动hadoop、yarn将flink1.14.6上传到各个服务器节点,解压flinksqlclientonyarnhttps://nightlies.apache.org/flink/flink-docs-release-1.15/docs/deployment/overview/Appli

  5. ruby - yarn 未初始化常量 Socket::SOL_TCP - 2

    我在这里尝试使用yarn,遇到了一个可能与ruby​​相关的问题。在执行任何yarn命令,我收到错误.../.rvm/gems/ruby-2.3.0/gems/yarn-0.1.1/lib/yarn/server.rb:14:in':uninitializedconstantSocket::SOL_TCP(NameError)错误堆栈:$yarn.../.rvm/gems/ruby-2.3.0/gems/yarn-0.1.1/lib/yarn/server.rb:14:in':uninitializedconstantSocket::SOL_TCP(NameError)Didyoume

  6. MAC系统安装Hadoop - 2

    一、设置免密登录1、系统偏好设置-----共享----勾选远程登录,所有用户2、打开终端,输入命令ssh-keygen-trsa,一直回车即可2.查看生成的公钥和私钥    cd~/.ssh    ls会看到~/.ssh目录下有两个文件:①私钥:id_rsa②公钥:id_rsa.pub3.将公钥内容写入到~/.ssh/authorized_keys中    cat~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys4.测试在terminal终端输入 sshlocalhost如果出现以下询问输入yes,不需要输入密码就能登录,说明配置成功Areyousureyouw

  7. javascript - 用于在 React Native metro bundler 中使用动态 yarn 工作空间路径将节点模块列入黑名单的正则表达式 - 2

    类似于:Howtoblacklistspecificnode_modulesofmypackage'sdependenciesinreact-native'spackager?我正在尝试使用需要返回正则表达式的黑名单选项从metropackager中排除reactnative。我需要的是返回如下内容:/\/DYNAMIC_PROJECT_DIRECTORY\/node_modules\/react-native\/.*/,我可以在DYNAMIC_PROJECT_DIRECTORY中插入一个变量,因为它会根据其他模块的yarn工作区路径而改变。我只是不熟悉正则表达式!谢谢编辑:我尝试在路

  8. javascript - 在 docker 容器中安装 yarn 说缺少依赖 - 2

    我正在使用node:6.7.0图像作为我的docker容器,然后按照yarn的安装指南进行操作sudoapt-keyadv--keyserverpgp.mit.edu--recvD101F7899D41F3C3echo"debhttp://dl.yarnpkg.com/debian/stablemain"|sudotee/etc/apt/sources.list.d/yarn.list然后我做apt-getupdate&&apt-getinstallyarn但此时我收到一条错误消息,上面写着yarn:Depends:nodejs(>=4.0.0)butitisnotgoingtobei

  9. javascript - yarn 无法使用 node 12.1.0 构建 node-sass - 2

    我正在尝试使用yarninstall安装我的包我安装了node12.1.0,据我所知,node-sass需要至少版本4.12+才能工作Node12我的package.json文件是这样的:{"name":"redacted","private":true,"dependencies":{"@rails/webpacker":"3.5","babel-preset-react":"^6.24.1","bootstrap":"^4.1.2","font-awesome":"^4.7.0","js-md5":"^0.7.3","moment":"^2.22.2","prop-types":"

  10. javascript - 如何在 ubuntu 中安装特定的 yarn 版本 - 2

    如何在ubuntu中安装yarn版本0.27.5?因为最新更新的yarn版本是1.2.1。 最佳答案 您可以通过查看https://github.com/yarnpkg/yarn/releases来选择任何版本的yarn并滚动和分页到您需要的版本。对于yarn0.27.5,转到https://github.com/yarnpkg/yarn/releases/tag/v0.27.5你可以看到yarn0.27.5的所有包。下载yarn_0.27.5_all.deb(Ubuntu是基于Debian的Linux)然后您可以使用dpkg安装它

随机推荐