情景:mapreduce任务出现如下错误 错误: Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster 全过程:
[hadoop@hadoop102 ~]$ hadoop jar wc.jar com.muzhi.mapreduce.wordcount1.WordCountDriver /input /output
2021-08-21 10:53:30,543 INFO client.RMProxy: Connecting to ResourceManager at hadoop103/192.168.220.103:8032
2021-08-21 10:53:31,430 WARN mapreduce.JobResourceUploader: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this.
2021-08-21 10:53:31,461 INFO mapreduce.JobResourceUploader: Disabling Erasure Coding for path: /tmp/hadoop-yarn/staging/hadoop/.staging/job_1629442479906_0002
2021-08-21 10:53:31,614 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
2021-08-21 10:53:31,823 INFO input.FileInputFormat: Total input files to process : 1
2021-08-21 10:53:31,878 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
2021-08-21 10:53:31,927 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
2021-08-21 10:53:31,961 INFO mapreduce.JobSubmitter: number of splits:1
2021-08-21 10:53:32,201 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
2021-08-21 10:53:32,272 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1629442479906_0002
2021-08-21 10:53:32,272 INFO mapreduce.JobSubmitter: Executing with tokens: []
2021-08-21 10:53:32,620 INFO conf.Configuration: resource-types.xml not found
2021-08-21 10:53:32,620 INFO resource.ResourceUtils: Unable to find 'resource-types.xml'.
2021-08-21 10:53:32,712 INFO impl.YarnClientImpl: Submitted application application_1629442479906_0002
2021-08-21 10:53:32,774 INFO mapreduce.Job: The url to track the job: http://hadoop103:8088/proxy/application_1629442479906_0002/
2021-08-21 10:53:32,777 INFO mapreduce.Job: Running job: job_1629442479906_0002
2021-08-21 10:53:36,844 INFO mapreduce.Job: Job job_1629442479906_0002 running in uber mode : false
2021-08-21 10:53:36,847 INFO mapreduce.Job: map 0% reduce 0%
2021-08-21 10:53:36,878 INFO mapreduce.Job: Job job_1629442479906_0002 failed with state FAILED due to: Application application_1629442479906_0002 failed 2 times due to AM Container for appattempt_1629442479906_0002_000002 exited with exitCode: 1
Failing this attempt.Diagnostics: [2021-08-21 10:53:35.878]Exception from container-launch.
Container id: container_1629442479906_0002_02_000001
Exit code: 1
[2021-08-21 10:53:35.923]Container exited with a non-zero exit code 1. Error file: prelaunch.err.
Last 4096 bytes of prelaunch.err :
Last 4096 bytes of stderr :
Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster
Please check whether your etc/hadoop/mapred-site.xml contains the below configuration:
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
[2021-08-21 10:53:35.924]Container exited with a non-zero exit code 1. Error file: prelaunch.err.
Last 4096 bytes of prelaunch.err :
Last 4096 bytes of stderr :
Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster
Please check whether your etc/hadoop/mapred-site.xml contains the below configuration:
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
</property>
For more detailed output, check the application tracking page: http://hadoop103:8088/cluster/app/application_1629442479906_0002 Then click on links to logs of each attempt.
. Failing the application.
2021-08-21 10:53:36,929 INFO mapreduce.Job: Counters: 0
[hadoop@hadoop102 ~]$
解决办法: 1.在 mapred-site.xml 中如下内容
<property>
<name>mapreduce.application.classpath</name>
<value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*:$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
2.还需在** mapred-site.xm**l 继续添加 yarn.application.classpath 查看:
[hadoop@hadoop102 hadoop-3.1.3]$ hadoop classpath
/opt/module/hadoop-3.1.3/etc/hadoop:/opt/module/hadoop-3.1.3/share/hadoop/common/lib/*:/opt/module/hadoop-3.1.3/share/hadoop/common/*:/opt/module/hadoop-3.1.3/share/hadoop/hdfs:/opt/module/hadoop-3.1.3/share/hadoop/hdfs/lib/*:/opt/module/hadoop-3.1.3/share/hadoop/hdfs/*:/opt/module/hadoop-3.1.3/share/hadoop/mapreduce/lib/*:/opt/module/hadoop-3.1.3/share/hadoop/mapreduce/*:/opt/module/hadoop-3.1.3/share/hadoop/yarn:/opt/module/hadoop-3.1.3/share/hadoop/yarn/lib/*:/opt/module/hadoop-3.1.3/share/hadoop/yarn/*
把“:”改成“,” 结果如下
<property>
<name>yarn.application.classpath</name>
<value>/opt/module/hadoop-3.1.3/etc/hadoop,
/opt/module/hadoop-3.1.3/share/hadoop/common/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/common/*,
/opt/module/hadoop-3.1.3/share/hadoop/hdfs,
/opt/module/hadoop-3.1.3/share/hadoop/hdfs/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/hdfs/*,
/opt/module/hadoop-3.1.3/share/hadoop/mapreduce/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/mapreduce/*,
/opt/module/hadoop-3.1.3/share/hadoop/yarn,
/opt/module/hadoop-3.1.3/share/hadoop/yarn/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/yarn/*
</value>
</property>
总共需要添加的内容
<!--用于集群跑mr任务-->
<property>
<name>mapreduce.application.classpath</name>
<value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*:$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>yarn.application.classpath</name>
<value>/opt/module/hadoop-3.1.3/etc/hadoop,
/opt/module/hadoop-3.1.3/share/hadoop/common/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/common/*,
/opt/module/hadoop-3.1.3/share/hadoop/hdfs,
/opt/module/hadoop-3.1.3/share/hadoop/hdfs/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/hdfs/*,
/opt/module/hadoop-3.1.3/share/hadoop/mapreduce/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/mapreduce/*,
/opt/module/hadoop-3.1.3/share/hadoop/yarn,
/opt/module/hadoop-3.1.3/share/hadoop/yarn/lib/*,
/opt/module/hadoop-3.1.3/share/hadoop/yarn/*
</value>
</property>
|