Windows上Eclipse远程调用Hadoop2.6.0
来源:互联网 发布:c语言100以内的素数 编辑:程序博客网 时间:2024/05/18 21:10
接着上一章节继续实践
一:下载eclipse,并解压安装(就不再多说了)我这里装在F:\eclipse-4.5.1二:下载 Hadoop2.6.0 包到本Windows上,并解压到F盘(这里你自己指定位置)
我这里装在F:\apache-hadoop-2.6.0三:下载插件:hadoop-eclipse-plugin-2.6.0.jar,并安装到eclipse中
1、目前这个插件还在开发中,你可以自己下载源码编译,网上也有人发布编译好的jar。源码地址: https://github.com/winghc/hadoop2x-eclipse-plugin
2、把下载好的jar,复制到 F:\eclipse\plugins\ 目录下,然后重启eclipse
四:在Eclipse中配置,测试DFS访问远程hadoop集群目录
1、指定Windows上的hadoop根目录(即:$HADOOP_HOME)windows --> preferences--> hadoop map/reduce
2、打开eclipse窗口,切换到map/reduce视图
windows --> show view --> other
3、添加一个map/reduce Location,并配置信息
4、点击Finish配置完成
5. 此时刷新一下DFS,既可以看到你远程hadoop集群上的文件夹了
五:创建HelloWord项目
File --> New--> Other --> MAP/Reduce Project --> Next
输入项目名称,检查没问题,就下一步下一步,完成ok。创建完成后会自动引用很多hadoop需要用到的jar,这里不用去管他。
接着创建WordCount程序:
package com.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();Job job = Job.getInstance(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(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));System.exit(job.waitForCompletion(true) ? 0 : 1);}}
右键-->Run As-->Run Configurations,配置好信息以后,点击运行
查看结果:
七:可能遇到的错误分析:
1、在DFS Lcation 上不能远程访问文件及操作:
这里报错,说没有权限的问题。你需要把hadoop集群中master机子上的hdfs-site.xml文件中添加:
<property><name>dfs.permissions</name><value>false</value></property>2、log4j问题(这个问题最好处理一下,不然hadoop的有一些错误信息打印不出来)
只需在src文件下创建log4j.properties文件
3、Exception in thread "main" org.apache.hadoop.mapred.InvalidJobConfException: Output directory not set.
说明你的输出目录重复,先删除,再运行。
3、java.io.IOException: Could not locateexecutable null/bin/winutils.exe in the Hadoop binaries.
这个问题是因为hadoop2.6.0在Windows上运行时却少几个文件,需要自己添加一下。
3.1、首先下载hadoop-native-64-2.6.0.tar,解压以后把里面的所有文件拷贝到F:\apache-hadoop-2.6.0\hadoop-2.6.0\bin(你的hadoop目录)
3.2、在把hadoop.dll文件拷贝到C:\Windows\System32目录下
3.3、配置hadoop的环境变量,新建HADOOP_PATH=F:\apache-hadoop-2.6.0\hadoop-2.6.0 然后在Path的最前面添加%HADOOP_HOME%\bin; ,保存退出。修改环境变量需重启电脑才能生效,也可不重启,但需在代码中插入一行,即
public static void main(String[] args) throws Exception {System.setProperty("hadoop.home.dir", "F:/apache-hadoop-2.6.0/hadoop-2.6.0");Configuration conf = new Configuration();Job job = Job.getInstance(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(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));System.exit(job.waitForCompletion(true) ? 0 : 1);}
鄙人才疏学浅,若有错误之处,还望指点!
0 0
- Windows上Eclipse远程调用Hadoop2.6.0
- windows eclipse远程连接hadoop2.6
- 搭建(win7)eclipse远程操作(Linux上)hadoop2.6.0_出错集
- 搭建(win7)eclipse远程操作(Linux上)hadoop2.6.0_出错集
- 搭建(win7)eclipse远程操作(Linux上)hadoop2.6.0_出错集
- 搭建(win7)eclipse远程操作(Linux上)hadoop2.6.0_出错集
- 搭建(win7)eclipse远程操作(Linux上)hadoop2.6.0_出错集
- windows Eclipse远程连接linux hadoop2.3.0伪分布式
- windows下eclipse远程调试hadoop2.7.2,debug mapreduce
- 在windows上eclipse安装hadoop2.7插件
- hadoop2.x入门:在windows上用Eclipse编写程序
- eclipse远程调试hadoop2.6
- windows 8.0上eclipse 4.4.0 配置centos 6.5 上的hadoop2.2.0开发环境
- 在eclipse下远程调试hadoop2.0
- Windows下使用Hadoop2.6.0-eclipse-plugin插件
- Hadoop II Windows下安装hadoop2.6.0-eclipse-plugin插件
- Windows下使用Hadoop2.6.0-eclipse-plugin插件
- Windows下使用Hadoop2.6.0-eclipse-plugin插件
- 安卓学习之获取QQ登录账户和密码并发送短信
- 写了一个将数据分片的工具,还请大神指正问题(目前只支持list,没搞太复杂)
- T-TPOJ3083
- poj1426
- 通用型 控制层接受参数方法
- Windows上Eclipse远程调用Hadoop2.6.0
- 杭电1392-凸包
- 字符串输入处理
- 扒扒数据库长长知识(下载资源组合看)之05 (多行函数_分组数据_分组过滤)
- [ShareSDK] QuickIntegrater.jar文件各种打不开
- POJ2299 分治法
- Android 开发过程中总计的一些经验教z
- 大话设计模式-简单工厂模式
- 泛型的简单理解