一、概述 最近开始着手高校云平台的搭建,前些天做了hadoop集群测试环境的安装与配置的经验分享, 这篇文章主要介绍win7 64位下 eclipse4.2 连接远程redhat linux 5下hadoop-1.2.0集群开发环境搭建 二、环境 1、window 7 64位 2、eclipse 4.2 3、redhat linu
一、概述
最近开始着手高校云平台的搭建,前些天做了hadoop集群测试环境的安装与配置的经验分享, 这篇文章主要介绍win7 64位下 eclipse4.2 连接远程redhat linux 5下hadoop-1.2.0集群开发环境搭建
二、环境
1、window 7 64位
2、eclipse 4.2
3、redhat linux 5
4、hadoop-1.2.0
三、安装配置hadoop集群
参考我的文章:
http://blog.csdn.net/shan9liang/article/details/9841933
http://www.jialinblog.com/?p=176
?
四、在eclipse下安装配置hadoop插件
1、编译eclipse-hadoop插件
参考: http://www.cnblogs.com/chenying99/archive/2013/05/31/3109566.html
2、安装
安装插件就很简单了,把上面编译的插件文件放到 eclipse的安装目录下的plugins,重新启动eclipse
3、配置
(1)将hadoop解压到windows文件系统的某个目录中
(2)?打开eclipse,设置好workspace
?打开window-->preferens,你会发现hadoop map/reduce选项,在这个选项里你需要配置hadoop installation directory。配置完成后退出。
(3)选择window -> open perspective -> other... , 选择有大象图标的 map/reduce,此时,就打开了map/reduce的开发环境。可以看到,右下角多了一个map/reduce locations的框。如下图
?
新建,在打开的窗口中输入:
?
location name : 此处为参数设置名称,可以任意填写
map/reduce master (此处为hadoop集群的map/reduce地址,应该和mapred-site.xml中的mapred.job.tracker设置相同)
dfs master (此处为hadoop的master服务器地址,应该和core-site.xml中的 fs.default.name 设置相同)
设置完成后,点击finish就应用了该设置。
此时,在最左边的project explorer中就能看到dfs的目录,如下图所示。
配置完毕
五、测试
新建项目:file-->new-->other-->map/reduce project ,项目名可以随便取,如hadoop_test_01
它会自动添加依赖包,如下:
?
可以运行hadoop自带的wordcount实例
/**
?* ?licensed under the apache license, version 2.0 (the license);
?* ?you may not use this file except in compliance with the license.
?* ?you may obtain a copy of the license at
?*
?* ? ? ?http://www.apache.org/licenses/license-2.0
?*
?* ?unless required by applicable law or agreed to in writing, software
?* ?distributed under the license is distributed on an as is basis,
?* ?without warranties or conditions of any kind, either express or implied.
?* ?see the license for the specific language governing permissions and
?* ?limitations under the license.
?*/
package com.jialin.hadoop;
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{
?
? ? 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 {
? ? private intwritable result = new intwritable();
? ? public void reduce(text key, iterable 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();
?
? ? string[] otherargs = new genericoptionsparser(conf, args).getremainingargs();
? ? if (otherargs.length != 2) {
? ? ? system.err.println(usage: wordcount );
? ? ? system.exit(2);
? ? }
? ? 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, new path(otherargs[0]));
? ? fileoutputformat.setoutputpath(job, new path(otherargs[1]));
? ? system.exit(job.waitforcompletion(true) ? 0 : 1);
? }
}
运行时参数设置:
右击wordcount,选择run as - run configurations
?
参数根据自己实际情况
input目录下有两个文件input1和input2,内容分别为:hello world,hello hadoop
output目录不用手动创建。
运行:
右击wordcount-run as -run on hadoop
运行成功,查看output中的文件内容
hello 2
hadoop 1
world 1
?
注:测试中遇到问题的解决方式
解决权限问题
1、hadoop权限
如果当前登录windows的用户名和hadoop集群的用户名不一致,将没有权限访问,会报错
?目前做法是开发时将hadoop服务集群关闭权限认证,正式发布时,可以在服务器创建一个和hadoop集群用户名一致的用户,即可不用修改master的permissions策略。
详细参考我的文章:
http://blog.csdn.net/shan9liang/article/details/9734693
http://www.jialinblog.com/?p=172
?
2、windows下0700问题
这个问题真是纠结了我好几天,最后修还hadoop源码hadoop-core-1.2.0.jar中的fileutil,重新编译 hadoop-core-1.2.0.jar?,替换掉原来的。才得以解决
详细参考我的文章:
http://blog.csdn.net/shan9liang/article/details/9734677
http://www.jialinblog.com/?p=174
?
七、总结
至此高校云平台的hadoop集群基本开发环境已经出来了,剩下的就是在此基础上进行丰富了。如果是简单的测试,推荐使用单机hadoop方式,或者伪分布式。我之所以不选择单机或伪分布式,只是想尽可能地模拟真实环境。大家按需选择吧。
?
作者:shan9liang 发表于2013-8-14 20:11:55 原文链接
阅读:51 评论:0 查看评论
原文地址:windows 7 with eclipse 下hadoop应用开发环境搭建, 感谢原作者分享。