問題描述:
輸入兩個檔案:
第一個檔案內容:Hello World Bye World
第二個檔案內容:Hello Hadoop Goodbye Hadoop are ate
運行WordCount程式的輸出內容:卻是以上兩行!
Hello Hadoop Goodbye Hadoop are ate
Hello World Bye World
----------------------------------------------------------------------------------
WordCount程式應該沒問題,應為之前運行正常呢,今天忽然間運行不正常,感覺像Mapper,Reducer不作業了,真心不知道咋回事!
本想看看hadoop行程運行是否正常,可是進入hadoop的安裝目錄bin檔案夾后,它竟然說jps命令找不到!
控制臺列印的部分資訊是:
13/10/02 21:35:43 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
13/10/02 21:35:43 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/10/02 21:35:43 INFO input.FileInputFormat: Total input paths to process : 2
13/10/02 21:35:43 WARN snappy.LoadSnappy: Snappy native library not loaded
13/10/02 21:35:44 INFO mapred.JobClient: Running job: job_local255489033_0001
13/10/02 21:35:44 INFO mapred.LocalJobRunner: Waiting for map tasks
13/10/02 21:35:44 INFO mapred.LocalJobRunner: Starting task: attempt_local255489033_0001_m_000000_0
13/10/02 21:35:44 INFO util.ProcessTree: setsid exited with exit code 0
13/10/02 21:35:44 INFO mapred.Task: Using ResourceCalculatorPlugin : org.apache.hadoop.util.LinuxResourceCalculatorPlugin@58dad8b5
13/10/02 21:35:44 INFO mapred.MapTask: Processing split: hdfs://localhost:9000/user/test/input/2.txt:0+36
13/10/02 21:35:44 INFO mapred.MapTask: io.sort.mb = 100
13/10/02 21:35:45 INFO mapred.MapTask: data buffer = 79691776/99614720
13/10/02 21:35:45 INFO mapred.MapTask: record buffer = 262144/327680
uj5u.com熱心網友回復:
原始碼貼出來看看呢uj5u.com熱心網友回復:
package testpkg;
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;
import org.apache.hadoop.util.GenericOptionsParser;
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();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(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(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
uj5u.com熱心網友回復:
可以重啟下機器再試下uj5u.com熱心網友回復:
重啟了哇,也還是那樣,算了,我再重新配置一下試試吧~
uj5u.com熱心網友回復:
嗯,感覺是環境變數的問題。。。uj5u.com熱心網友回復:
jsp不好使?那是java環境的問題啊,/etc/profile配置是不是出問題了。還有hadop-env.sh也得設定javahome。uj5u.com熱心網友回復:
jps命令是在jdk的bin目錄中uj5u.com熱心網友回復:
jps是jdk里面用來查看java行程的命令。請將jar包重新打下,試試。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/112924.html
標籤:云存儲
上一篇:一個工位的強電一般多少?
