eclipse远程连接hadoop进行开发测试

标签: eclipse hadoop 开发 | 发表时间:2015-03-27 18:17 | 作者:duguyiren3476
出处:http://www.iteye.com

eclipse远程连接hadoop进行开发测试

马克飞象 由于搭建hadoop环境在仿真系统,在本地远程连接hdfs和提交mapreduce的job任务精力了曲折,现整理如下:

  • hadoop环境 :hadoop2.5.2 jdk1.7 eclipse_luno hadoop_eclipse插件2.6; 
    wordcount代码如下:
    package test;

import java.io.File;
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.mapred.JobConf;
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;

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 {
    Configuration conf = new Configuration();
    conf.set("df.default.name", "hdfs://10.128.7.140:9000");
    conf.set("hadoop.job.user","hadoop");
//    conf.set("mapred.job.tracker", "10.128.7.140:9001");
    Path in = new Path("hdfs://10.128.7.140:9000/test/test.txt");
    Path out = new Path("hdfs://10.128.7.140:9000/usr/output");
    out.getFileSystem(conf).delete(out, true);

    Job job = new Job(conf, "word——count");

//    
    File jarFile = EJob.createTempJar("bin");
    EJob.addClasspath("/home/hadoop/hadoop-1.2.1/conf");
    ClassLoader classLoader = EJob.getClassLoader();
    Thread.currentThread().setContextClassLoader(classLoader);
    ((JobConf) job.getConfiguration()).setJar(jarFile.toString()); 

    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, in);
    FileOutputFormat.setOutputPath(job,out);

    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}
  • 异常1 :找不到winutils.exe
    2015-03-27 18:01:42,982 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(373)) - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
    at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:355)
    at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:370)
    at org.apache.hadoop.util.Shell.<clinit>(Shell.java:363)
    at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:78)
    at org.apache.hadoop.security.Groups.parseStaticMapping(Groups.java:93)
    at org.apache.hadoop.security.Groups.<init>(Groups.java:77)
    at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:240)
    at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:257)
    at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:234)
    at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:749)
    at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:734)
    at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:607)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2748)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2740)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2606)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:368)
    at org.apache.hadoop.fs.Path.getFileSystem(Path.java:296)
    at test.WordCount.main(WordCount.java:73)
2015-03-27 18:01:43,812 INFO  [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1019)) - session.id is deprecated. Instead, use dfs.metrics.session-id
2015-03-27 18:01:43,812 INFO  [main]

解决:下载winutils.exe文件: 
下载地址: https://github.com/srccodes/hadoop-common-2.2.0-bin 
将bin目录下的文件最好都下载到本地,然后替换本地hadoop安装目录下的bin目录 
然后设置HADOOP_HOME环境变量或者在javamain方法中代码设置:

    System.setProperty("hadoop.home.dir", "D://hadoop");
  • 异常2 :如上,问题消失后又出来如下错误:
    2015-03-27 18:07:38,072 INFO  [main] mapreduce.JobSubmitter (JobSubmitter.java:submitJobInternal(441)) - Cleaning up the staging area file:/tmp/hadoop-Administrator/mapred/staging/Administrator1538933894/.staging/job_local1538933894_0001
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
    at org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Native Method)
    at org.apache.hadoop.io.nativeio.NativeIO$Windows.access(NativeIO.java:570)
    at org.apache.hadoop.fs.FileUtil.canRead(FileUtil.java:977)
    at org.apache.hadoop.util.DiskChecker.checkAccessByFileMethods(DiskChecker.java:173)
    at org.apache.hadoop.util.DiskChecker.checkDirAccess(DiskChecker.java:160)
    at org.apache.hadoop.util.DiskChecker.checkDir(DiskChecker.java:94)
    at org.apache.hadoop.fs.LocalDirAllocator$AllocatorPerContext.confChanged(LocalDirAllocator.java:285)
    at org.apache.hadoop.fs.LocalDirAllocator$AllocatorPerContext.getLocalPathForWrite(LocalDirAllocator.java:344)
    at org.apache.hadoop.fs.LocalDirAllocator.getLocalPathForWrite(LocalDirAllocator.java:150)
    at org.apache.hadoop.fs.LocalDirAllocator.getLocalPathForWrite(LocalDirAllocator.java:131)
    at org.apache.hadoop.fs.LocalDirAllocator.getLocalPathForWrite(LocalDirAllocator.java:115)
    at org.apache.hadoop.mapred.LocalDistributedCacheManager.setup(LocalDistributedCacheManager.java:131)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.<init>(LocalJobRunner.java:163)
    at org.apache.hadoop.mapred.LocalJobRunner.submitJob(LocalJobRunner.java:731)
    at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:432)
    at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1285)
    at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1282)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1614)
    at org.apache.hadoop.mapreduce.Job.submit(Job.java:1282)
    at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1303)
    at test.WordCount.main(WordCount.java:92)

解决办法:将刚下载的bin目录中的hadoop.dll文件放到目录C:\Windows\System32 目录下问题解决

  • eclipse_hadoop2.6的插件可以在附件中下载适用于eclipse luno(4.3)hadoop2.5 2.6


已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐



相关 [eclipse hadoop 开发] 推荐:

Eclipse执行Hadoop WordCount

- - CSDN博客云计算推荐文章
Eclipse执行Hadoop WordCount.   我的Eclipse是安装在windows下的,通过Eclipse执行程序连接Hadoop,需要让虚拟机的访问地址和本机的访问地址保持在同一域内,虚拟机的地址更改前面的文章介绍过了,如果想改windows本机ip地址,打开“网络和共享中心“,点击左侧菜单”更改适配器设置“,选择相应连接网络进行IpV4属性地址修改即可.

基于Eclipse的Hadoop开发环境配置方法

- - CSDN博客推荐文章
(1)启动hadoop守护进程. 在Terminal中输入如下命令:. (2)在Eclipse上安装Hadoop插件. 找到hadoop的安装路径,我的是hadoop-0.20.2,将/home/wenqisun/hadoop-0.20.2/contrib/eclipse-plugin/下的hadoop-0.20.2- eclipse-plugin.jar拷贝到eclipse安装目录下的plugins里,我的是在/home/wenqisun/eclipse /plugins/下.

windows 7 with eclipse 下hadoop应用开发环境搭建

- - CSDN博客云计算推荐文章
最近开始着手高校云平台的搭建,前些天做了hadoop集群测试环境的安装与配置的经验分享, 这篇文章主要介绍win7 64位下 eclipse4.2 连接远程Redhat Linux 5下hadoop-1.2.0集群开发环境搭建. 1、window 7 64位. 三、安装配置hadoop集群. 四、在Eclipse下安装配置hadoop插件.

eclipse远程连接hadoop进行开发测试

- - 开源软件 - ITeye博客
eclipse远程连接hadoop进行开发测试. 马克飞象 由于搭建hadoop环境在仿真系统,在本地远程连接hdfs和提交mapreduce的job任务精力了曲折,现整理如下:. hadoop环境 :hadoop2.5.2 jdk1.7 eclipse_luno hadoop_eclipse插件2.6; .

Hadoop学习笔记之在Eclipse中远程调试Hadoop

- - BlogJava-首页技术区
话说Hadoop 1.0.2/src/contrib/eclipse-plugin只有插件的源代码,这里给出一个我打包好的对应的Eclipse插件:. 下载后扔到eclipse/dropins目录下即可,当然eclipse/plugins也是可以的,前者更为轻便,推荐;重启Eclipse,即可在透视图(Perspective)中看到Map/Reduce.

Eclipse开发Android应用程序入门

- Bingnan - 酷壳 - CoolShell.cn
原文出处:http://www.smashingmagazine.com/2010/10/25/get-started-developing-for-android-with-eclipse/. 如今的移动设备应用程序开发充满着让人振奋的东西. 功能强大的硬件支持,平板电脑,多样的软件平台(塞班 OS,iOS,WebOS,Windows Phone 7…),移动设备开发者前景充满了机会和挑战.

eclipse配置nodejs开发环境

- - CSDN博客云计算推荐文章
首先说明一下本人的开发环境,个人兴趣爱好问题,这边使用的很多环境都是基于Linux系统下做的,这次也不例外. 前提条件:NodeJs已经在系统中正确安装. 1、下载安装eclipse,地址: http://www.eclipse.org/downloads/. Eclipse Standard 版本即可.

开发者应该了解的 12 款 Eclipse 插件

- - ITeye资讯频道
Eclipse成为最流行的集成开发环境,在很大程度上要归功于它跨平台的插件支持系统. 通过将各种类型的插件添加到Eclipse中,可以扩充Eclipse的功能,以满足你的各种需求. 目前有许多款流行的Eclipse插件,其中一些很流行,有一些很时尚,还有一些仅仅是功能新巧,所有的这些功能各异的插件构成了强大的Eclipse,并不断为它的发展添加活力.

用Python+Django在Eclipse环境下开发web网站 - Ruthless

- - 博客园_Ruthless
如果这是你第一次使用Django,那么你必须进行一些初始设置. 也就是通过自动生成代码来建立一个Django项目--一个Django项目的设置集,包含了数据库配置、Django详细选项设置和应用特性配置,具体操作步骤如下所示. 1.新建Django项目. 3.测试新建的模块是否正常. 服务器启动起来后,去浏览器输入网址:http://127.0.0.1:8000,你会看到一个令人愉悦的,柔和的淡蓝色 “Welcome to Django” 页面.

Windows7+Eclipse环境下Hbase Java客户端的开发

- - zzm
Centos 下Hbase0.98.10-hadoop2 集群的配置. 在Eclipse中创建Maven的工程. 将集群的hbase-site.xml文件放到工程的classes目录下. C:\windows\system32\drivers\etc文件,将Hbase集群的IP以及域名配置到该文件中.