eclipse上hadoop插件的安装和配置

编译hadoop2.6.0的eclipse插件

下载源码:

git clone https://github.com/winghc/hadoop2x-eclipse-plugin.git
编译源码:
  1. cd src/contrib/eclipse-plugin  
  2. ant jar -Dversion=2.6.0 -Declipse.home=/usr/local/eclipse -Dhadoop.home=/usr/local/hadoop-2.6.0  //需要手动安装的eclipse,通过命令行一键安装的不行  
eclipse.home 和 hadoop.home 设置成你自己的环境路径

生成位置:

  1. [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用户


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

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

  • 新建Map/Reduce任务

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

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

  1. import java.io.IOException;  
  2. import java.util.*;  
  3. import org.apache.hadoop.fs.Path;  
  4. import org.apache.hadoop.conf.*;  
  5. import org.apache.hadoop.io.*;  
  6. import org.apache.hadoop.mapred.*;  
  7. import org.apache.hadoop.util.*;  
  8. public class WordCount {  
  9. public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {  
  10. private final static IntWritable one = new IntWritable(1);  
  11. private Text word = new Text();  
  12.   
  13. public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {  
  14.  String line = value.toString();  
  15.  StringTokenizer tokenizer = new StringTokenizer(line);  
  16.  while (tokenizer.hasMoreTokens()) {  
  17.    word.set(tokenizer.nextToken());  
  18.    output.collect(word, one);  
  19.  }  
  20. }  
  21. }  
  22. public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {  
  23. public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {  
  24.  int sum = 0;  
  25.  while (values.hasNext()) {  
  26.    sum += values.next().get();  
  27.  }  
  28.  output.collect(key, new IntWritable(sum));  
  29. }  
  30. }  
  31. public static void main(String[] args) throws Exception {  
  32. JobConf conf = new JobConf(WordCount.class);  
  33. conf.setJobName("wordcount");  
  34.   
  35. conf.setOutputKeyClass(Text.class);  
  36. conf.setOutputValueClass(IntWritable.class);  
  37.   
  38. conf.setMapperClass(Map.class);  
  39. conf.setReducerClass(Reduce.class);  
  40.   
  41. conf.setInputFormat(TextInputFormat.class);  
  42. conf.setOutputFormat(TextOutputFormat.class);  
  43.   
  44. FileInputFormat.setInputPaths(conf, new Path(args[0]));  
  45. FileOutputFormat.setOutputPath(conf, new Path(args[1]));  
  46.   
  47. JobClient.runJob(conf);  
  48. }  
  49. }  
配置运行时参数:右键-->Run as-->Run Confiugrations

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的管理员




转载至:http://blog.csdn.net/ggz631047367/article/details/42497557

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值