如果我们只是在IDE里面跑Hadoop作业,那么这个作业的运行过程不会显示在Hadoop 管理界面上,但是如果我们把作业上传到服务器上运行,那么作业的运行过程就会显示在管理界面上。
还是以上次的分析最高气温的Map-Reduce为例,源代码可以见http://supercharles888.blog.51cto.com/609344/878422 这篇博客的内容。我们将其打包成jar包,然后上传到/home/hadoop-user/hadoop-0.20.2/charlestest 目录中:

我们在命令行中执行MaxTemperature类中定义的作业:
hadoop jar ParseWeatherFile.jar com.charles.parseweather.MaxTemperature input/1901.txt output-001
这里我们执行的入口为 WeatherFile的 jar包中的MaxTemperature类,最后2个参数分别是输入文件位置和输出目录:
运行结果如图:

现在我们就可以去控制台去看整个过程了:
我们去http://192.168.129.35:50030/jobtracker.jsp 来看map-reduce过程。
在Completed Job部分,我们看到了刚才运行的作业:

对比Job Name刚好是我们在job类中设定的名字,见第43行所示:
- package com.charles.parseweather;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.io.IntWritable;
- import org.apache.hadoop.io.Text;
- import org.apache.hadoop.mapreduce.Job;
- import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
- import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
- import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
- import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
- public class MaxTemperature {
-
-
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
-
-
- if (args.length !=2){
- System.err.println("Usage: MaxTemperature <input path> <output path>");
- System.exit(-1);
- }
-
- //创建一个Map-Reduce的作业
- Configuration conf = new Configuration();
- conf.set("hadoop.job.ugi", "hadoop-user,hadoop-user");
-
- Job job = new Job(conf,"Get Maximum Weather Information! ^_^");
-
- //设定作业的启动类/
- job.setJarByClass(MaxTemperature.class);
-
- //解析输入和输出参数,分别作为作业的输入和输出,都是文件
- FileInputFormat.addInputPath(job, new Path(args[0]));
- FileOutputFormat.setOutputPath(job, new Path(args[1]));
-
- //配置作业,设定Mapper类,Reducer类
- job.setMapperClass(MaxTemperatureMapper.class);
- job.setReducerClass(MaxTemperatureReducer.class);
- job.setOutputKeyClass(Text.class);
- job.setOutputValueClass(IntWritable.class);
-
- System.exit(job.waitForCompletion(true)?0:1);
-
-
-
-
-
-
- }
-
- }
;
我们点进去,则可以看到Map-Reduce的更多细节:
