styxmx 发表于 2018-10-31 13:00:33

编译hadoop-eclipse插件并测试

  由于开发人员使用不同的eclipse版本,hadoop自0.20.x版本后不再提供现成的hadoop-eclipse插件而是给出了源码自行编译。
  一、环境和所需软件
  1、ubuntu 12.04
  2、eclipse-4.2
  3、ant-1.8.4
  4、hadoop-1.1.1
  5、由于需要对hadoop native库进行编译,需要安装automake autoconf libtool
  sudo apt-get install automake autoconf libtool
  二、编译hadoop-eclipse-plugin-1.1.2.jar插件
  (一)、building hadoop
  1、编辑{HADOOP_HOME}/build.xml
  (1)、对31行的hadoop版本做修改
  
  修改为:
  
  (2)、对2418行的ivy下载进行注释,因为已经包含了ivy.jar
  
  (3)、对2426行去除对ivy-download的依赖关系,保留如下:
  Preferens,你会发现HadoopMap/Reduce选项,在这个选项里你需要配置Hadoop installation directory。配置完成后退出。
http://blog.csdn.net/hunauchenym/article/details/8566414
  2、选择window -> open perspective -> Other...,选择有大象图标的 Map/Reduce.
http://blog.csdn.net/hunauchenym/article/details/8566414
  此时,就打开了Map/Reduce的开发环境。可以看到,右下角多了一个Map/Reduce Locations的框。如下图:
http://blog.csdn.net/hunauchenym/article/details/8566414
  3、设置Hadoop的环境参数。选择Map/ReduceLocations标签,点击该标签最右边的大象图标,即那个齿轮状图标右侧的大象图标,打开参数设置页面,参数填写如下图:
http://blog.csdn.net/hunauchenym/article/details/8566414
  LocationName :此处为参数设置名称,可以任意填写
  Map/ReduceMaster (此处为Hadoop集群的Map/Reduce地址,应该和mapred-site.xml中的mapred.job.tracker设置相同)
  Host: 10.0.0.211
  port: 9001
  DFSMaster(此处为Hadoop的master服务器地址,应该和core-site.xml中的fs.default.name 设置相同)
  Host: 10.0.0.211
  Port: 9000
  设置完成后,点击Finish就应用了该设置。
  此时,在最左边的ProjectExplorer中就能看到DFS的目录,如下图所示。
http://blog.csdn.net/hunauchenym/article/details/8566414
  注:解决linux上运行权限的问题,可以在服务器创建一个和hadoop集群用户名一致的用户,即可不用修改master的permissions策略。
  四、测试
  1、新建项目:File-->New-->Other-->Map/Reduce Project ,项目名可以随便取,如HadoopTest
  2、将测试代码 src.zip解压到HadoopTest源码目录的src目录下,刷新项目源码目录结构如下:
http://blog.csdn.net/hunauchenym/article/details/8566414
  3、修改WordCountTest.java
  public static void main(String[] args) throws Exception {
  // Add these statements. XXX
  File jarFile = EJob.createTempJar("bin");
  EJob.addClasspath("/opt/hadoop-1.1.1/conf");

  ClassLoader>  Thread.currentThread().setContextClassLoader(classLoader);
  String inputPath = "hdfs://localhost:9000/user/chenym/input/file*";
  String outputPath = "hdfs://localhost:9000/user/chenym/output2";
  Configuration conf = new Configuration();
  String[] otherArgs = new String[] { inputPath, outputPath };
  if (otherArgs.length != 2) {
  System.err.println("Usage: wordcount");
  System.exit(2);
  }
  Job job = new Job(conf, "word count");
  // And add this statement. XXX
  ((JobConf) job.getConfiguration()).setJar(jarFile.toString());
  job.setJarByClass(WordCountTest.class);
  job.setMapperClass(TokenizerMapper.class);
  job.setCombinerClass(IntSumReducer.class);
  job.setReducerClass(IntSumReducer.class);
  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(IntWritable.class);
  FileInputFormat.addInputPath(job, new Path(otherArgs));
  FileOutputFormat.setOutputPath(job, new Path(otherArgs));
  System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
4、run as mapreduece project  转自http://blog.csdn.net/hunauchenym/article/details/8566414

页: [1]
查看完整版本: 编译hadoop-eclipse插件并测试