我已经设置了hadoop-1.2.1多节点集群。请帮我,我花了很多时间,但不了解为什么没有mapreduce代码运行。在bashr
c文件中,我有export JAVA_HOME
,export HADOOP_HOME
,export PATH
和export HADOOP_CLASSPATH
。我已经尝试了WordCount和ProcessUnits,但是遇到了同样的问题。现在我认为代码没有问题,但是还有其他问题。
hadoop@hadoop:~/hadoop$ hadoop com.sun.tools.javac.Main hadoop/WordCount.java
Warning: $HADOOP_HOME is deprecated.
hadoop@hadoop:~/hadoop$ jar -cf units.jar hadoop/WordCount*.class
hadoop@hadoop:~/hadoop$ hadoop jar units.jar hadoop/WordCount input_dir output_dir
Warning: $HADOOP_HOME is deprecated.
17/03/06 02:41:48 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
17/03/06 02:41:48 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
17/03/06 02:41:49 INFO input.FileInputFormat: Total input paths to process : 1
17/03/06 02:41:49 INFO util.NativeCodeLoader: Loaded the native-hadoop library
17/03/06 02:41:49 WARN snappy.LoadSnappy: Snappy native library not loaded
17/03/06 02:41:52 INFO mapred.JobClient: Running job: job_201703052335_0001
17/03/06 02:41:53 INFO mapred.JobClient: map 0% reduce 0%
17/03/06 02:42:02 INFO mapred.JobClient: Task Id : attempt_201703052335_0001_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: hadoop.WordCount$Map
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:857)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:718)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.ClassNotFoundException: hadoop.WordCount$Map
at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:810)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:855)
... 8 more
17/03/06 02:42:02 WARN mapred.JobClient: Error reading task outputConnection refused (Connection refused)
17/03/06 02:42:02 WARN mapred.JobClient: Error reading task outputConnection refused (Connection refused)
17/03/06 02:42:07 INFO mapred.JobClient: Task Id : attempt_201703052335_0001_m_000000_1, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: hadoop.WordCount$Map
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:857)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:718)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.ClassNotFoundException: hadoop.WordCount$Map
at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:810)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:855)
... 8 more
17/03/06 02:42:07 WARN mapred.JobClient: Error reading task outputConnection refused (Connection refused)
17/03/06 02:42:07 WARN mapred.JobClient: Error reading task outputConnection refused (Connection refused)
17/03/06 02:42:12 INFO mapred.JobClient: Task Id : attempt_201703052335_0001_m_000000_2, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: hadoop.WordCount$Map
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:857)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:718)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.ClassNotFoundException: hadoop.WordCount$Map
at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:810)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:855)
... 8 more
17/03/06 02:42:12 WARN mapred.JobClient: Error reading task outputConnection refused (Connection refused)
17/03/06 02:42:12 WARN mapred.JobClient: Error reading task outputConnection refused (Connection refused)
17/03/06 02:42:19 INFO mapred.JobClient: Job complete: job_201703052335_0001
17/03/06 02:42:19 INFO mapred.JobClient: Counters: 7
17/03/06 02:42:19 INFO mapred.JobClient: Job Counters
17/03/06 02:42:19 INFO mapred.JobClient: SLOTS_MILLIS_MAPS=24389
17/03/06 02:42:19 INFO mapred.JobClient: Total time spent by all reduces waiting after reserving slots (ms)=0
17/03/06 02:42:19 INFO mapred.JobClient: Total time spent by all maps waiting after reserving slots (ms)=0
17/03/06 02:42:19 INFO mapred.JobClient: Launched map tasks=4
17/03/06 02:42:20 INFO mapred.JobClient: Data-local map tasks=4
17/03/06 02:42:20 INFO mapred.JobClient: SLOTS_MILLIS_REDUCES=0
17/03/06 02:42:20 INFO mapred.JobClient: Failed map tasks=1
字数
package org.myorg;
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
`
最佳答案
尝试添加conf.setJarByClass(WordCount.class);
它应该将您的jar文件添加到分布式缓存中。
关于hadoop - MapReduce代码无法在Hadoop集群中运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42614126/