阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Hadoop2.6.0的Eclipse插件编译和设置

108次阅读
没有评论

共计 3543 个字符,预计需要花费 9 分钟才能阅读完成。

编译 Hadoop2.6.0 的 eclipse 插件

下载源码:

git clone https://github.com/winghc/hadoop2x-eclipse-plugin.git

编译源码:

src/contrib/eclipse-plugin
ant jar -Dversion=2.6.0 -Declipse.home=/usr/local/eclipse -Dhadoop.home=/usr/local/hadoop-2.6.0  // 需要手动安装的 eclipse,通过命令行一键安装的不行

eclipse.home 和 hadoop.home 设置成你自己的环境路径

生成位置:

 [jar] Building jar: /home/hunter/hadoop2x-eclipse-plugin/build/contrib/eclipse-plugin/hadoop-eclipse-plugin-2.6.0.jar

安装插件

登录桌面后面要打开 eclipse 的用户最好是 hadoop 的管理员,也就是 hadoop 安装时设置的那个用户,否则会出现拒绝读写权限问题。

复制编译好的 jar 到 eclipse 插件目录,重启 eclipse

配置 hadoop 安装目录

window ->preference -> hadoop Map/Reduce -> Hadoop installation directory

配置 Map/Reduce 视图

window ->Open Perspective -> other->Map/Reduce -> 点击“OK”

windows → show view → other->Map/Reduce Locations-> 点击“OK”

控制台会多出一个“Map/Reduce Locations”的 Tab 页

在“Map/Reduce Locations”Tab 页 点击图标 < 大象 +> 或者在空白的地方右键,选择“New Hadoop location…”,弹出对话框“New hadoop location…”,配置如下内容:将 ha1 改为自己的 hadoop 用户

Hadoop2.6.0 的 Eclipse 插件编译和设置

注意:MR Master 和 DFS Master 配置必须和 mapred-site.xml 和 core-site.xml 等配置文件一致

打开 Project Explorer, 查看 HDFS 文件系统。

新建 Map/Reduce 任务

File->New->project->Map/Reduce Project->Next

编写 WordCount 类:记得先把服务都起来

import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();

public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
 String line = value.toString();
 StringTokenizer tokenizer = new StringTokenizer(line);
 while (tokenizer.hasMoreTokens()) {
  word.set(tokenizer.nextToken());
  output.collect(word, one);
 }
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
 int sum = 0;
 while (values.hasNext()) {
  sum += values.next().get();
 }
 output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName(“wordcount”);

conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);

conf.setMapperClass(Map.class);
conf.setReducerClass(Reduce.class);

conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);

FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));

JobClient.runJob(conf);
}
}

配置运行时参数: 右键 –>Run as–>Run Confiugrations

Hadoop2.6.0 的 Eclipse 插件编译和设置

user/ha1/input/hadoop 是你上传在 hdfs 的文件夹(自己创建),里面放要处理的文件。ouput4 放输出结果

将程序放在 hadoop 集群上运行:右键 –>Runas –>Run on Hadoop, 最终的输出结果会在 HDFS 相应的文件夹下显示。至此,Ubuntu 下 hadoop-2.6.0 eclipse 插件配置完成。

配置过程中出先的问题:

在 eclipse 中无法向文件 HDFS 文件系统写入的问题,这将直接导致 eclipse 下编写的程序不能在 hadoop 上运行。

打开 conf/hdfs-site.xml,找到 dfs.permissions 属性修改为 false(默认为 true)OK 了。

<property>

<name>dfs.permissions</name>

<value>false</value>

</property>

改完需要重启 HDFS;

最简单的就是刚才说的登录桌面启动 eclipse 的用户本身就是 hadoop 的管理员

CentOS 安装和配置 Hadoop2.2.0  http://www.linuxidc.com/Linux/2014-01/94685.htm

Ubuntu 13.04 上搭建 Hadoop 环境 http://www.linuxidc.com/Linux/2013-06/86106.htm

Ubuntu 12.10 +Hadoop 1.2.1 版本集群配置 http://www.linuxidc.com/Linux/2013-09/90600.htm

Ubuntu 上搭建 Hadoop 环境(单机模式 + 伪分布模式)http://www.linuxidc.com/Linux/2013-01/77681.htm

Ubuntu 下 Hadoop 环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm

单机版搭建 Hadoop 环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm

搭建 Hadoop 环境(在 Winodws 环境下用虚拟机虚拟两个 Ubuntu 系统进行搭建)http://www.linuxidc.com/Linux/2011-12/48894.htm

更多 Hadoop 相关信息见 Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计3543字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中