阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境

165次阅读
没有评论

共计 3869 个字符,预计需要花费 10 分钟才能阅读完成。

图文详解 Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境,给需要的朋友参考学习。

Eclipse 的 Hadoop 插件下载地址:https://github.com/winghc/hadoop2x-eclipse-plugin

将下载的压缩包解压,将 hadoop-eclipse-kepler-plugin-2.2.0 这个 jar 包扔到 eclipse 下面的 dropins 目录下,重启 eclipse 即可

进入 windows->Preference 配置根目录

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

,这里面的 hadoop installation directory 并不是你 windows 上装的 hadoop 目录,而仅仅是你在 centos 上编译好的源码,在 windows 上的解压路径而已,该路径仅仅是用于在创建 MapReduce Project 能从这个地方自动引入 MapReduce 所需要的 jar

进入 Window–>Open Perspective–>other–>Map/Reduce 打开 Map/Reduce 窗口

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

找到

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

,右击选择,New Hadoop location,这个时候会出现

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

Map/Reduce(V2) 中的配置对应于 mapred-site.xml 中的端口配置,DFS Master 中的配置对应于 core-site.xml 中的端口配置,配置完成之后 finish 即可,这个时候可以查看

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

测试,新建一个 MapReduce 项目,

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

,要解决这个问题,你必须要完成如下几个步骤,在 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 环境

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

。如我的 jre1.8 是 64 位,jre7 是 32 位,如果这里面没有,你直接 add 即可,选中你的 64 位 jre 环境之后,就会出现了。

之后写个 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();
 }
}

Windows 8.0 上 Eclipse 4.4.0 配置 CentOS 6.5 上的 Hadoop2.2.0 开发环境

Ubuntu 13.04 上搭建 Hadoop 环境 http://www.linuxidc.com/Linux/2013-06/86106.htm

Ubuntu 12.10 +Hadoop 1.2.1 版本集群配置 http://www.linuxidc.com/Linux/2013-09/90600.htm

Ubuntu 上搭建 Hadoop 环境(单机模式 + 伪分布模式)http://www.linuxidc.com/Linux/2013-01/77681.htm

Ubuntu 下 Hadoop 环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm

单机版搭建 Hadoop 环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm

搭建 Hadoop 环境(在 Winodws 环境下用虚拟机虚拟两个 Ubuntu 系统进行搭建)http://www.linuxidc.com/Linux/2011-12/48894.htm

在 Ubuntu 下使用 Eclispe 连接 Hadoop 时拒绝链接解决方案总结 http://www.linuxidc.com/Linux/2014-11/109106.htm

更多 Hadoop 相关信息见 Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计3869字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中