Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MapReduce作业在HADOOP-2.6.0中不起作用_Hadoop_Mapreduce - Fatal编程技术网

MapReduce作业在HADOOP-2.6.0中不起作用

MapReduce作业在HADOOP-2.6.0中不起作用,hadoop,mapreduce,Hadoop,Mapreduce,我正在尝试运行wordcount示例 这是密码 import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import

我正在尝试运行wordcount示例

这是密码

   import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCount {

  public static class TokenizerMapper
       extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values,
                       Context context
                       ) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}
我偶然发现了这个帖子
但解决方案对我不起作用

您使用的是Hadoop 2.6和mapred软件包。我认为新的包名包括mapreduce。请按照示例运行正确的版本。您还可以使用和来理解两者之间的差异。最后,我解决了这个问题。我需要在warn-site.xml中添加以下属性

 <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>Hostname-of-your-RM</value>
        <description>The hostname of the RM.</description>
    </property>

warn.resourcemanager.hostname
您的RM的主机名
RM的主机名。

这将解决您的问题。

请添加作业类、地图类和减速器类,以帮助您better@Ramzy我更新了我的问题我把它列为树。同样的问题你们是在集群还是在本地工作区运行。如果是本地的,您可以添加任何调试语句并查看,如果您得到任何异常,哪里可以得到调试语句?我的意思是在java代码中,以及您参考的文章中提到的日志中。即使我不确定,由于没有异常,它在哪里失败了。我观察到的一件事是,它建议使用ToolRunner接口。这是写作业的另一种方式。你能试试看它是否管用吗。此外,如果您的映射器被选中,那么它应该显示如下“mapreduce.Job:map 0%reduce 0%mapreduce.Job:map 100%reduce 0%
 <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>Hostname-of-your-RM</value>
        <description>The hostname of the RM.</description>
    </property>