我们为了开发调试方便,编写的代码需要在本地进行调试好之后再到服务器上运行。
运行在本地需要在本地安装hadoop环境。针对hadoop安装本地,需要更换bin路径下的文件为window下的版本,
针对于window下的版本,可以在https://github.com/steveloughran/winutils中下载对应的版本。
然后再你本机配置环境变量。跟java类似。配置一个hadoop_home并且要配置到path下。
需要注意的是,你工程中引用的jar包的版本需要和本地安装的版本一致,否则容易出各种问题。
public class JobSubmitterWindowsLocal {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
//不用刻意指定,jar包中默认就只这个配置
//conf.set("fs.defaultFS", "file:///");
//conf.set("mapreduce.framework.name", "local");
Job job = Job.getInstance(conf);
job.setJarByClass(JobSubmitterLinuxToYarn.class);
job.setMapperClass(WordCountMapper.class);
job.setReducerClass(WordCountReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.setInputPaths(job, new Path("f:/mrdata/wordcount/input"));
FileOutputFormat.setOutputPath(job, new Path("f:/mrdata/wordcount/output"));
job.setNumReduceTasks(3);
boolean res = job.waitForCompletion(true);
System.exit(res?0:1);
}
}