歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Eclipse調用Hadoop2.2運行MR程序

Eclipse調用Hadoop2.2運行MR程序

日期:2017/3/1 9:45:55   编辑:Linux編程

Hadoop:hadoop2.2 ,windows myeclipse環境;

Eclipse調用hadoop運行MR程序其實就是普通的java程序可以提交MR任務到集群執行而已。在Hadoop1中,只需指定jt(jobtracker)和fs(namenode)即可,一般如下:

Configuration conf = new Configuration();
conf.set("mapred.job.tracker", "192.168.128.138:9001");
conf.set("fs.default.name","192.168.128.138:9000");

上面的代碼在hadoop1中運行是ok的,完全可以使用java提交任務到集群運行。但是,hadoop2卻是沒有了jt,新增了yarn。這個要如何使用呢?最簡單的想法,同樣指定其配置,試試。

Configuration conf = new YarnConfiguration();
conf.set("fs.defaultFS", "hdfs://node31:9000");
conf.set("mapreduce.framework.name", "yarn");
conf.set("yarn.resourcemanager.address", "node31:8032");

恩,這樣配置後,可以運行,首先是下面的錯誤:

2014-04-03 21:20:21,568 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(303)) - 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:278)
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:300)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:293)
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:76)
at org.apache.hadoop.yarn.conf.YarnConfiguration.<clinit>(YarnConfiguration.java:345)
at org.fansy.hadoop.mr.WordCount.getConf(WordCount.java:104)
at org.fansy.hadoop.mr.WordCount.runJob(WordCount.java:84)
at org.fansy.hadoop.mr.WordCount.main(WordCount.java:47)

這個錯誤不用管,這個好像是windows調用的時候就會出的錯誤。

然後是什麼權限問題之類的,這個時候就需要去調整下權限,至少我目前是這樣做的。調整的權限主要有/tmp 以及運行wordcount的輸入、輸出目錄。命令如下: $HADOOP_HOME/bin/hadoop fs -chmod -R 777 /tmp 。

然後直到你出現了下面的錯誤,那麼,好了,可以說你已經成功了一半了。

2014-04-03 20:32:36,596 ERROR [main] security.UserGroupInformation (UserGroupInformation.java:doAs(1494)) - PriviledgedActionException as:Administrator (auth:SIMPLE) cause:java.io.IOException: Failed to run job : Application application_1396459813671_0001 failed 2 times due to AM Container for appattempt_1396459813671_0001_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:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)


.Failing this attempt.. Failing the application.

用上面出現的錯誤去google,可以得到這個網頁:https://issues.apache.org/jira/browse/MAPREDUCE-5655 。 恩,對的。這個網頁就是我們的solution。

我們分為1、2、3步驟吧。

1. 修改MRapps.java 、YARNRunner.java的源碼,然後打包替換原來的jar包中的相應class文件,這兩個jar我已經打包,可以在這裡下載http://download.csdn.net/detail/fansy1990/7143547 。然後替換集群中相應的jar吧,同時需要注意替換Myeclipse中導入的包。額,說起Myeclipse中的jar包,這裡還是先上幅jar包的圖吧:



2. 修改mapred-default.xml ,添加:(這個只需在eclipse中導入的jar包修改即可,修改後的jar包不用上傳到集群)

<property>
<name>mapred.remote.os</name>
<value>Linux</value>
<description>
Remote MapReduce framework's OS, can be either Linux or Windows
</description>
</property>

(題外話,添加了這個屬性後,按說我new一個Configuration後,我使用conf.get("mapred.remote.os")的時候應該是可以得到Linux的,但是我得到的卻是null,這個就不清楚是怎麼了。)

其文件在:


這時,你再運行程序,額好吧程序基本可以提交了,但是還是報錯,查看log,可以看到下面的錯誤:

Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster

Copyright © Linux教程網 All Rights Reserved