Creating a Hadoop-2.x project in Eclipse

hortonworks:MapReduce Ports

http://docs.hortonworks.com/HDPDocuments/HDP1/HDP-1.2.0/bk_reference/content/reference_chap2_2.html

hadoop-1.x 集群默认配置和常用配置

http://www.cnblogs.com/ggjucheng/archive/2012/04/17/2454590.html

Eclipse下搭建Hadoop-2.x开发环境{good}

http://blog.csdn.net/twlkyao/article/details/17578541

Location name和Host填写localhost,

DFS Master填写HDFS的端口号必须和core-site.xml中的HDFS配置端口一致,这里填写9000,

Map/Reduce Master的端口号必须和Mapred-site.xml中的HDFS配置端口号一致(Hadoop2.x.0版本中没有配置,建议按照 Hadoop1.x配置),这里填写9001;

貌似这一端口号是9000累加的。

User name为Hadoop的所有者用户名,即安装Hadoop的Linux用户,这里为Hduser。

注意:hadoop 2.x 各种端口很复杂,也没有正式的文档。

这里是沿袭 hadoop 1.x的设置, 但幸运的是仍然可以工作。

=======================

 

December 7, 2013

Running Hadoop-1.2.1 MapReduce App from Eclipse Kepler

http://letsdobigdata.wordpress.com/2013/12/07/running-hadoop-mapreduce-application-from-eclipse-kepler/

===========================

Eclipse上运行hadoop应用总的来说有2种模式,
第一种就是Local模式,也叫本地模式,第二种就是我们正式的线上集群模式。

当运行Local模式的时候,程序并不会被提交到Hadoop集群上,而是基于单机的模式跑的,
但是单机的模式,运行的结果仍在是存储在HDFS上的,只不过没有利用hadoop集群的资源,
单机的模式不提交jar包到hadoop集群上,因此使用local来测试MR程序是否能够正常运行。

1.安装环境
   系统:centos6.4 x64
   hadoop版本:2.2.0
   eclipse版本:kepler

2. 下载eclipse hadoop2.2插件,hadoop2x-eclipse-plugin-master.zip,解压放到eclipse的plugin目录下,重启eclipse.

3. 配置hadoop installation directory。
  如果安装插件成功,打开Window-->Preferens,你会发现Hadoop Map/Reduce选项,
  在这个选项里你需要配置Hadoop installation  directory。配置完成后退出。

4.配置Map/Reduce Locations。 在Window-->open persperctive->other...,
  在MapReduce Tools中选择Map/Reduce Locations。

在Map/Reduce Locations(Eclipse界面的正下方)中新建一个Hadoop Location。在这个View中,点击鼠标右键-->New Hadoop Location。
   在弹出的对话框中你需要配置Location name,可任意填,如Hadoop,  
   DFS Master填写HDFS的端口号必须和core-site.xml中的HDFS配置端口一致,这里填写9000,
   Map/Reduce Master的端口号必须和Mapred-site.xml中的HDFS配置端口号一致(Hadoop2.x.0版本中没有配置,建议按照 Hadoop1.x配置),这里填写9001;
  貌似这一端口号是9000累加的。
  User name为Hadoop的所有者用户名,即安装Hadoop的Linux用户,这里为Hduser。

  注意:hadoop 2.x 各种端口很复杂,也没有正式的文档。

    这里是沿袭 hadoop 1.x的设置, 但幸运的是仍然可以工作

5.新建一个hadoop项目测试.
   新建项目:File-->New-->Other-->Map/Reduce Project 项目名可以随便取,如Test001。
   新建测试类,WordCountTest,代码如下:
  准备输入: HDFS下创建input目录,并把统计文本put到目录下面。

6.Run

选择run -》java application ,

检查输出:

如果执行成功刷新下hdfs的目录会出现 /output目录 结果就在part-r-00000文件

7.到此为止,只是利用Local模式运行并测试了hadoop  MR Application,并没有部署到实际集群上。

8.分布式运行:

Eclispe Hadoop插件支持导出可执行jar文件。

例如:本项目,在Eclipse中Export jar, 导出~/Test.jar, 然后提交到shell运行:

$ bin/hadoop jar  ~/Test.jar   TestPkg.WordCountTest

再例如 hadoop2.x自带的wordcount,提交到shell运行

$ bin/hadoop jar  hadoop-mapreduce-examples-2.3.0.jar  wordcount   /input   /output

Q:java.lang.IllegalArgumentException: Wrong FS:  hdfs:/ expected file:///

A:需要把集群上的core-site.xml和hdfs-site.xml放到Eclipse当前工程下的bin文件夹下面.

 package TestPkg;

 import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
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 WordCountTest { public static class TokenizerMapper extends
Mapper<Object, Text, Text, IntWritable> { /**
* LongWritable, IntWritable, Text Hadoop Java WritableComparable
* long,int,String
*/
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();// Text BinaryComparablekey /**
* Mappermap void map(K1 key, V1 value, OutputCollector<K2,V2> output,
* Reporter reporter) k/vk/v 0 OutputCollectorMapperReducer<k,v>
* OutputCollectorcollect(k, v):(k,v)output
*/ public void map(Object key, Text value, Context context)
throws IOException, InterruptedException { /**
*
* c++ java hello world java hello you me too mapmapkey 0 c++ java
* hello 16 world java hello 34 you me too
*/ /**
*
*
*
* c++ 1 java 1 hello 1 world 1 java 1 hello 1 you 1 me 1 too 1
* reduce
*/
StringTokenizer itr = new StringTokenizer(value.toString());//
System.out.println("value " + value.toString());
System.out.println("key " + key.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(); /**
* reduce (c++ [1]) (java [1,1]) (hello [1,1]) (world [1]) (you [1]) (me
* [1]) (you [1]) reduce
*
*/
public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
/**
* reduce
*
* c++ 1 hello 2 java 2 me 1 too 1 world 1 you 1
*
*/
for (IntWritable val : values) {
sum += val.get();
} result.set(sum);
context.write(key, result);
}
} public static void main(String[] args) throws Exception { args = new String[2];
args[0] = "hdfs://n0:9000/input";
args[1] = "hdfs://n0:9000/output"; System.out.println("========input,output=============");
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args)
.getRemainingArgs(); for (String s : otherArgs) {
System.out.println(s);
} // HDFS
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
} //check output dir: if exist,delete.
FileSystem fs=FileSystem.get(conf);
Path pout=new Path(otherArgs[1]);
if(fs.exists(pout)){
fs.delete(pout, true);
System.out.printf("output path [%s]exist,delete....\n",otherArgs[1]);
}
// // JobConf conf1 = new JobConf(WordCount.class);
Job job = new Job(conf, "Word Count Test"); job.setJarByClass(WordCountTest.class); job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); // key
job.setOutputValueClass(IntWritable.class);// value FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1);
} }

Creating a Hadoop-2.x project in Eclipse的更多相关文章

  1. Stanford: Creating a Hadoop-2.x project in Eclipse

    Creating a Hadoop-2.x project in Eclipse http://snap.stanford.edu/class/cs246-data-2014/hw0.pdf Hado ...

  2. Hadoop: Setup Maven project for MapReduce in 5mn

    Hadoop: Setup Maven project for MapReduce in 5mn 25 MAY 2013 / ANTOINE AMEND I am sure I am not the ...

  3. hadoop开发环境部署——通过eclipse远程连接hadoop2.7.3进行开发

    一.前言 环境: 系统:centos6.5 hadoop版本:Apache hadoop2.7.3(Windows和centos都是同一个) eclipse版本:4.2.0(juno版本,window ...

  4. How to import a GitHub project into Eclipse

    Assuming you have created a project in GitHub, these are the steps to import it into Eclipse. First, ...

  5. (转)把hadoop源码关联到eclipse工程

    把hadoop源码关联到eclipse工程     转:http://www.superwu.cn/2013/08/04/355 在eclipse中阅读源码非常方便,利于我们平时的学习,下面讲述如何把 ...

  6. 谁再把IDEA的Project比作Eclipse的Workspace,我就跟谁急

    前言 你好,我是A哥(YourBatman). 有一个观点:若一个Java开发者能把IDEA玩得666,则技术一定不会差:但若玩不转IDEA(如不会设置.定制.解决日常问题.快捷键等等),那大概率水平 ...

  7. 【Hadoop学习之五】win7+Eclipse+hadoop3搭建本机开发环境

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 拓扑: 知识准备: 1.eclip ...

  8. MyEclipse Web Project导入Eclipse Dynamic Web Project,无法部署到tomcat问 题

    做作业遇到一个小问题,将MyEclipse Web Project导入到Eclipse中开发.在部署到tomcat时,发现无法发布这个项目. 问题分析: MyEclipse Web Project被识 ...

  9. hadoop源码import到eclipse工程

    1.解压hadoop-1.1.2.tar.gz,重点在src文件夹 2.在eclipse中通过菜单栏创建一个java工程,工程名随便 3.在创建的工程上,点击右键,在弹出菜单中选择最后一项,在弹出窗口 ...

随机推荐

  1. IDEA新建一个Project和Module的问题

  2. P3833 [SHOI2012]魔法树

    思路 树剖板子 注意给出点的编号是从零开始的 代码 #include <cstdio> #include <algorithm> #include <cstring> ...

  3. Tag Helpers in forms in ASP.NET Core

    Tag Helpers in ASP.NET Core Tag Helpers in forms in ASP.NET Core HTML Form element ASP.NET Core buil ...

  4. Java中String型与Date型数据的互相转换

    /** * Date类型转为指定格式的String类型 * * @param source * @param pattern * @return */ public static String Dat ...

  5. HTML学习笔记CSS

    类选择器和ID选择器的区别 1id只能用一回,类可以循环使用 2可以使用类选择器词列表方法为一个元素同时设置多个样式.我们可以为一个元素同时设多个样式,但只可以用类选择器的方法实现,ID选择器是不可以 ...

  6. 转一个集成速锐的ss 回头试试 补充加速一、Vultr安装锐速

    https://liyuans.com/archives/ssr-serverspeeder-onekey.html Debian/Ubuntu 系统 ShadowsocksR 一键安装脚本 (集成锐 ...

  7. python 比较两个yaml文件

    import yaml with open("a.yaml") as f: with open("a.yaml") as k: ): x=f.readline( ...

  8. Pycharm设置去除显示的波浪线

    1.选择文件选择file—Settings,如下图打开setting对话框 2.选择Editur—Color Scheme—General选项,然后选择右边对话框中的Errors and Warnin ...

  9. STL——set

    (转) 1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用 ...

  10. Scrapy基本命令

    全局命令,不用在项目中运行fetch:爬取网页,不依赖爬虫项目直接爬网页信息,并显示爬取过程scrapy命令格式:scrapy 命令名 --参数,可能通过--控制,例如:scrapy fetch -h ...