windows 8.0上eclipse 4.4.0 配置centos 6.5 上的hadoop2.2.0开发环境

  1. eclipse的hadoop插件下载地址:https://github.com/winghc/hadoop2x-eclipse-plugin
  2. 将下载的压缩包解压,将hadoop-eclipse-kepler-plugin-2.2.0这个jar包扔到eclipse以下的dropins文件夹下。重新启动eclipse就可以
  3. 进入windows->Preference配置根文件夹,这里面的hadoop installation directory并非你windows上装的hadoop文件夹,而不过你在centos上编译好的源代码,在windows上的解压路径而已,该路径不过用于在创建MapReduce Project能从这个地方自己主动引入MapReduce所须要的jar
  4. 进入Window-->Open Perspective-->other-->Map/Reduce打开Map/Reduce窗体
  5. 找到,右击选择。New Hadoop location。这个时候会出现Map/Reduce(V2)中的配置相应于mapred-site.xml中的port配置,DFS Master中的配置相应于core-site.xml中的port配置,配置完毕之后finish就可以,这个时候能够查看
  6. 測试,新建一个MapReduce项目。,要解决问题,你必需要完毕例如以下几个步骤,在windows上配置HADOOP_HOME。然后将%HADOOP_HOME%\bin增加到path之中。然后去https://github.com/srccodes/hadoop-common-2.2.0-bin下载一个,下载之后将这个bin文件夹里面的东西所有复制到你自己windows上的HADOOP的bin文件夹下,覆盖就可以,同一时候把hadoop.dll加到C盘下的system32中,假设这些都完毕之后还是碰到:Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z,那么就检查一下你的JDK,有可能是32位的JDK导致的。须要下载64位安装JDK。而且在eclipse将jre环境配置为你新安装的64位JRE环境如我的jre1.8是64位。jre7是32位。假设这里面没有,你直接add就可以。选中你的64位jre环境之后,就会出现了。
  7. 之后写个wordcount程序測试一下。贴出我的代码例如以下,前提是你已经在hdfs上建好了input文件,而且在里面放些内容
    import java.io.IOException;
    import java.util.StringTokenizer;
    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.Mapper;
    import org.apache.hadoop.mapreduce.Reducer;
    import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
    import org.apache.hadoop.util.GenericOptionsParser;
    public class WordCount {
     public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
      private final static IntWritable one = new IntWritable(1);
      private Text word = new Text();
      public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
       StringTokenizer itr = new StringTokenizer(value.toString());
       while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
       }
      }
     }
     public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
      private IntWritable result = new IntWritable();
      public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
       int sum = 0;
       for (IntWritable val : values) {
        sum += val.get();
       }
       result.set(sum);
       context.write(key, result);
      }
     }
     public static void main(String[] args) throws Exception {
    //	System.setProperty("hadoop.home.dir", "E:\\hadoop2.2\\");
      Configuration conf = new Configuration();
      String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
      // if (otherArgs.length != 2) {
      // System.err.println("Usage: wordcount <in> <out>");
      // System.exit(2);
      // }
      Job job = new Job(conf, "word count");
      job.setJarByClass(WordCount.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("hdfs://master:9000/input"));
      FileOutputFormat.setOutputPath(job, new Path("hdfs://master:9000/output"));
      boolean flag = job.waitForCompletion(true);
      System.out.print("SUCCEED!" + flag);
      System.exit(flag ? 0 : 1);
      System.out.println();
     }
    }


    至此,程序最终执行成功,刷新一下你的DFS就可以,看到输出结果
posted @ 2016-03-10 09:20  mengfanrong  阅读(252)  评论(0编辑  收藏  举报