如何在Eclipse中开发Hadoop程序

前面的文章介绍了如果在linux环境下搭建真分布式环境,这篇文章主要讲如何在windows下面开发hadoop程序,就是在eclipse中直接使用linux中搭建好的hdfs,其实现在已经有一个比较好的eclipse插件给我们解决了很多麻烦事:

准备:

把你linux下的hadoop安装包下载到windows : hadoop-2.7.1.tar.gz

把对应安装包的源代码也下载到windows :hadoop-2.7.1-src.tar.gz

1. 下载https://github.com/winghc/hadoop2x-eclipse-plugin/tree/master/release    本人使用的是hadoop-eclipse-plugin-2.6.0.jar

直接把jar包扔到eclipse的plugins目录下,然后重启eclipse ,接下来的配置操作可以参看http://www.cnblogs.com/huligong1234/p/4137133.html  此工具就是方便查看hdfs中的文件,可以在eclipse中上传或者下载hdfs中的文件。

说明的2点:

  1. Hadoop安装目录的配置需要你把linux下安装包download下来放到windows某个目录,然后配置这个目录即可,eclipse中的程序会读取此目录下的jar包。
  2. 其中我看到Hadoop Location的配置只需要配置一下Host就可以了,其他端口好像没撒用。

2. 创建Map/Reduce  project,一样参看http://www.cnblogs.com/huligong1234/p/4137133.html

说明的几点:

  1. log4j的配置很重要,先配置好这个,才能看到打印出来的debug日志
  2. windows下开发需要winutil.exe工具 ,否则报Could not locate executable winutils.exe in the Hadoop binaries.  找不到win上的执行程序,可以去https://github.com/srccodes/hadoop-common-2.2.0-bin 下载bin包,复制到本机的hadoop根目录下的bin包即可
  3. HADOOP_HOME or hadoop.home.dir are not set.错误,程序写死hadoop根目录
  4. 权限的问题,在linux下执行 hdfs dfs -chmod -R 777 /user/szuser  赋予所有的权限。或者打开conf/hdfs-site.xml,找到dfs.permissions属性修改为false(默认为true)OK了。注意生产环境处于安全考虑不要这么搞。
  5. 解决java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)异常问题 ,拷贝源码文件org.apache.hadoop.io.nativeio.NativeIO到项目中
    然后定位到609行,直接修改为return true;

3. Hadoop程序的基本操作,可以参考http://www.cnblogs.com/xia520pi/archive/2012/06/04/2534533.html  里面有很多例子

匿名进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>