如何在Hortonworks沙箱Hadoop平台中运行mapreduce作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Hortonworks沙箱Hadoop平台中运行mapreduce作业相关的知识,希望对你有一定的参考价值。
我是Hadoop的新手。我已经在虚拟机中安装了oracle虚拟盒并安装了hortonworks沙箱的映像。此外,我已经在eclipse中编写了wordcount程序并尝试在虚拟机中运行它。但是我得到了一个异常树。我也发布程序和错误树。
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 IOException {
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);
}
}
[hue @ sandbox`] $ hadoop jar / usr / lib / wordcount.jar wordcount [-m] [ - r]
线程主java.lang.NoClassDefFoundError中的异常:jar / usr / lib / wordcount / jar
由java.net引起的java.lang.ClassNotFoundException:jar.usr.lib.wordcount.jar:java.net.URLClassLoader $ 1.run(URLlassLoader.java:202)java.net上的java.security.AccessController.doPriviledged(Native Method) .URLClassLoader.findClass(URLClassLoader.java:190)at java.lang.ClassLoader.loadClass(ClassLoader.java:306)at sun.misc.Launcher $ AppClassLoader.loadClass(Laucher.java:301)at java.lang.ClassLoader。的loadClass(ClassLoader.java:247)
找不到主类:jar / usr / lib / wordcount.jar
我在64位机器上使用Hortonworks + Sandbox + 1.3 + VirtualBox + RC6这个版本。
你没有正确调用hadoop,你错过了一个空间,还有args。尝试
hadoop jar /usr/lib/wordcount.jar WordCount <the path to your input file on HDFS> <the path to your output directory on HDFS>
如果您找不到另一个类,请尝试使用WordCount的完整类名(例如,com.mysite.WordCount)。我看不出它的包装。
以上是关于如何在Hortonworks沙箱Hadoop平台中运行mapreduce作业的主要内容,如果未能解决你的问题,请参考以下文章
如何在 hortonworks 沙箱上的 Ambari 中启用 HDFS 文件视图?
如何将文件从 ubuntu 桌面传输到 hortonworks 沙箱