Mac上的第一个hadoop小demo

来源:互联网 发布:人工智能的研究内容 编辑:程序博客网 时间:2024/06/05 01:05

环境: mac eclipse hadoop2.6.0
1. 安装eclipse
2. 下载插件 hadoop-2.4.1-plugin.jar 放在eclipse/plugins目录下
3. 重启eclipse,配置Hadoop installation directory 偏好设置
这里写图片描述

4.配置 Map/Reduce Locations
Windows—show view—Other——OK
这里写图片描述
输入Location Name,任意名称即可.配置Map/Reduce Master和DFS Mastrer,Host和Port配置成与core-site.xml的设置一致即可。
一般是 localhost 9001 && 9000

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

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

代码:新建WordCount项目
File—>Project,选择Map/Reduce Project,输入项目名称WordCount等。
在WordCount项目里新建class,名称为WordCount,代码参考:
http://www.cnblogs.com/kinglau/p/3802705.html

最后,运行。
1、在HDFS上创建目录input
hdfs fs -mkdir /input
2、拷贝本地README.txt到HDFS的input里
hdfs fs -copyFromLocal /usr/local/hadoop/README.txt /input
3.点击WordCount.java,右键,点击Run As—>Run Configurations,配置运行参数,即输入和输出文件夹
hdfs://localhost:9000/input hdfs://localhost:9000/output

查看结果方式:
1. hdfs fs -ls /output
2. 展开DFS Locations,如下图所示,双击打开part-r00000查看结果
3. web查看

这里写图片描述

ps :
1. hdfs命令参考: http://blog.csdn.net/wuwenxiang91322/article/details/22166423

  1. hdfs的目录不能再磁盘上查看,是逻辑目录,只能在web页面或者命令查看

  2. 如果出现了 org.apach.* 不能查看,可能是hadoop没有正确的引入;

  3. 如果出现 Input path does not exist: hdfs://localhost:9000/user/hadoop/input 查看hdfs上是否存在此目录
0 0