Ubuntu 14.10 下Eclipse安装Hadoop插件
准备环境
1 安装好了Hadoop,之前安装了Hadoop 2.5.0,安装参考http://www.cnblogs.com/liuchangchun/p/4097286.html
2 安装Eclipse,这个直接在其官网下载即可
安装步骤
1 下载Eclipse插件,我找的是Hadoop 2.2 的插件,在Hadoop 2.5 下可以正常用,获取插件这里有两种方式
1.1 一是自己下载源码自己编译,过程如下
首先,下载eclipse-hadoop的插件,网址是https://github.com/winghc/hadoop2x-eclipse-plugin,你可以点击网页右下方的Download ZIP下载。下载之后,解压缩,。
然后,进入到 hadoop2x-eclipse-plugin-master/src/contrib/eclipse-plugin文件夹里面,执行命令
ant jar -Declipse.home=/usr/local/eclipse -Dhadoop.home=~/Downloads/hadoop-2.2.0 -Dversion=2.5.0
编译顺利通过,生成的插件在hadoop2x-eclipse-plugin-master/build/contrib/eclipse-plugin目录下。
1.2 或是直接下载编译好的插件,下载地址http://pan.baidu.com/s/1mgiHFok
将下载好的插件复制到eclipse/plugins目录下,需要重启Eclipse
3 配置Hadoop installation directory
3.1 如果插件安装成功,打开Windows—Preferences后,在窗口左侧会有Hadoop Map/Reduce选项,点击此选项,在窗口右侧设置Hadoop安装路径。
3.2 配置Map/Reduce Locations:打开Windows—Open Perspective—Other 选择Map/Reduce,点击OK
3.3 点击Map/Reduce Location选项卡,点击右边小象图标,打开Hadoop Location配置窗口:输入Location Name,任意名称即可.配置Map/Reduce Master和DFS Mastrer,Host和Port配置成与core- site.xml的设置一致即可。如果没有自己修改端口,那么一个是9001,一个是9000
3.4 点击左侧的DFSLocations—>Location Name(上一步配置的location name),如能看到Hadoop下的文件,那么表示安装成功。
4 测试MapReduce。Eclipse中,File—>Project,选择Map/Reduce Project,输入项目名称WordCount等。然后新建一个类,代码拷贝下
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);
}
}
5 运行项目,先需要做些准备工作
5.1、在HDFS上创建目录input
hadoop fs -mkdir input
5.2 、随便拷贝本地README.txt到HDFS的input里
hadoop fs -copyFromLocal /usr/local/hadoop/README.txt input
5.3、点击WordCount.java,右键,点击Run As—>Run Configurations,配置运行参数,即输入和输出文件夹
hdfs://localhost:9000/user/hadoop/input hdfs://localhost:9000/user/hadoop/output
5.4 注意,输入目录output不要在Hadoop中建立,否则会报错
6 查看结果,可以直接在DFS Locations刷新下就会看到多个目录,里面就有结果
----------------------------------------------------------------------------------------------------------------------------------------
WordCount程序上面是写在一个类里面,规范一点是Map类,Reduce类,MapRedcueDriver分开建立,低耦合
1 新建Map/Reduce工程wordcount。
2 新建Mapper.java,选择File——>New——>Mapper,输入包名及类名。
3 新建Reduccer.java,选择File——>New——>Reducer,输入包名及类名。
4 建立Map/Reduce Driver,选择File——>New——>MapReduce Driver,输入包名及类名。
5 运行,同上面
Ubuntu 14.10 下Eclipse安装Hadoop插件的更多相关文章
- Ubuntu 14.10 下DokuWiki安装
环境说明: Ubuntu 14.10 64位 1 下载DokuWiki:http://download.dokuwiki.org/ 2 解压到 /var/www/html下面 3 如果没有安装Apac ...
- Ubuntu 14.10 下Eclipse操作HBase
环境介绍 64位Ubuntu14.10,Hadoop 2.5.0 ,HBase 0.99.0 准备环境 1 安装Hadoop 2.5.0,可参考http://www.cnblogs.com/liuch ...
- Ubuntu 14.10 下Ganglia监控Hadoop集群
前提是已经安装好Ganglia和Hadoop集群 1 Master节点配置hadoop-metrics2.properties # syntax: [prefix].[source|sink|jmx] ...
- Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例
Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例 一.在Eclipse下编译安装Hadoop插件 Hadoop的Eclipse插件现在已经没有二进制版直接提供,只能自己编译. ...
- Ubuntu 14.04 下手动安装Firefox的Flash插件
有时候我们不得不採用手动安装一些软件. Ubuntu 14.04 下手动安装Firefox的Flash插件有下面几步 1. 下载Flash插件 下载地址为http://get.adobe.com/cn ...
- Ubuntu 14.10下基于Nginx搭建mp4/flv流媒体服务器(可随意拖动)并支持RTMP/HLS协议(含转码工具)
Ubuntu 14.10下基于Nginx搭建mp4/flv流媒体服务器(可随意拖动)并支持RTMP/HLS协议(含转码工具) 最近因为项目关系,收朋友之托,想制作秀场网站,但是因为之前一直没有涉及到这 ...
- 在 Ubuntu 14.10 Server 上安装 Jetty
Jetty提供了一个Web服务器和javax.servlet容器,为SPDY.WebSocket.OSGi.JMX.JNDI.JAAS以及许多其它集成套件添加了支持.这些组件都是开源的,也可用于商业用 ...
- windows下Eclipse安装Perl插件教程
windows下Eclipse安装Perl插件教程 想用eclipse编写perl.网上看了很多资料.但EPIC插件的下载连接都失效了.无奈,只好自己动手写个教程记录一下. 准备工作: 安装好Ecli ...
- Ubuntu 14.10 下安装Ganglia监控集群
关于 Ganglia 软件,Ganglia是一个跨平台可扩展的,高性能计算系统下的分布式监控系统,如集群和网格.它是基于分层设计,它使用广泛的技术,如XML数据代表,便携数据传输,RRDtool用于数 ...
随机推荐
- java-BigInteger类
1.BigInteger类的概述和方法使用 * A:BigInteger的概述 * 可以让超过Integer范围内的数据进行运算 * B:构造方法 * public BigInteger(String ...
- Kubernetes学习
DNS for Services and Pods Services 创建基本的Service kind: Service spec.clusterIP: 为一组相同的服务的Pod集群提供一个虚拟ip ...
- mysql插入操作跳过(ignore)、覆盖(replace into)、更新(on duplicate key)
原帖地址:http:.html .insert ignore into 当插入数据时,如出现错误时,如重复数据,将不返回错误,只以警告形式返回.所以使用ignore请确保语句本身没有问题,否则也会被忽 ...
- using python to compute production rules
#coding=utf8 import loggingimport itertoolsimport reimport sys logger = logging.getLogger()root_form ...
- JS 冒泡排序法 输出最大值
<html lang="en-US"> <head> <meta charset="UTF-8"> <title> ...
- 关于Spring IOC的学习和理解
面向对象——三层架构(表现层.业务层.持久层) 三层架构:即表现层.业务层.持久层. ① 持久层:采用DAO模式,建立实体类和数据库表映射(ORM映射).也就是哪个类对应哪个表,哪个属性对应哪个列.持 ...
- nginx unit 1.8 支持基于java servlet 的开发模型
最近unit 1.8 发布了,有两个比较大的新特性,内部请求路由,以及java servlet 容器应用的开发 内部请求路由配置参考 { "routes": [ { "m ...
- YII2常用知识点总结
YII2常用知识点总结 (一)总结性语句 (1)经常看看yii源码比如vendor\yiisoft\yii2\web这个目录(很重要)下的文件中的方法(这些文件中的公共方法,大致看了下基本上都可以通过 ...
- RTMP、RTSP、HTTP可用的地址
香港卫视: rtmp://live.hkstv.hk.lxdns.com/live/hks1 香港财经,rtmp://202.69.69.180:443/webcast/bshdlive-pc 韩国 ...
- gitlab不小心把sign-in取消了怎么恢复
环境和版本 [root@linux-node1 etc]# ll /var/cache/yum/x86_64/7/gitlab-ce/packages/ total 292928 -rw-r--r-- ...