Hadoop学习三十:Win7 Eclipse调试Centos Hadoop2.2-Mapreduce
一. 自己搭建开发环境
今天自己搭建了一套Centos5.3 + Hadoop2.2 + Hbase0.96.1.1的开发环境,Win7 Eclipse调试MapReduce成功。可能是版本比较高的原因,出了问题,网上找不到完整解决方案,只能靠自己。
二. Hadoop安装
这个就不啰嗦了,网上大把文章。我下载的是hadoop-2.2.0.tar.gz。
- http://www.cnblogs.com/xia520pi/archive/2012/05/16/2503949.html 很详细的介绍了Hadoop Hdfs的安装。它这个不是Hadoop2.2的,但配置都大同小异。
- MapReduce的配置可以参考http://blog.sina.com.cn/s/blog_546abd9f0101i8b8.html。
安装成功后,能顺利查看以下几个页面,就OK了。我的集群环境是200master,201-203slave。
- dfs.http.address 192.168.1.200:50070
- dfs.secondary.http.address 192.168.1.200:50090
- dfs.datanode.http.address 192.168.1.201:50075
- yarn.resourcemanager.webapp.address 192.168.1.200:50030
- 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,运行时发现出问题了。
-
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
public static final String getQualifiedBinPath(String executable) throws IOException { // construct hadoop bin path to the specified executable String fullExeName = HADOOP_HOME_DIR + File.separator + "bin" + File.separator + executable; File exeFile = new File(fullExeName); if (!exeFile.exists()) { throw new IOException("Could not locate executable " + fullExeName + " in the Hadoop binaries."); } return exeFile.getCanonicalPath(); } private static String HADOOP_HOME_DIR = checkHadoopHome(); private static String checkHadoopHome() { // first check the Dflag hadoop.home.dir with JVM scope String home = System.getProperty("hadoop.home.dir"); // fall back to the system/user-global env variable if (home == null) { home = System.getenv("HADOOP_HOME"); } ... } -
这个时候得到完整的地址fullExeName,我机器上是D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe。继续执行代码又发现了错误
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下载一个,放就去即可。
-
继续出问题
at org.apache.hadoop.util.Shell.execCommand(Shell.java:661) at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:639) at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:435)继续跟代码org.apache.hadoop.util.Shell.java
public static String[] getSetPermissionCommand(String perm, boolean recursive, String file) { String[] baseCmd = getSetPermissionCommand(perm, recursive); String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1); cmdWithFile[cmdWithFile.length - 1] = file; return cmdWithFile; } /** Return a command to set permission */ public static String[] getSetPermissionCommand(String perm, boolean recursive) { if (recursive) { return (WINDOWS) ? new String[] { WINUTILS, "chmod", "-R", perm } : new String[] { "chmod", "-R", perm }; } else { return (WINDOWS) ? new String[] { WINUTILS, "chmod", perm } : new String[] { "chmod", perm }; } }cmdWithFile数组的内容为{"D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe", "chmod", "755", "xxxfile"},我把这个单独在cmd里执行了一下,发现
无法启动此程序,因为计算机中丢失 MSVCR100.dll那就下载一个呗http://files.cnblogs.com/sirkevin/msvcr100.rar,丢到C:\Windows\System32里面。再次cmd执行,又来了问题
应用程序无法正常启动(0xc000007b)下载http://blog.csdn.net/vbcom/article/details/7245186 DirectX_Repair来解决这个问题吧。记得修复完后要重启电脑。搞定后cmd试一下,很棒。
-
到了这里,已经看到曙光了,但问题又来了
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z代码就去
/** Windows only method used to check if the current process has requested * access rights on the given path. */ 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,重启电脑。
-
终于看到了MapReduce的正确输出output99。

五. 总结
-
hadoop eclipse插件不是必须的,其作用在我看来就是如下三点(这个是一个错误的认识,具体请参考http://zy19982004.iteye.com/blog/2031172)。study-hadoop是一个普通project,直接运行(不通过Run on Hadoop这只大象),一样可以调试到MapReduce。
-
- 对hadoop中的文件可视化。
- 创建MapReduce Project时帮你引入依赖的jar。
- Configuration conf = new Configuration();时就已经包含了所有的配置信息。
-
-
还是自己下载hadoop2.2的源码编译好,应该是不会有任何问题的(没有亲测)。
六. 其它问题
-
还是
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去看
static { // Try to load native hadoop library and set fallback flag appropriately if(LOG.isDebugEnabled()) { LOG.debug("Trying to load the custom-built native-hadoop library..."); } try { System.loadLibrary("hadoop"); LOG.debug("Loaded the native-hadoop library"); nativeCodeLoaded = true; } catch (Throwable t) { // Ignore failure to load if(LOG.isDebugEnabled()) { LOG.debug("Failed to load native-hadoop with error: " + t); LOG.debug("java.library.path=" + System.getProperty("java.library.path")); } } if (!nativeCodeLoaded) { LOG.warn("Unable to load native-hadoop library for your platform... " + "using builtin-java classes where applicable"); } }这里报错如下
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位后,没问题了
2014-03-11 19:43:08,805 DEBUG org.apache.hadoop.util.NativeCodeLoader - Trying to load the custom-built native-hadoop library... 2014-03-11 19:43:08,812 DEBUG org.apache.hadoop.util.NativeCodeLoader - Loaded the native-hadoop library这里也解决了一个常见的警告
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
楼主你好!我运行报错 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in SLF4J: Found binding in SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type ERROR (Shell.java: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.(Shell.java:363) at org.apache.hadoop.util.StringUtils.(StringUtils.java:78) at org.apache.hadoop.security.Groups.parseStaticMapping(Groups.java:93) at org.apache.hadoop.security.Groups.(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.hbase.security.User$SecureHadoopUser.(User.java:285) at org.apache.hadoop.hbase.security.User$SecureHadoopUser.(User.java:281) at org.apache.hadoop.hbase.security.User.getCurrent(User.java:185) at org.apache.hadoop.hbase.security.UserProvider.getCurrent(UserProvider.java:88) at org.apache.hadoop.hbase.client.HConnectionKey.(HConnectionKey.java:71) at org.apache.hadoop.hbase.client.ConnectionManager.getConnectionInternal(ConnectionManager.java:277) at org.apache.hadoop.hbase.client.HBaseAdmin.(HBaseAdmin.java:202) at hbase.HBaseJavaAPI.createTable(HBaseJavaAPI.java:46) at hbase.HBaseJavaAPI.main(HBaseJavaAPI.java:148) 表还能创建成功,这是什么原因呢???
非常感谢,我也是一直被这个问题困扰,终于找到解决方案了。
楼主我也是出了这个问题,但是我直接跑程序是没问题,我放在tomcat下运行程序就会出现这个问题,按照你说的放hadoop.dll也放了,但没有用,怎么办呢????
不错,谢谢! :D
好文章 指出的一点, 需要将hadoop.dll放到system32 下
你好!我想问一下我运行程序的时候怎么报: log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Exception in thread "main" org.apache.hadoop.util.Shell$ExitCodeException: at org.apache.hadoop.util.Shell.runCommand(Shell.java:464) at org.apache.hadoop.util.Shell.run(Shell.java:379) at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:589) at org.apache.hadoop.util.Shell.execCommand(Shell.java:678) at org.apache.hadoop.util.Shell.execCommand(Shell.java:661) at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:639) at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:435) at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:277) at org.apache.hadoop.mapreduce.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:125) at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:344) at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1268) at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1265) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:396) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491) at org.apache.hadoop.mapreduce.Job.submit(Job.java:1265) at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1286) at com.panda.test.MRModel.run(MRModel.java:70) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
不好意思 这几天没有上网
HADOOP_HOME和JAVA_HOME一样的处理方式 把你在linux下的安装包 解压到win下某一目录即可
楼主,你说 java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
出这个错误,是因为win中没有这只HADOOP_HOME,但是win7中怎么会有HADOOP_HOME呢,设置后指向什么位置呢,win7中又不能安装hadoop,请问楼主这个问题具体怎么解决?谢谢
不需要 报错可能是因为插件和hadoop版本及eclipse版本不一致
lz好,我将hadoop-eclipse的插件导入了eclipse创建项目时显示mapreduce但是不能创建,总是报错,hadoop的解压目录需要配置到win的环境变量中吗
1.是在windows下配置 HADOOP_HOME 2.不行就System.setProperty("hadoop.home.dir", "...");
2014-06-02 13:43:11,550 ERROR util.Shell (Shell.java:getWinUtilsPath(336)) - 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:318) at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:333) at org.apache.hadoop.util.Shell.(Shell.java:326) at org.apache.hadoop.util.StringUtils.(StringUtils.java:76) at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1324) HADOOP_HOME我配置了,可怎么还报上边的错
试了下出现了 Exception in thread "main" java.lang.UnsatisfiedLinkError: no hadoop in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1030) at score.ScoreAnalyze.main(ScoreAnalyze.java:60)
不太确定你是什么原因
System.loadLibrary("hadoop"); 看会不会报错
楼主你好,我也遇到了这个错误 Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z 按照你的办法编译了hadoop.dll然后放到bin目录下并没有解决这个问题,然后我换了好几个版本的hadoop.dll仍然不行,我的系统是win7 32位的
lz,我把hadoop.dll放进bin下面了,怎么还是报NativeIO$Windows.access0(Ljava/lang/String;I)Z异常,可能错在什么地方了,谢谢!
有生产环境去运用最好 没有就多看debug源码
你好,我遇到了您同样的问题,但是我按照您的方法来测试了,但是还是不行,也不知道为什么同样是job.waitForCompletion(true)报错,您能给点详细信息吗? 如果集群配但是yarn框架就指定到hadoop安装包的yarn下,如果是mapreduce框架就指定到mapreduce下,是一样的异常信息?.. job.waitForCompletion(true)这是执行job入口,,能否贴下具体异常信息..
你好,我遇到了您同样的问题,但是我按照您的方法来测试了,但是还是不行,也不知道为什么同样是job.waitForCompletion(true)报错,您能给点详细信息吗?