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用于数 ...
随机推荐
- MergeKLists
public ListNode mergeKLists(ListNode[] lists) { if(lists==null||lists.length==0) return null; Priori ...
- stm32l071cbt6片内flash操作
今天在看片内flash的操作,发现按照下面的操作并没有写成功: unsigned long temp = 0x12345678; HAL_FLASH_Unlock(); FLASH_PageErase ...
- Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- 【BZOJ3240】【UOJ#124】【NOI2013】矩阵游戏
终于看懂一道题QAQ然而NOI都是这种难度题怎么玩QAQ 原题: 婷婷是个喜欢矩阵的小朋友,有一天她想用电脑生成一个巨大的n行m列的矩阵(你不用担心她如何存储).她生成的这个矩阵满足一个神奇的性质:若 ...
- whistle.js连接ios手机中https步骤
1:对于安卓直接扫码安装https的证书: 对于ios 连接电脑发出的wifi,打开whistle,配置代理之后(一定要保证先链接电脑发出的wifi,且配置代理) 用Safari打开网址:http: ...
- WCF- 契约Contract(ServiceContract、OperationContract、DataContract、ServiceKnownType和DataMember)(转)
示例 1.服务 IPersonManager.cs using System; using System.Collections.Generic; using System.Linq; using S ...
- mac sz rz file tras
安装Zmodem的实现 brew install lrzsz 下载 iterm2-send-zmodem.sh 和 iterm2-recv-zmodem.sh 到路径/usr/local/bin/ ...
- gtk_init()
#include<stdio.h> #if 0int main(int argc, char *argv[]){ char ***p = &argv; //传参退化成二级指针,对二 ...
- react-static 基于react 渐进式静态站点生成框架
react-static 是一个不错的基于react 开发的静态站点生成框架,可以用来替代create-react-app 包含的特性 100% react 很快的构建以及性能 自动代码以及数据分离 ...
- Be Careful When Using Bit Field
Below illustration is based on MSP430, IAR. See the implementation below. typedef struct { uint8_t g ...