用Hadoop管理界面来分析Map-Reduce作业

 如果我们只是在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行所示:

  
  
  
  
  1. package com.charles.parseweather; 
  2.  
  3.  
  4. import org.apache.hadoop.conf.Configuration; 
  5. import org.apache.hadoop.fs.Path; 
  6. import org.apache.hadoop.io.IntWritable; 
  7. import org.apache.hadoop.io.Text; 
  8. import org.apache.hadoop.mapreduce.Job; 
  9. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
  10. import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; 
  11. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 
  12. import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; 
  13.  
  14.  
  15. /** 
  16.  *  
  17.  * 
  18.  * Description: 这个类定义并且运行作业 
  19.  * 
  20.  * @author charles.wang 
  21.  * @created May 24, 2012 5:29:12 PM 
  22.  * 
  23.  */ 
  24.  
  25. public class MaxTemperature { 
  26.  
  27.     /** 
  28.      * @param args 
  29.      */ 
  30.     public static void main(String[] args) throws Exception{ 
  31.         // TODO Auto-generated method stub 
  32.  
  33.          
  34.         if (args.length !=2){ 
  35.             System.err.println("Usage: MaxTemperature <input path> <output path>"); 
  36.             System.exit(-1); 
  37.         } 
  38.          
  39.         //创建一个Map-Reduce的作业 
  40.         Configuration conf = new Configuration(); 
  41.         conf.set("hadoop.job.ugi""hadoop-user,hadoop-user"); 
  42.          
  43.         Job job = new Job(conf,"Get Maximum Weather Information! ^_^"); 
  44.          
  45.         //设定作业的启动类/  
  46.         job.setJarByClass(MaxTemperature.class); 
  47.          
  48.         //解析输入和输出参数,分别作为作业的输入和输出,都是文件 
  49.         FileInputFormat.addInputPath(job, new Path(args[0])); 
  50.         FileOutputFormat.setOutputPath(job, new Path(args[1])); 
  51.         
  52.         //配置作业,设定Mapper类,Reducer类 
  53.         job.setMapperClass(MaxTemperatureMapper.class); 
  54.         job.setReducerClass(MaxTemperatureReducer.class); 
  55.         job.setOutputKeyClass(Text.class); 
  56.        job.setOutputValueClass(IntWritable.class); 
  57.          
  58.         System.exit(job.waitForCompletion(true)?0:1); 
  59.         
  60.          
  61.          
  62.          
  63.          
  64.  
  65.     } 
  66.  

 

我们点进去,则可以看到Map-Reduce的更多细节:

 

你可能感兴趣的:(hadoop,管理界面)