安装Hadoop系列 — 新建MapReduce项目
1、新建MR工程


依次点击 File → New → Ohter… 选择Mapper,自动继承Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>



package com.mrdemo; 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);
}
//conf.set("fs.defaultFS", "hdfs://192.168.6.77:9000");
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);
}
}
hello hadoop
jobtracker
maptracker
reducetracker
task
namenode
datanode
block
beautiful world
hadoop:
HDFS
MapReduce
hdfs://localhost:9000/user/yyq/output01
Run As → Run Configurations… ,在Arguments中配置运行参数,例如程序的输入参数:

Run As -> Run on Hadoop ,执行完成后可以看到如下信息:
安装Hadoop系列 — 新建MapReduce项目的更多相关文章
- hadoop系列三:mapreduce的使用(一)
转载请在页首明显处注明作者与出处 http://www.cnblogs.com/zhuxiaojie/p/7224772.html 一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据的 ...
- hadoop系列四:mapreduce的使用(二)
转载请在页首明显处注明作者与出处 一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据的一些内容,如hadoop,spark,storm,机器学习等. 当前使用的hadoop版本为2.6 ...
- 安装Hadoop系列 — 导入Hadoop源码项目
将Hadoop源码导入Eclipse有个最大好处就是通过 "ctrl + shift + r" 可以快速打开Hadoop源码文件. 第一步:在Eclipse新建一个Java项目,h ...
- 安装Hadoop系列 — 安装Hadoop
安装步骤如下: 1)下载hadoop:hadoop-1.0.3 http://archive.apache.org/dist/hadoop/core/hadoop-1.0.3/ 2)解压文 ...
- 安装Hadoop系列 — 安装JDK-8u5
安装步骤如下: 1)下载 JDK 8 从http://www.oracle.com/technetwork/java/javasebusiness/downloads/ 选择下载JDK的最新版本 JD ...
- 安装Hadoop系列 — eclipse plugin插件编译安装配置
[一].环境参数 eclipse-java-kepler-SR2-linux-gtk-x86_64.tar.gz //现在改为eclipse-jee-kepler-SR2-linux-gtk-x86_ ...
- 新建MapReduce项目
添加各种jar包 /usr/local/hadoop/share/hadoop/.. 这几个文件夹下的jar包以及它们子目录lib下的所有jar包 将/usr/local/hadoop/etc/had ...
- 安装Hadoop系列 — 安装Eclipse
1.下载 Eclipse从 http://www.eclipse.org/downloads/index-developer.php下载合适版本,如:Eclipse IDE for C/C++ Dev ...
- 安装Hadoop系列 — 安装SSH免密码登录
配置ssh免密码登录 1) 验证是否安装ssh:ssh -version显示如下的话则成功安装了OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 ...
随机推荐
- Linux 下面对物理地址的访问
参考链接:http://zhuhaibobb.blog.163.com/blog/static/2744006720101049030606/ Linux内核提供了/dev/mem驱动,提供了一种直接 ...
- lex&yacc5--YYSTYPE
yacc里的YYSTYPE默认是int型的,当然也可以勇%union来定义联合但是由于程序需要,我要将YYSTYPE定义为我自己定义的一个struct的指针然后作为一个全局变量,让lex在扫描的时候, ...
- [java学习笔记]java语言核心----面向对象之构造函数
1.构造函数概念 特点: 函数名与类名相同 不用定义返回值类型 没有具体的返回值 作用: 给对象进行初始化 注意: 默认构造函数 多个构造函数是以重载出现的 一个类中如果 ...
- HTTP 错误 404.2 解决方案
HTTP 错误 404.2 - Not Found 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面 详细错误:HTTP 错误 404.2 - Not Found ...
- 【Qt】数据库连接池
请查看公孙二狗的文章 数据库连接池
- Winform程序只允许运行一个程序实例
/// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Main() { Application ...
- Iso8601 日期格式
unit Iso8601Unit; interface type TIso8601 = class(TObject) public class function DateTimeFromIso8601 ...
- Linux进程间通信IPC学习笔记之同步一(线程、互斥锁和条件变量)
基础知识: 测试代码: 参考资料: Posix 多线程程序设计
- PID控制器的数字实现及C语法讲解
PID控制器的数字实现及C语法讲解 概述 为方便学习与交流,根据自己的理解与经验写了这份教程,有错误之处请各位读者予以指出,具体包含以下三部分内容: (1) PID数字化的推导过程(实质:微积分的近 ...
- ASP.NET 页面传值得9种方式
1. Get(即使用QueryString显式传递) 方式:在url后面跟参数. 特点:简单.方便. 缺点:字符串长度最长为255个字符:数据泄漏在url中. 适用数据 ...