Win7 Eclipse调试Centos Hadoop2.2-Mapreduce(转)

一. 自己搭建开发环境

今天自己搭建了一套Centos5.3 + Hadoop2.2 + Hbase0.96.1.1的开发环境,Win7 Eclipse调试MapReduce成功。可能是版本比较高的原因,出了问题,网上找不到完整解决方案,只能靠自己。

二. Hadoop安装

这个就不啰嗦了,网上大把文章。我下载的是hadoop-2.2.0.tar.gz

  1. http://www.cnblogs.com/xia520pi/archive/2012/05/16/2503949.html 很详细的介绍了Hadoop Hdfs的安装。它这个不是Hadoop2.2的,但配置都大同小异。
  2. MapReduce的配置可以参考http://blog.sina.com.cn/s/blog_546abd9f0101i8b8.html

安装成功后,能顺利查看以下几个页面,就OK了。我的集群环境是200master,201-203slave。

  1. dfs.http.address   192.168.1.200:50070
  2. dfs.secondary.http.address  192.168.1.200:50090
  3. dfs.datanode.http.address  192.168.1.201:50075
  4. yarn.resourcemanager.webapp.address  192.168.1.200:50030
  5. mapreduce.jobhistory.webapp.address 192.168.1.200:19888。这个好像访问不了。需要启动hadoop/sbin/mr-jobhistory-daemon.sh start historyserver才可以访问。

三. Hadoop2.x eclispe-plugin

https://github.com/winghc/hadoop2x-eclipse-plugin

目前这个插件还在开发中,你可以自己下载源码编译,网上也有人发布编译好的jar。

http://blog.csdn.net/zythy/article/details/17397153 这个同学写的很详细了。

需要注意一点的是,Hadoop installation directory里填写Win下的hadoop home地址,其目的在于创建MapReduce Project能从这个地方自动引入MapReduce需要的jar。解压hadoop-2.2.0.tar.gz到本地即可。

四. 各种问题

上面一步完成后,创建一个MapReduce Project,运行时发现出问题了。

    1. java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

    跟代码就去发现是HADOOP_HOME的问题。如果HADOOP_HOME为空,必然fullExeName为null\bin\winutils.exe。解决方法很简单啦,乖乖的配置环境变量吧,不想重启电脑可以在MapReduce程序里加上System.setProperty("hadoop.home.dir", "...");暂时缓缓。org.apache.hadoop.util.Shell.java

    1. public static final String getQualifiedBinPath(String executable)
    2. throws IOException {
    3. // construct hadoop bin path to the specified executable
    4. String fullExeName = HADOOP_HOME_DIR + File.separator + "bin"
    5. + File.separator + executable;
    6. File exeFile = new File(fullExeName);
    7. if (!exeFile.exists()) {
    8. throw new IOException("Could not locate executable " + fullExeName
    9. + " in the Hadoop binaries.");
    10. }
    11. return exeFile.getCanonicalPath();
    12. }
    13. private static String HADOOP_HOME_DIR = checkHadoopHome();
    14. private static String checkHadoopHome() {
    15. // first check the Dflag hadoop.home.dir with JVM scope
    16. String home = System.getProperty("hadoop.home.dir");
    17. // fall back to the system/user-global env variable
    18. if (home == null) {
    19. home = System.getenv("HADOOP_HOME");
    20. }
    21. ...
    22. }
  1. 这个时候得到完整的地址fullExeName,我机器上是D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe。继续执行代码又发现了错误
    1. Could not locate executable D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe in the Hadoop binaries.

    就去一看,没有winutils.exe这个东西。去https://github.com/srccodes/hadoop-common-2.2.0-bin下载一个,放就去即可。

  2. 继续出问题
    1. at org.apache.hadoop.util.Shell.execCommand(Shell.java:661)
    2. at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:639)
    3. at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:435)

    继续跟代码org.apache.hadoop.util.Shell.java

    1. public static String[] getSetPermissionCommand(String perm, boolean recursive,
    2. String file) {
    3. String[] baseCmd = getSetPermissionCommand(perm, recursive);
    4. String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
    5. cmdWithFile[cmdWithFile.length - 1] = file;
    6. return cmdWithFile;
    7. }
    8. /** Return a command to set permission */
    9. public static String[] getSetPermissionCommand(String perm, boolean recursive) {
    10. if (recursive) {
    11. return (WINDOWS) ? new String[] { WINUTILS, "chmod", "-R", perm }
    12. : new String[] { "chmod", "-R", perm };
    13. } else {
    14. return (WINDOWS) ? new String[] { WINUTILS, "chmod", perm }
    15. : new String[] { "chmod", perm };
    16. }
    17. }

    cmdWithFile数组的内容为{"D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe", "chmod", "755", "xxxfile"},我把这个单独在cmd里执行了一下,发现

    1. 无法启动此程序,因为计算机中丢失 MSVCR100.dll

    那就下载一个呗http://files.cnblogs.com/sirkevin/msvcr100.rar,丢到C:\Windows\System32里面。再次cmd执行,又来了问题

    1. 应用程序无法正常启动(0xc000007b)

    下载http://blog.csdn.net/vbcom/article/details/7245186 DirectX_Repair来解决这个问题吧。记得修复完后要重启电脑。搞定后cmd试一下,很棒。

  3. 到了这里,已经看到曙光了,但问题又来了
    1. Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

    代码就去

    1. /** Windows only method used to check if the current process has requested
    2. *  access rights on the given path. */
    3. private static native boolean access0(String path, int requestedAccess);

    显然缺少dll文件,还记得https://github.com/srccodes/hadoop-common-2.2.0-bin下载的东西吧,里面就有hadoop.dll,最好的方法就是用hadoop-common-2.2.0-bin-master/bin目录替换本地hadoop的bin目录,并在环境变量里配置PATH=HADOOP_HOME/bin,重启电脑。

  4. 终于看到了MapReduce的正确输出output99。Win7 Eclipse调试Centos Hadoop2.2-Mapreduce(转)

五. 总结

  1. hadoop eclipse插件不是必须的,其作用在我看来就是如下三点(这个是一个错误的认识,具体请参考http://zy19982004.iteye.com/blog/2031172)。study-hadoop是一个普通project,直接运行(不通过Run on Hadoop这只大象),一样可以调试到MapReduce。
    1. 对hadoop中的文件可视化。
    2. 创建MapReduce Project时帮你引入依赖的jar。
    3. Configuration conf = new Configuration();时就已经包含了所有的配置信息。
  2. 还是自己下载hadoop2.2的源码编译好,应该是不会有任何问题的(没有亲测)。

六. 其它问题

  1. 还是
    1. Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

    代码跟到org.apache.hadoop.util.NativeCodeLoader.java去看

    1. static {
    2. // Try to load native hadoop library and set fallback flag appropriately
    3. if(LOG.isDebugEnabled()) {
    4. LOG.debug("Trying to load the custom-built native-hadoop library...");
    5. }
    6. try {
    7. System.loadLibrary("hadoop");
    8. LOG.debug("Loaded the native-hadoop library");
    9. nativeCodeLoaded = true;
    10. } catch (Throwable t) {
    11. // Ignore failure to load
    12. if(LOG.isDebugEnabled()) {
    13. LOG.debug("Failed to load native-hadoop with error: " + t);
    14. LOG.debug("java.library.path=" +
    15. System.getProperty("java.library.path"));
    16. }
    17. }
    18. if (!nativeCodeLoaded) {
    19. LOG.warn("Unable to load native-hadoop library for your platform... " +
    20. "using builtin-java classes where applicable");
    21. }
    22. }

    这里报错如下

    1. DEBUG org.apache.hadoop.util.NativeCodeLoader - Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: HADOOP_HOME\bin\hadoop.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform

    怀疑是32位jdk的问题,替换成64位后,没问题了

    1. 2014-03-11 19:43:08,805 DEBUG org.apache.hadoop.util.NativeCodeLoader - Trying to load the custom-built native-hadoop library...
    2. 2014-03-11 19:43:08,812 DEBUG org.apache.hadoop.util.NativeCodeLoader - Loaded the native-hadoop library

    这里也解决了一个常见的警告

    1. WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
上一篇:css 字体样式设置大全


下一篇:CSS和JavaScript标签style属性对照表