Mapreduce提交任务

一、提交任务

public class Driver {
	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		
		conf.set("fs.defaultFS", "hdfs://bigdata01:9000");
		Job job = Job.getInstance(conf);
		
		//设置任务的使用类
		job.setMapperClass(MapTask.class);
		job.setReducerClass(ReduceTask.class);
		job.setJarByClass(Driver.class);
		
		//设置输出类型
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(IntWritable.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		
		//设置reduceTask数量,不是必要选项
		job.setNumReduceTasks(2);
		
		//设置输入和输出目录
		FileInputFormat.addInputPath(job, new Path("/test/qingshu.txt"));
		FileOutputFormat.setOutputPath(job, new Path("/test/qingshuOut2"));
		
		//获得反馈信息
		boolean completion = job.waitForCompletion(true);
		System.out.println(completion?"程序执行完毕,没毛病":"程序出bug了,赶紧修改再来运行");
		
	}
}

二、Mapreduce提交任务的四种方法

注意:一下四种方法都需要配置job

1、打包成jar包,在集群上运行,eg:hadoop jar xxx.jar 类全路径名(包名+类名)

[root@bigdata01 ~]# hadoop jar mr.jar cn.aliyun.mr.Driver

需声明在哪个集群上运行,eg:

conf.set("fs.defaultFS", "hdfs://bigdata01:9000");

2、本地运行。文件系统是本地的,运行也是在本地。
1)conf无需配置
2)设置输入和输出目录时需配置本地路径名,eg:

//设置输入和输出目录
FileInputFormat.addInputPath(job, new Path("E:\\小牛学堂\\杂项\\line.txt"));
FileOutputFormat.setOutputPath(job, new Path("E:\\小牛学堂\\杂项\\lineOut"));

3、半本地运行,文件系统时hadoop集群的,运行是在本地的
1)需声明在哪个集群上运行的
2)权限问题,需声明使用用户进行提交

  System.setProperty("HADOOP_USER_NAME", "root");

4、代码直接提交到集群(eclispe提交到集群)
1)权限问题,需声明使用用户进行提交
2)向yarn集群提交任务,需声明在哪个集群上运行的
3)提交至yarn上

  conf.set(“mapreduce.framework.name","yarn")

4)yarn的的rsoursemanager

  conf.set("yarn.resourcemanager.hostname", "bigdata01");

5)平台转换,从window向linux提交任务

  conf.set("mapreduce.app-submission.cross-platform", "true");

6)通过代码直接往集群上提交时,需设置为jar的位置

  job.setJar("C:\\Users\\root\\Desktop\\wc.jar");
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值