基于Eclipse的Hadoop应用开发环境配置(zhuanzai)

沙诺 posted @ 2013年7月31日 21:47 in 云计算 , 1368 阅读

我的开发环境:

操作系统centos5.5 一个namenode 两个datanode

Hadoop版本:hadoop-0.20.203.0

Eclipse版本:eclipse-java-helios-SR2-linux-gtk.tar.gz(使用3.7的版本总是崩溃,让人郁闷)

第一步:先启动hadoop守护进程

具体参看:http://www.cnblogs.com/flyoung2008/archive/2011/11/29/2268302.html

第二步:在eclipse上安装hadoop插件

1.复制 hadoop安装目录/contrib/eclipse-plugin/hadoop-0.20.203.0-eclipse-plugin.jar 到 eclipse安装目录/plugins/ 下。 

2.重启eclipse,配置hadoop installation directory。 
如果安装插件成功,打开Window-->Preferens,你会发现Hadoop Map/Reduce选项,在这个选项里你需要配置Hadoop installation directory。配置完成后退出。

3.配置Map/Reduce Locations。 
在Window-->Show View中打开Map/Reduce Locations。 
在Map/Reduce Locations中新建一个Hadoop Location。在这个View中,右键-->New Hadoop Location。在弹出的对话框中你需要配置Location name,如Hadoop,还有Map/Reduce Master和DFS Master。这里面的Host、Port分别为你在mapred-site.xml、core-site.xml中配置的地址及端口。如:

Map/Reduce Master

192.168.1.101
9001

DFS Master

192.168.1.101
9000

配置完后退出。点击DFS Locations-->Hadoop如果能显示文件夹(2)说明配置正确,如果显示"拒绝连接",请检查你的配置。


第三步:新建项目。 
File-->New-->Other-->Map/Reduce Project 
项目名可以随便取,如WordCount。 
复制 hadoop安装目录/src/example/org/apache/hadoop/example/WordCount.java到刚才新建的项目下面。 

第四步:上传模拟数据文件夹。 
为了运行程序,我们需要一个输入的文件夹,和输出的文件夹。
在本地新建word.txt

java c++ python c
java c++ javascript 
helloworld hadoop
mapreduce java hadoop hbase 

通过hadoop的命令在HDFS上创建/tmp/workcount目录,命令如下:bin/hadoop fs -mkdir /tmp/wordcount

通过copyFromLocal命令把本地的word.txt复制到HDFS上,命令如下:bin/hadoop fs -copyFromLocal /home/grid/word.txt  /tmp/wordcount/word.txt


第五步:运行项目

1.在新建的项目Hadoop,点击WordCount.java,右键-->Run As-->Run Configurations 
2.在弹出的Run Configurations对话框中,点Java Application,右键-->New,这时会新建一个application名为WordCount 
3.配置运行参数,点Arguments,在Program arguments中输入“你要传给程序的输入文件夹和你要求程序将计算结果保存的文件夹”,如:

hdfs://centos1:9000/tmp/wordcount/word.txt   hdfs://centos1:9000/tmp/wordcount/out

4、如果运行时报java.lang.OutOfMemoryError: Java heap space 配置VM arguments(在Program arguments下)

-Xms512m -Xmx1024m -XX:MaxPermSize=256m

5.点击Run,运行程序。 

点击Run,运行程序,过段时间将运行完成,等运行结束后,查看运行结果,使用命令: bin/hadoop fs -ls /tmp/wordcount/out查看例子的输出结果,发现有两个文件夹和一个文件,使用命令查看part-r-00000文件, bin/hadoop fs -cat /tmp/wordcount/out/part-r-00000可以查看运行结果。

复制代码
c    1
c++    2
hadoop    2
hbase    1
helloworld    1
java    3
javascript    1
mapreduce    1
python    1

 

Avatar_small
celeb networth 说:
2020年8月16日 21:51

Checking out the birthday of celebrity on celebrity networth to know if they have the same birthday as you, or same age, or to know which celebrity have birthday today.

Avatar_small
seo service london 说:
2024年2月21日 03:54

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well..


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter