YARN主要由ResourceManager、NodeManager、ApplicationMaster和Container等组件构成。
目前,Hadoop作业调度器主要有三种:FIFO、Capacity Scheduler和Fair Scheduler。Hadoop3.1.3默认的资源调度器是Capacity Scheduler。yarn-default.xml
The class to use as the resource scheduler. yarn.resourcemanager.scheduler.class org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler
Hadoop集群典型的应用:
- 批处理作业(I/O密集型):这种作业往往耗时较长,对时间完成一般没有严格要求,如数据挖掘、机器学习等方面的应用程序。
- 交互式作业:这种作业期望能及时返回结果,如SQL查询(Hive)等。
- 生产性作业(CPU密集型):这种作业要求有一定量的资源保证,如统计值计算、垃圾数据分析等。
Hadoop作业调度器:
- 先进先出调度器(FIFO):将所有的 Application 按照提交时候的顺序来执行,只有当上一个 Job 执行完成之后后面的 Job 才会按照队列的顺序依次被执行。
- 容量调度器(Capacity Scheduler):1)可有多队列,可设置每个队列的资源占比;2)队列有最低资源保证和使用上限;3)用户可设定资源使用上限;4)队列A空闲资源可以共享给其他队列B,当队列A有新的应用程序提交,队列B归还队列A的资源;5)队列中的任务共享队列资源;6)支持多用户共享集群和多应用同时运行;7)动态更新配置文件;8)使用Hadoop ACL 控制队列訪问权限
- 公平调度器(Fair Scheduler):1)可有多队列,可设置每个队列的资源占比;2)对一个队列的作业按照优先级分享整个队列的资源,并发执行;3)可设置每个作业最小资源值,调度器保证作业获得设定资源;4)时间尺度上,所有作业公平获得资源,调度器优先为缺额(作业应获得资源和实际获取资源的缺额)大的作业分配资源;5)max-min fairness 最大最小公平算法
apacity-scheduler.xml中为YARN配置多条队列(默认只有default队列)
所有集群都配置(hadoop102、hadoop103、hadoop104)
yarn.scheduler.capacity.root.queues default,hive The queues at the this level (root is the root queue). yarn.scheduler.capacity.root.default.capacity 40 yarn.scheduler.capacity.root.default.maximum-capacity 60 yarn.scheduler.capacity.root.hive.capacity 60 yarn.scheduler.capacity.root.hive.user-limit-factor 1 yarn.scheduler.capacity.root.hive.maximum-capacity 80 yarn.scheduler.capacity.root.hive.state RUNNING yarn.scheduler.capacity.root.hive.acl_submit_applications * yarn.scheduler.capacity.root.hive.acl_administer_queue * yarn.scheduler.capacity.root.hive.acl_application_max_priority * yarn.scheduler.capacity.root.hive.maximum-application-lifetime -1 yarn.scheduler.capacity.root.hive.default-application-lifetime -1
// 声明配置对象
Configuration conf = new Configuration();
// 指定当前job提交的队列的名称
conf.set("mapreduce.job.queuename","hive");
// 以命令行的反射设置参数
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
打包程序上传到HDFS,执行如下命令
[atguigu@hadoop102 program]$ hadoop jar Demo02-1.0-SNAPSHOT.jar com.atguigu.mr.wordcount.WordCountDriver /input /output1



