Hadoop开发环境搭建(linux)

Hadoop开发环境搭建(linux)

零、安装xwindows

apt-get install ubuntu-desktop

一、安装Eclipse

下载Eclipse,解压安装,例如安装到/usr/local,即/usr/local/eclipse

二、在eclipse上安装hadoop插件

1、下载hadoop插件

下载地址:http://pan.baidu.com/s/1mgiHFok

此zip文件包含了源码,我们使用使用编译好的jar即可,解压后,release文件夹中的hadoop.eclipse-kepler-plugin-2.6.0.jar就是编译好的插件。

2、把插件放到eclipse/plugins目录下

3、重启eclipse,配置Hadoop installation directory

如果插件安装成功,打开Windows—Preferences后,在窗口左侧会有Hadoop Map/Reduce选项,点击此选项,在窗口右侧设置Hadoop安装路径。

4、配置Map/Reduce Locations

打开Windows—Open Perspective—Other

选择Map/Reduce,点击OK

在右下方看到如下图所示

点击Map/Reduce Location选项卡,点击右边小象图标,打开Hadoop Location配置窗口:

输入Location Name,任意名称即可.配置Map/Reduce Master和DFS Mastrer,Host和Port配置成与core-site.xml的设置一致即可。

点击"Finish"按钮,关闭窗口。

点击左侧的DFSLocations—>myhadoop(上一步配置的location name),如能看到user,表示安装成功

如果如下图所示表示安装失败,请检查Hadoop是否启动,以及eclipse配置是否正确。

三、新建WordCount项目

File—>Project,选择Map/Reduce Project,输入项目名称WordCount等。

在WordCount项目里新建class,名称为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);

}

}

四、运行

1、在HDFS上创建目录input

hadoop fs -mkdir input

2、拷贝本地README.txt到HDFS的input里

hadoop fs -copyFromLocal /usr/local/hadoop/README.txt input

3、运行

点击WordCount.java,右键,点击Run As—>Run Configurations,配置运行参数,即输入和输出文件夹

hdfs://localhost:9000/user/hadoop/input hdfs://localhost:9000/user/hadoop/output

点击Run按钮,运行程序。

4、运行完成后,查看运行结果

方法1:

hadoop fs -ls output

可以看到有两个输出结果,_SUCCESS和part-r-00000

执行hadoop fs -cat output/*

方法2:

展开DFS Locations,如下图所示,双击打开part-r00000查看结果

时间: 2024-08-25 18:26:55

Hadoop开发环境搭建(linux)的相关文章

Hadoop开发环境搭建 windows下Eclipse

Hadoop开发环境搭建 windows下Eclipse 下载Eclipse www.eclipse.org 解压. 下载Hadoop的Eclipse Plugin 将插件包放到eclipse的plugins目录下.重启eclipse. 下载hadoop的安装包 将下载的hadoop安装包,解压到任一目录,最好是英文且无空格目录. 配置eclipse Hadoop instllation directory:设置为hadoop安装包解压的目录. Window->open persperctive

hadoop开发环境搭建(1)

作为初学Hadoop的新手,搭建Hadoop开发环境花了我很大功夫.倒不是hadoop搭建复杂,由于hadoop本身是一个分布式.多jvm进程的运行环境,我们想达到能用eclipse进行代码跟踪调试目的,还真不是一般的费劲. 一边在网上向给位前辈学习,一边自己动手尝试,花了我整整一天的时间终于完成了,为了使自己好不太容易完成的成就,后续被轻易忘记,也为了帮助其他hadoop小白同类脱贫致富,花了一晚上总结了此篇博文,以兹鼓励. 一.准备篇 言归正传,首先是准备篇.这里我们需要准备不少东东: 1.

hadoop开发环境搭建

很早就听说hadoop,但项目中一直没怎么接触,今天终于下定决心,花了一天的时间,搭起了基本的开发环境,总结如下. 一.软件准备 jdk.hadoop软件包.eclipse软件包(linux版) 二.安装java 详见http://blog.csdn.net/tonytfjing/article/details/42167599 三.安装hadoop(单机伪分布式) 3.1创建hadoop用户 为hadoop创建一个专门的用户,具体如下: groupadd hadoopGroup //创建had

hadoop 开发环境搭建

一,安装java环境 添加java环境变量 vi /etc/profile # add by tank export JAVA_HOME=/data/soft/jdk/jdk1.7.0_71 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin 二,修改文件句柄数

Hadoop开发环境搭建(不定时更新)

参考链接 hadoop家族.strom.spark.Linux.flume等jar包.安装包汇总下载(持续更新) http://www.aboutyun.com/thread-8178-1-1.html Win7中使用Eclipse连接虚拟机中的Ubuntu中的Hadoop2.4经验总结 http://www.aboutyun.com/thread-7784-1-1.html

ubuntu下eclipse+erlang+mongodb开发环境搭建

ubuntu下eclipse+erlang+mongodb开发环境搭建 - Linux操作系统:Ubuntu_Centos_Debian - 红黑联盟 最近公司webGame项目中用到了Erlang+MongoDB,没办法项目需要那就学呗. 学这个东西最起码得有环境吧,今天搭建开发环境就顺便记录一下,依然在ubuntu下进行开发. 顺便说下,如果做开发,最好选择linux,因为很多环境在linux下搭建很方便.win下一般也会 有相应的发法搭建,但是经常会遇到一些莫名其妙的问题.因此建议做开发的

Hadoop那些事儿(二)---MapReduce开发环境搭建

上一篇文章介绍了在ubuntu系统中安装Hadoop的伪分布式环境,这篇文章主要为MapReduce开发环境的搭建流程. 1.HDFS伪分布式配置 使用MapReduce时,如果需要与HDFS建立连接,及使用HDFS中的文件,还需要做一些配置. 首先进入Hadoop的安装目录 cd /usr/local/hadoop/hadoop2 在HDFS中创建用户目录 ./bin/hdfs dfs -mkdir -p /user/hadoop 创建input目录,并将./etc/hadoop中的xml文件

(转)Hadoop Eclipse开发环境搭建

来源:http://www.cnblogs.com/justinzhang/p/4261851.html This document is from my evernote, when I was still at baidu, I have a complete hadoop development/Debug environment. But at that time, I was tired of writing blogs. It costs me two day’s spare tim

Hadoop Eclipse开发环境搭建

    This document is from my evernote, when I was still at baidu, I have a complete hadoop development/Debug environment. But at that time, I was tired of writing blogs. It costs me two day's spare time to recovery from where I was stoped. Hope the b