问题导读
1.如何远程连接eclipse?
2.遇到连接失败可能原因是什么?
3.如何解决连接权限问题?
4.windows下0700问题该如何解决?
一、概述
最近开始着手高校云平台的搭建,前些天做了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
三、在Eclipse下安装配置hadoop插件
1、安装
安装插件就很简单了,把上面编译的插件文件放到 Eclipse的安装目录下的plugins,重新启动Eclipse
2、配置
(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<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();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
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集群的用户名不一致,将没有权限访问,会报错
解决办法1:dfs.permissions修改为false。
解决方法2:
可以在服务器创建一个和hadoop集群用户名一致的用户,即可不用修改master的permissions策略。
2、windows下0700问题
这个问题真是纠结了我好几天,最后修还hadoop源码hadoop-core-1.2.0.jar中的FileUtil,重新编译 hadoop-core-1.2.0.jar ,替换掉原来的。才得以解决
eclipse连接远程hadoop集群开发时报错
错误信息:
Exception in thread "main" java.io.IOException:Failed to set permissions of path:\tmp\hadoop-ysc\mapred\staging\ysc-2036315919\.staging to 0700
解决方案(经笔者在hadoop1.2.0+jdk1.7下验证通过):
0.安装jdk,ant,并且配置好环境变量
安装配置jdk不再多说,ant可参考从零教你在Linux环境下(ubuntu)如何编译hadoop2.4
1.首先到官网上把该版本hadoop的tar包下载下来,并解压到$HADOOP_HOME目录下
2.修改hadoop-1.2.0\src\core\org\apache\hadoop\fs下的FileUtil类
private static void checkReturnValue(boolean rv, File p,
FsPermission permission
) throws IOException {
if (!rv) {
throw new IOException("Failed to set permissions of path: " + p +
" to " +
String.format("%04o", permission.toShort()));
}
}
将这个抛异常操作注释掉或者把throw new IOException改为LOG.warn
3.进入到$HADOOP_HOME/src目录中,修改saveVersion.sh文件,因为原saveVersion.sh生成的package-info.java有问题。更正内容为:
user=`whoami` #此处修改成固定值,如user=jialin
3、修改$HADOOP_HOME\build.xml,搜索autoreconf,移除匹配的6个executable="autoreconf"的exec配置 ,如: <exec executable="autoreconf"
dir="${c++.task-controller.src}"
searchpath="yes" failonerror="yes">
<arg value="-i"/>
</exec>
共有6处,将该语言块删除
4、 修改hadoop安装目录下的\build.xml 指定java版本<property name="javac.version" value="1.6"/> 如是1.7就改为1.7
5、在命令行切换到$HADOOP_HOME,执行ant
6、用新生成的$HADOOP_HOME\build\hadoop-core-1.*.*-SNAPSHOT.jar替换nutch的hadoop-core-*.*.*.jar
参考http://blog.csdn.net/shan9liang/article/details/9734677
|
|