一、常用命令
1.yarn application -list
列出所有Application
2.yarn application -list -appStates 状态(ALL,NEW,NEW_SAVING,SUBMITTED,ACCEPTED,RUNNING,FINISHED,FAILED,KILLED)
根据Application状态过滤
3.yarn application -kill 进程ID
杀死某个进程
4.yarn logs -applicationId 进程id
查看进程日志
5.yarn logs -applicationId 进程id -containerId 容器id
查看容器id
6.yarn applicationattempt -list 进程id
列出所有Application尝试的列表
7.yarn applicationattempt -status 进程id
打印ApplicationAttemp状态
8.yarn container -list 进程id
列出所有Container
9.yarn container -status 容器id
打印Container状态
10.yarn node -list -all
列出所有节点
11.yarn rmadmin -refreshQueues
加载队列配置
12.yarn queue -status 队列名称
打印队列信息
二、队列相关命令
1.配置多队列的容量调度器
(1)在capacity-scheduler.xml中配置如下:
修改配置:
<property >
<name > yarn.scheduler.capacity.root.queues</name >
<value > default,hive</value >
<description >
The queues at the this level (root is the root queue).
</description >
</property >
<property >
<name > yarn.scheduler.capacity.root.default.capacity</name >
<value > 40</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.default.maximum-capacity</name >
<value > 60</value >
</property >
为新加队列添加必要属性:
<property >
<name > yarn.scheduler.capacity.root.hive.capacity</name >
<value > 60</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.user-limit-factor</name >
<value > 1</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.maximum-capacity</name >
<value > 80</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.state</name >
<value > RUNNING</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.acl_submit_applications</name >
<value > *</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.acl_administer_queue</name >
<value > *</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.acl_application_max_priority</name >
<value > *</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.maximum-application-lifetime</name >
<value > -1</value >
</property >
<property >
<name > yarn.scheduler.capacity.root.hive.default-application-lifetime</name >
<value > -1</value >
</property >
(2)分发配置文件
(3)重启Yarn或者执行yarn rmadmin -refreshQueues刷新队列
3.任务优先级
(1)修改yarn-site.xml文件,增加以下参数(其中value值随便自己设):
<property >
<name > yarn.cluster.max-application-priority</name >
<value > 5</value >
</property >
(2)分发配置,并重启yarn
(3)设置任务优先级hadoop jar /opt/module/hadoop-3.2.4/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.4.jar pi -D mapreduce.job.priority=5 5 2000000
(4)修改正在执行的任务的优先级yarn application -appID 进程id -updatePriority 优先级
4.配置多队列的公平调度器
(1)修改yarn-site.xml文件,加入以下参数:
<property >
<name > yarn.resourcemanager.scheduler.class</name >
<value > org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value >
<description > 配置使用公平调度器</description >
</property >
<property >
<name > yarn.scheduler.fair.allocation.file</name >
<value > /opt/module/hadoop-3.2.4/etc/hadoop/fair-scheduler.xml</value >
<description > 指明公平调度器队列分配配置文件</description >
</property >
<property >
<name > yarn.scheduler.fair.preemption</name >
<value > false</value >
<description > 禁止队列间资源抢占</description >
</property >
(2)配置fair-scheduler.xml:
<?xml version="1.0"?>
<allocations >
<queueMaxAMShareDefault > 0.5</queueMaxAMShareDefault >
<queueMaxResourcesDefault > 4096mb,4vcores</queueMaxResourcesDefault >
<queue name ="test" >
<minResources > 2048mb,2vcores</minResources >
<maxResources > 4096mb,4vcores</maxResources >
<maxRunningApps > 4</maxRunningApps >
<maxAMShare > 0.5</maxAMShare >
<weight > 1.0</weight >
<schedulingPolicy > fair</schedulingPolicy >
</queue >
<queue name ="atguigu" >
<minResources > 2048mb,2vcores</minResources >
<maxResources > 4096mb,4vcores</maxResources >
<maxRunningApps > 4</maxRunningApps >
<maxAMShare > 0.5</maxAMShare >
<weight > 1.0</weight >
<schedulingPolicy > fair</schedulingPolicy >
</queue >
<queuePlacementPolicy >
<rule name ="specified" create ="false" />
<rule name ="nestedUserQueue" create ="true" >
<rule name ="primaryGroup" create ="false" />
</rule >
<rule name ="reject" />
</queuePlacementPolicy >
</allocations >
(3)分发配置并重启Yarn
4.测试提交任务
(1)任务指定到root.test队列hadoop jar /opt/module/hadoop-3.2.4/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.4.jar pi -Dmapreduce.job.queuename=root.test 1 1
(2)不指定队列则按照配置规则选队列hadoop jar /opt/module/hadoop-3.2.4/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.4.jar pi 1 1
三、总结
1.Yarn的工作机制(面试题)
2.Yarn的调度器
(1)FIFO/容量/公平
(2)apache默认调度器:容量;CDH默认调度器:公平
(3)公平/容量默认一个default,需要创建多队列
(4)中小企业:hive spark flink mr
(5)中大企业:业务模块:登录/注册/购物车/营销
(6)好处:解耦 降低风险 11.11 6.18 降级使用
(7)每个调度器特点:
相同点:支持多队列,可以借资源,支持多用户
不同点:容量调度器:优先满足先进来的任务先执行
公平调度器:在队列里面的任务公平享有队列资源
(8)生产环境怎么选:
中小企业:对并发度要求不高,选择容量
中大企业:对并发度要求比较高,选择公平
3.并发需要重点掌握:
(1)队列运行原理
(2)Yarn常用命令
(3)核心参数配置
(4)配置容量调度器和公平调度器
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构