hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.

错误:
Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.
说明:计算wordcount出错,错误提示补充mapred-site.xml配置
hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第1张图片

解决方法:1
这个在我这里不管用(很多博客都说改这个)
在 mapred-site-xml中插入以下代码

<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:(亲测有效)

  • 1:输入命令:hadoop classpath
    举例:
    hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第2张图片
  • 2:复制该返回值,并修改成以下格式
        <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>

  • 3:然后把该代码分别加入到yarn-site.xmlmapred-site.xml里面
    举例yarn-site.xml,mapred-site.xml同
    hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第3张图片
    !!!!记得将这两个修改的文件分发到其他的机器,然后重启yarn,dfs
    hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第4张图片
    hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第5张图片
    hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第6张图片

成功!!!(开心)
hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第7张图片

HDFS上结果!!!
hadoop运行踩坑:Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app._第8张图片

你可能感兴趣的:(Bug)