- Java Application
- Run on Hadoop
Hadoop学习三十二:Win7下无法提交MapReduce Job到集群环境
一. 对hadoop eclipse plugin认识不足
如果说Run As Java Application在本地运行还好说,它直接使用项目下的依赖的Hadoop Jar,使用Hdfs作为input,对MyWordCount main方法的一步步调用,把输出结果写入Hdfs完成。这一切都跟MapReduce集群无关。
二. Hadoop2.x eclispe-plugin
再次下载源码https://github.com/winghc/hadoop2x-eclipse-plugin。简单看了几个类,如
Wizard for publishing a job to a Hadoop server public class RunOnHadoopWizard extends Wizard {} Representation of a Map/Reduce running job on a given location public class HadoopJob {}
从注释就可以看出来插件是支持远程提交Job的。那是我使用不当吗?
三. Hadoop2.x eclispe-plugin工作原理
Run on Hadoop时
- 会在EclipseWorkspace\.metadata\.plugins\org.apache.hadoop.eclipse\下生成一个MapReduce Jar和一个对应文件夹(包含core-site.xml)。我们在Eclipse里配置的Hadoop集群信息会写到core-site.xml里面。
- 然后把此Job依据配置信息提交到本地或者集群。
我去看了下Job对应的core-site.xml,mapreduce.framework.name居然是local,yarn.resourcemanager.address居然是0.0.0.0:8032,于是回到Eclispe配置集群环境的地方,发现果然是这样的,也就是说插件根本没有把集群环境下的配置信息全部copy到Eclipse下。把Eclipse下这两项修改后,还是在本地运行,我就奇怪了,于是我在程序里加上
conf.set("mapreduce.framework.name", "yarn"); conf.set("yarn.resourcemanager.address", "192.168.1.200:8032");
终于正常提交到集群环境了。我怀疑插件最后在什么地方还是读取到了local和0.0.0.0:8032,写入了core-site.xml,有时间再去看看插件的源码。
四. 继续出问题
Job虽然是提交到了集群环境,但运行失败了。查看日志如下
2014-04-01 19:50:36,731 INFO org.apache.hadoop.yarn.server.resourcemanager.amlauncher.AMLauncher: Command to launch container container_1396351641800_0005_02_000001 : %JAVA_HOME% -Dlog4j.configuration=container-log4j.properties -Dyarn.app.container.log.dir=<LOG_DIR> -Dyarn.app.container.log.filesize=0 -Dhadoop.root.logger=INFO,CLA -Xmx1024m org.apache.hadoop.mapreduce.v2.app.MRAppMaster 1><LOG_DIR>/stdout 2><LOG_DIR>/stderr 2014-03-13 22:50:41,317 INFO org.apache.hadoop.mapreduce.Job - Job job_1394710790246_0003 failed with state FAILED due to: Application application_1394710790246_0003 failed 2 times due to AM Container for appattempt_1394710790246_0003_000002 exited with exitCode: 1 due to: Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException: /bin/bash: line 0: fg: no job control 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.yarn.server.nodemanager.DefaultContainerExecutor.launchContainer(DefaultContainerExecutor.java:195) at org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:283) at org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:79) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
上网找答案,发现是Hadoop本身的问题。
https://issues.apache.org/jira/browse/YARN-1298
https://issues.apache.org/jira/browse/MAPREDUCE-5655。
五. 自己编译Hadoop2.2
- 下载Hadoop2.2源码http://apache.fayea.com/apache-mirror/hadoop/common/hadoop-2.2.0/hadoop-2.2.0-src.tar.gz
- 下载https://issues.apache.org/jira/i#browse/MAPREDUCE-5655两个patch
- 下载https://issues.apache.org/jira/i#browse/HADOOP-10110这个patch
- patch指令。patch -p0 < MRApps.patch。p0的0代表进去层次。不会的参考http://hi.baidu.com/thinkinginlamp/item/0ba1d051319b5ac09e2667f8
- 然后按照http://my.oschina.net/yiyuqiuchi/blog/188510去编译。hadoop-2.2.0-src/hadoop-dist/targethadoop-2.2.0.tar.gz就是编译好的。
给两张patch前后的对照图
下图左边为patch前Hadoop源码
下图左边为patch成功后Hadoop源码
六. 使用自己编译的包
- 检查看看patch是否被打包进去了。通过查看MRApps.class字节码得知已经被打包进去。通过查看YARNRunner.class字节码也是正确的,我在YARNRunner.java里面设置了一个PATCH_TEST编译时常量,"zy19982004"的字节码已经被内嵌到class的字节码里。
- 替换集群Jar,因为上述三个patch只涉及到两个Jar,另外一个pacth是修改pom文件并且是scope test,可以不管。用hadoop-2.2.0\share\hadoop\mapreduce\hadoop-mapreduce-client-common-2.2.0.jar(MRApps.patch)替换集群下的对应jar,用hadoop-2.2.0\share\hadoop\mapreduce\hadoop-mapreduce-client-jobclient-2.2.0.jar(YARNRunner.patch)替换集群下的对应jar。
- 修改windows环境下的mapred-site.xml,添加
<property> <name>mapred.remote.os</name> <value>Linux</value> <description>Remote MapReduce framework's OS, can be either Linux or Windows</description> </property>
- 重启集群,这个错误已经没有了,但出现了另外的错误。
Application application_1396339724108_0014 failed 2 times due to AM Container for appattempt_1396339724108_0014_000002 exited with exitCode: 1 due to: Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException: 2014-04-01 19:50:36,731 INFO org.apache.hadoop.yarn.server.resourcemanager.amlauncher.AMLauncher: Command to launch container container_1396351641800_0005_02_000001 : $JAVA_HOME/bin/java -Dlog4j.configuration=container-log4j.properties -Dyarn.app.container.log.dir=<LOG_DIR> -Dyarn.app.container.log.filesize=0 -Dhadoop.root.logger=INFO,CLA -Xmx1024m org.apache.hadoop.mapreduce.v2.app.MRAppMaster 1><LOG_DIR>/stdout 2><LOG_DIR>/stderr
然后1) Add such config property to your mapred-site.xml (client side only): <property> <name>mapreduce.application.classpath</name> <value> $HADOOP_CONF_DIR, $HADOOP_COMMON_HOME/share/hadoop/common/*, $HADOOP_COMMON_HOME/share/hadoop/common/lib/*, $HADOOP_HDFS_HOME/share/hadoop/hdfs/*, $HADOOP_HDFS_HOME/share/hadoop/hdfs/lib/*, $HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*, $HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*, $HADOOP_YARN_HOME/share/hadoop/yarn/*, $HADOOP_YARN_HOME/share/hadoop/yarn/lib/* </value> </property>
终于成功了。。。
七. 不使用hadoop eclispe plugin的场景
自己调试Hadoop源码的时候,Debug As Java Application即可。前面两篇博客解决错误都是通过debug源码来解决的。
八. 总结
Window向Linux Hadoop提交作业的方法
- 配置好hadoop eclipse plugin。
- Job配置文件里mapreduce.framework.name为yarn。其它配置也需要正确。
- Run On Hadoop
Run As Application其实也可以提交Job,依赖于上一次Run on Hadoop过程中产生的jar,这为我们debug提供了一种思路。