2015-3-27

参考:

http://www.cnblogs.com/baixl/p/4154429.html

http://blog.csdn.net/u010911997/article/details/44099165

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

hadoop在虚拟机上(远程连接也是一样只需要知道master的ip和core-site.xml配置即可。

Vmware上搭建了hadoop分布式平台:

192.168.47.133 master

192.168.47.134 slave1

192.168.47.135 slave2

core-site.xml 配置文件:

<property>
  <name>fs.defaultFS</name>
  <value>hdfs://master:9000</value>
  <description>The name of the default file system.</description>
</property>

1 下载插件

hadoop-eclipse-plugin-2.6.0.jar

github上下载源码后需要自己编译。这里使用已经编译好的插件即可

2 配置插件

把插件放到..\eclipse\plugins目录下,重启eclipse,配置Hadoop installation directory   ,

如果插件安装成功,打开Windows—Preferences后,在窗口左侧会有Hadoop Map/Reduce选项,点击此选项,在窗口右侧设置Hadoop安装路径。(windows下只需把hadoop-2.5.1.tar.gz解压到指定目录)

3 配置Map/Reduce Locations

打开Windows—Open Perspective—Other,选择Map/Reduce,点击OK,控制台会出现:

右键 new Hadoop location 配置hadoop:输入

Location Name,任意名称即可.

配置Map/Reduce Master和DFS Mastrer,Host和Port配置成与core-site.xml的设置一致即可。

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

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

4 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 extendsMapper<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) throwsIOException,InterruptedException{

StringTokenizer itr=new StringTokenizer(value.toString());

while (itr.hasMoreTokens()) {

word.set(itr.nextToken());

context.write(word, one);

}

}

}

public static class IntSumReducer extendsReducer<Text,IntWritable,Text,IntWritable> {

private IntWritable result = new IntWritable();

public void reduce(Text key, Iterable<IntWritable> values,Contextcontext) 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 = 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, newPath("hdfs://192.168.11.134:9000/in/test*.txt"));//路径1

FileOutputFormat.setOutputPath(job, newPath("hdfs://192.168.11.134:9000/output"));//输出路径

System.exit(job.waitForCompletion(true) ? 0 : 1);

}

}

上面的路径1 和路径2 由于在代码中已经定义,这不需要在配置文件中定义,若上面路径1和路径2 代码为:

FileInputFormat.addInputPath(job, new Path(otherArgs[0]));

FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));

这需要配置运行路径:类 右键 Run As—>Run Configurations

红色部分为配置的hdfs上文件路径,

点击run 或或者:Run on Hadoop,运行结果会显示在DFS Locations。若运行中有更新,右键DFS Locations,点disconnect更新

运行结果:

5 问题及解决办法

5.1 出现 空指针异常:

1 在Hadoop的bin目录下放winutils.exe,

2 在环境变量中配置 HADOOP_HOME,

3 hadoop.dll拷贝到C:\Windows\System32下面即可

下载地址:

http://mail-archives.apache.org/mod_mbox/incubator-slider-commits/201411.mbox/%3Ce263738846864bfda0dd6c17a7457988@git.apache.org%3E

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/29483696/bin/windows/hadoop-2.6.0-SNAPSHOT/bin/winutils.exe
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/29483696/bin/windows/hadoop-2.6.0-SNAPSHOT/bin/hadoop.dll

问题1:在DFS Lcation 上不能多文件进行操作:

在hadoop上的每个节点上修改该文件       conf/mapred-site.xml

增加:

<property>

<name>dfs.permissions</name>

<value>false</value>

</property>

关闭权限验证

问题2

log4j:WARN No appenders could be foundfor logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).

log4j:WARN Please initialize the log4jsystem properly.

log4j:WARN Seehttp://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

在src文件夹下创建以log4j.properties命名的文件

文件内容如下

log4j.rootLogger=WARN, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d%p [%c] - %m%n

问题3

java.io.IOException: Could not locateexecutable null/bin/winutils.exe in the Hadoop binaries.

缺少winutils.exe 下载一个添加进去就行

下载地址 http://download.csdn.net/detail/u010911997/8478049

问题4

Exceptionin thread "main" java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjava/lang/String;JZ)V

这是由于hadoop.dll 版本问题,2.4之前的和自后的需要的不一样

需要选择正确的版本并且在 Hadoop/bin和 C:\windows\system32 上将其替换

问题5

Exception in thread "main"java.lang.UnsatisfiedLinkError:org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

atorg.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Native Method)

at org.apache.hadoop.io.nativeio.NativeIO$Windows.access(NativeIO.java:557)

目前未找到解决方法,只能修改源代码

源代码下载  http://pan.baidu.com/s/1jGJzVSy

将源代码放入 工程的src目录下并创建同样的包名,然后修改源代码

源代码 未修改前

publicstaticbooleanaccess(String path, AccessRight desiredAccess)

throws IOException {

return access0(path,desiredAccess.accessRight());

}

源代码 修改后

public staticbooleanaccess(String path, AccessRight desiredAccess)

throws IOException {

        return ture;

//       return access0(path,desiredAccess.accessRight());

}

修改后编译成功,但是看不到软件运行时候的信息反馈

Windows下Eclipse连接hadoop的更多相关文章

  1. [原创] Windows下Eclipse连接hadoop

    1 下载hadoop-eclipse-plugin :我用的是hadoop-eclipse-plugin1.2.1 ,百度自行下载 2 配置插件:将下载的插件解压,把插件放到..\eclipse\pl ...

  2. 解决windows下Eclipse连接远程Hadoop报错

    Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.N ...

  3. windows下eclipse连接ubuntu伪分布式hadoop2.6.0

    环境: win10 jdk1.7 hadoop2.6.0 linux虚拟机 Ubuntu14.04 首先把安装在Ubuntu上的hadoop2.6.0.tar.gz复制到windows系统上,解压到任 ...

  4. windows下eclipse远程连接hadoop集群开发mapreduce

    转载请注明出处,谢谢 2017-10-22 17:14:09  之前都是用python开发maprduce程序的,今天试了在windows下通过eclipse java开发,在开发前先搭建开发环境.在 ...

  5. windows下eclipse+hadoop2

    windows下eclipse+hadoop2.4开发手册 1.解压下载的hadoop2.4,到任意盘符,例如D:\hadoop-2.4.0. 2.设置环境变量 ①新建系统变量,如下所示. ②将新建的 ...

  6. Windows下搭建Spark+Hadoop开发环境

    Windows下搭建Spark+Hadoop开发环境需要一些工具支持. 只需要确保您的电脑已装好Java环境,那么就可以开始了. 一. 准备工作 1. 下载Hadoop2.7.1版本(写Spark和H ...

  7. windows下Eclipse安装Perl插件教程

    windows下Eclipse安装Perl插件教程 想用eclipse编写perl.网上看了很多资料.但EPIC插件的下载连接都失效了.无奈,只好自己动手写个教程记录一下. 准备工作: 安装好Ecli ...

  8. windows下Eclipse操作MapReduce例子报错:Failed to set permissions of path: \tmp\hadoop-Jerome\mapred\staging\

    windows下Eclipse操作MapReduce例子报错: 14/05/18 22:05:29 WARN util.NativeCodeLoader: Unable to load native- ...

  9. [b0007] windows 下 eclipse 开发 hdfs程序样例

    目的: 学习使用hdfs 的java命令操作 相关: 进化: [b0010] windows 下 eclipse 开发 hdfs程序样例 (二) [b0011] windows 下 eclipse 开 ...

随机推荐

  1. NLP 自然语言处理

    参考: 自然语言处理怎么最快入门:http://www.zhihu.com/question/ 自然语言处理简介:http://wenku.baidu.com/link?url=W6Mw1f-XN8s ...

  2. VirtualMachine所支持的操作

    在JDK中com.sun.tools.attach.VirtualMachine提供了一些从外部进程attach到jvm上,并执行一些操作的功能.VirtualMachine的子类HotSpotVir ...

  3. Construct a tree from Inorder and Level order traversals

    Given inorder and level-order traversals of a Binary Tree, construct the Binary Tree. Following is a ...

  4. Python CRC16校验算法

    def crc16(x, invert): a = 0xFFFF b = 0xA001 for byte in x: a ^= ord(byte) for i in range(8): last = ...

  5. iOS 数组内中英文混合排序

    NSInteger sortObjects(id obj1, id obj2,void *context) { NSMutableString * str1 = [[NSMutableString a ...

  6. Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

    /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode ri ...

  7. Apache Benchmark测试工具

    ab命令-- ab -c 数字(连接数) -t 数字(连接时间) http://网站:端口/路径 ab -n 数字(点击数) -c 数字(连接数) -k(同时点击) http://网站:端口/路径

  8. LuaXMLRPC笔记

    XMLRPC XMLRPC 为以http为传输协议,使用xml格式化数据来执行远程过程调用, 区别于本地过程调用, 即发生在不同主机之间. 属于分布式计算的一种简单实现,比web service简单易 ...

  9. LUA 函数式编程demo

    什么是函数式编程 http://www.zhihu.com/topic/19585411/hot 函数式编程的本质函数式编程中的函数这个术语不是指计算机中的函数(实际上是Subroutine),而是指 ...

  10. oracle重建控制文件

    根据已有数据库创建新的控制文件#数据库必须是mounted或open状态 sql> alter database backup controlfile to trace; 可以使用以下快捷方式找 ...