无法找到或加载主类org.apache.hadoop.mapreduce.v2.app.MRAppMaster

时间:2018-06-19 11:42:33

标签: hadoop hadoop3

mapred-site.xml的内容:

<configuration>
<property>
 <name>mapreduce.framework.name</name>
 <value>yarn</value>
</property>

<property>
 <name>yarn.app.mapreduce.am.env</name>
 <value>HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0</value>
</property>

<property>
 <name>mapreduce.map.env</name>
 <value>HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0</value>
</property>

<property>
 <name>mapreduce.reduce.env</name>
 <value>HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0</value>
</property>

<property> 
    <name>mapreduce.application.classpath</name>
    <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
</property>

</configuration>

尽管我已经设置了yarn.app.mapreduce.am.env和其他参数;我收到无法找到或加载主类org.apache.hadoop.mapreduce.v2.app.MRAppMaster错误。 我正在尝试在Linux机器上安装hadoop的地方远程运行map reduce程序,而我正在Windows机器上运行它。 以下是我的作业配置设置。

public class WordCount {
  public static void main(String[] args)
      throws IOException, ClassNotFoundException, InterruptedException {
    //
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser("admin");
    ugi.doAs(new PrivilegedExceptionAction<Void>() {

      public Void run() throws Exception {
        try {
          Configuration configuration = new Configuration();

          configuration.set("yarn.resourcemanager.address", "192.168.33.75:50001"); // see step 3
          configuration.set("mapreduce.framework.name", "yarn");
          // configuration.set("yarn.app.mapreduce.am.env",
          // "HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0");
          // configuration.set("mapreduce.map.env", "HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0");
          // configuration.set("mapreduce.reduce.env",
          // "HADOOP_MAPRED_HOME=/home/admin/hadoop-3.1.0");
          configuration.set("fs.defaultFS", "hdfs://192.168.33.75:54310"); // see step 2
          configuration.set("mapreduce.app-submission.cross-platform", "true");
          configuration.set("mapred.remote.os", "Linux");
          configuration.set("yarn.application.classpath",
              "$HADOOP_CONF_DIR:$HADOOP_COMMON_HOME/*:$HADOOP_COMMON_HOME/lib/*:"
                  + "$HADOOP_HDFS_HOME/*:$HADOOP_HDFS_HOME/lib/*:"
                  + "$HADOOP_YARN_HOME/*:$HADOOP_YARN_HOME/lib/*:"
                  + "$HADOOP_MAPRED_HOME/*:$HADOOP_MAPRED_HOME/lib/*");

          Job job = Job.getInstance(configuration);

          job.setJarByClass(WordCount.class); // use this when uploaded the Jar to the server and
                                              // running the job directly and locally on the server
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(IntWritable.class);
          job.setMapperClass(MapForWordCount.class);
          job.setReducerClass(ReduceForWordCount.class);

          Path input = new Path("/user/admin/wordCountInput.txt");
          Path output = new Path("/user/admin/output");
          FileInputFormat.addInputPath(job, input);
          FileOutputFormat.setOutputPath(job, output);
          System.exit(job.waitForCompletion(true) ? 0 : 1);
        } catch (Exception e) {
          e.printStackTrace();
        }
        return null;
      }

    });


  }

请帮助我。最近6天以来,我一直在解决这个问题。非常感谢。 Hadoop版本:3.1.0

4 个答案:

答案 0 :(得分:7)

我遇到了同样的问题,并通过将其添加到 mapred-site.xml 中来解决(因此,请编辑您的 mapreduce.application.classpath 属性)

<property> 
    <name>mapreduce.application.classpath</name>
    <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/common/*,$HADOOP_MAPRED_HOME/share/hadoop/common/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/yarn/*,$HADOOP_MAPRED_HOME/share/hadoop/yarn/lib/*,$HADOOP_MAPRED_HOME/share/hadoop/hdfs/*,$HADOOP_MAPRED_HOME/share/hadoop/hdfs/lib/*</value>
</property>

答案 1 :(得分:3)

我在yarn-site.xml中添加了以下属性

<property>
  <name>yarn.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>

在我的地图精简程序中做了相同的更改。

  configuration.set("yarn.application.classpath",
              "{{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/*");

我的程序现在运行顺利。随时问我细节。

答案 2 :(得分:2)

只需编辑 mapred-site.xml 文件:

添加以下属性:

  1. <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property>

  2. <property> <name>yarn.app.mapreduce.am.env</name> <value>HADOOP_MAPRED_HOME=/Users/adityaatri/Applications/hadoop-3.1.3</value> </property>

  3. <property> <name>mapreduce.map.env</name> <value>HADOOP_MAPRED_HOME=/Users/adityaatri/Applications/hadoop-3.1.3</value> </property>

  4. <property> <name>mapreduce.reduce.env</name> <value>HADOOP_MAPRED_HOME=/Users/adityaatri/Applications/hadoop-3.1.3</value> </property>

现在,针对上述所有4个属性,将路径/Users/adityaatri/Applications/hadoop-3.1.3替换为您的Hadoop本地地址。

现在添加第5个属性:

  1. <property> <name>mapreduce.application.classpath</name> <value></value> </property>

在终端中执行以下命令之后,必须在 <value> 元素中填充内容:

  1. export HADOOP_CLASSPATH=$(hadoop classpath)

  2. echo $HADOOP_CLASSPATH

我终端的输出:

/Users/adityaatri/Applications/hadoop-3.1.3/etc/hadoop:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/common/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/common/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/hdfs:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/hdfs/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/hdfs/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/mapreduce/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/mapreduce/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/yarn:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/yarn/lib/*:/Users/adityaatri/Applications/hadoop-3.1.3/share/hadoop/yarn/*

将此内容复制到第5个属性的 <value> 元素内。

现在您将不会收到任何错误。 :)

答案 3 :(得分:0)

问题是您的资源管理器(纱线)无法加载Hadoop库(jar)。 我通过更新配置解决了这个问题。 将此添加到yarn-site.xml:

<property>
<name>yarn.application.classpath</name>
<value>C:/hadoop-2.8.0/share/hadoop/mapreduce/*,C:/hadoop-2.8.0/share/hadoop/mapreduce/lib/*,C:/Hadoop-2.8.0/share/hadoop/common/*,C:/Hadoop-2.8.0/share/hadoop/common/lib/*,
    C:/hadoop-2.8.0/share/hadoop/hdfs/*,C:/hadoop-2.8.0/share/hadoop/hdfs/lib/*,C:/hadoop-2.8.0/share/hadoop/yarn/*,C:/hadoop-2.8.0/share/hadoop/yarn/lib/*</value>
</property>

请注意,根据您的系统,此处使用的路径可以是相对的。