hadoop 编写mapreduce测试流程
来源:互联网 发布:java web入门教程 编辑:程序博客网 时间:2024/05/21 22:47
1.在hadoop安装目录下 启动 namenodedatanoderesourcemanagernodemanager
$ sbin/hadoop-daemon.sh start namenode
$ sbin/hadoop-daemon.sh start datanode
$ sbin/yarn-daemon.sh start resourcemanager
$ sbin/yarn-daemon.sh start nodemanager
查看启动状态 $jps
2.编写map reduce程序
mkdir userapp
vim WordCount.java
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);
3 编译map reduce程序
root@ubuntu:/usr/local/userapp# javac -classpath /usr/local/hadoop/share/hadoop/common/hadoop-common-2.6.0.jar:/usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.0.jar -d ./ WordCount.java
4 打包jar
root@ubuntu:/usr/local/userapp# jar -cvf /usr/local/wordcount.jar -C userapp/ .
5上传测试数据
bin/hadoop dfs -pu /usr/local/test.txt /user/root/input/
6运行程序
root@ubuntu:/usr/local/userapp# bin/hadoop jar /usr/local/wordcount.jar org.myorg.WordCount /user/root/input output
7查看运行结果
bin/hadoop dfs -cat /user/root/output/*
- hadoop 编写mapreduce测试流程
- Hadoop MapReduce 编写例子
- hadoop mapreduce wordcount编写
- hadoop mapreduce执行流程
- hadoop mapreduce执行流程
- Hadoop MapReduce 技术流程
- Python编写Hadoop MapReduce程序
- Hadoop MapReduce WordCount程序编写
- 编写运行hadoop mapreduce程序
- Hadoop MapReduce执行流程详解
- Hadoop--MapReduce运行处理流程
- hadoop--之mapreduce框架流程
- Hadoop MapReduce工作详细流程
- hadoop安装测试流程
- 如何在Hadoop上编写MapReduce程序
- 如何在Hadoop上编写MapReduce程序
- 如何在Hadoop上编写MapReduce程序
- 在Hadoop中使用Streaming编写MapReduce
- 字符编码
- C语言实验——打印菱形
- Part 54 - T4 templates in asp.net mvc
- 物料帐发生业务之后再激活成本组件分割的处理方法
- Google浏览器 js调试
- hadoop 编写mapreduce测试流程
- jQuery - AJAX 简介
- 配置构建变体
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
- 感谢CSDN客服~
- EasyDarwin开源摄像机访问EasyCamera中海康摄像头语音对讲和云台控制转发实现
- jQuery笔记--事件篇
- Android 自定义通知Notification 适配不同背景颜色
- Android软件架构之RadioGroup + Fragment , TabLayout + ViewPager +Fragment 覆盖市场大部分商业软件架构