问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

我在CentOS系统中配置hadoopp,在eclipse中运行hadoopp的wordcount.java...

发布网友 发布时间:2022-05-02 22:02

我来回答

1个回答

热心网友 时间:2022-04-14 15:44

新建一个hadoop工程,如图

建一个运行wordcount的类,先不管他什么意思,代码如下

[java] view plain copy
/**
* Project: hadoop
*
* File Created at 2012-5-21
* $Id$
*/
package seee.you.app;
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.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.maprece.Job;
import org.apache.hadoop.maprece.Mapper;
import org.apache.hadoop.maprece.Recer;
import org.apache.hadoop.maprece.lib.input.FileInputFormat;
import org.apache.hadoop.maprece.lib.output.FileOutputFormat;
public class WordCount {
public static class TokenizerMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable 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 IntSumRecer extends Recer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
public void rece(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();
if (args.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.setRecerClass(IntSumRecer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

这时候右键run on hadoop

这时候不幸的是,报错了,错误信息如下:

[java] view plain copy
12/05/23 19:38:51 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
12/05/23 19:38:51 ERROR security.UserGroupInformation: PriviledgedActionException as:yongkang.qiyk cause:java.io.IOException: Failed to set permissions of path: \tmp\hadoop-yongkang\mapred\staging\yongkang.qiyk-1840800210\.staging to 0700
Exception in thread "main" java.io.IOException: Failed to set permissions of path: \tmp\hadoop-yongkang\mapred\staging\yongkang.qiyk-1840800210\.staging to 0700
at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:682)
at org.apache.hadoop.fs.FileUtil.setPermission(FileUtil.java:655)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:509)
at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:344)
at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:189)
at org.apache.hadoop.maprece.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:116)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:856)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:850)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1093)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:850)
at org.apache.hadoop.maprece.Job.submit(Job.java:500)
at org.apache.hadoop.maprece.Job.waitForCompletion(Job.java:530)
at seee.you.app.WordCount.main(WordCount.java:80)

错误信息很明显了,at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:682) 这一行的方法报错了

网上查到这是由于0.20.203.0以后的版本的权限认证引起的,只有去掉才行
修改hadoop源代码,去除权限认证,修改FileUtil.java的checkReturnValue方法,如下:

[java] view plain copy
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()));
// }
}

去掉这一行后,需要重新编译打包下,打包成功之后,可以将hadoop-core-1.0.2.jar拷贝到hadoop根目录下,eclipse中重新导入下即可(我用的这个1.0.2是从网上下载的修改好的,比较省事)

这时重新运行下实例,运行实例需要配置下arguments参数,我的配置如下:

run一下,结果如下,说明已经成功了

[java] view plain copy
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
****hdfs://10.16.110.7:9000/user/yongkang/test-in
INFO input.FileInputFormat: Total input paths to process : 0
INFO mapred.JobClient: Running job: job_local_0001
INFO mapred.Task: Using ResourceCalculatorPlugin : null
INFO mapred.LocalJobRunner:
INFO mapred.Merger: Merging 0 sorted segments
INFO mapred.Merger: Down to the last merge-pass, with 0 segments left of total size: 0 bytes
INFO mapred.LocalJobRunner:
INFO mapred.Task: Task:attempt_local_0001_r_000000_0 is done. And is in the process of commiting
INFO mapred.LocalJobRunner:
INFO mapred.Task: Task attempt_local_0001_r_000000_0 is allowed to commit now
INFO output.FileOutputCommitter: Saved output of task 'attempt_local_0001_r_000000_0' to /user/yongkang/test-out6
INFO mapred.JobClient: map 0% rece 0%
INFO mapred.LocalJobRunner: rece > rece
INFO mapred.Task: Task 'attempt_local_0001_r_000000_0' done.
INFO mapred.JobClient: map 0% rece 100%
INFO mapred.JobClient: Job complete: job_local_0001
INFO mapred.JobClient: Counters: 10
INFO mapred.JobClient: File Output Format Counters
INFO mapred.JobClient: Bytes Written=0
INFO mapred.JobClient: FileSystemCounters
INFO mapred.JobClient: FILE_BYTES_READ=8604
INFO mapred.JobClient: FILE_BYTES_WRITTEN=51882
INFO mapred.JobClient: Map-Rece Framework
INFO mapred.JobClient: Rece input groups=0
INFO mapred.JobClient: Combine output records=0
INFO mapred.JobClient: Rece shuffle bytes=0
INFO mapred.JobClient: Rece output records=0
INFO mapred.JobClient: Spilled Records=0
INFO mapred.JobClient: Total committed heap usage (bytes)=5177344
INFO mapred.JobClient: Rece input records=0
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
靓仔怎么在班里受欢迎啊? 男的叫哥,女的叫姐 2024年nba总决赛几号开始总决赛赛程时间表出炉了-今日头条 无限连接的打印机不能打印公务员准考证 全国流量什么意思 新笑傲江湖手游恒山不能复活吗 有没有复活技能解答 新笑傲江湖手游恒山派怎么样_新笑傲江湖手游恒山派技能详解 新笑傲江湖恒山菩提武学怎么玩_恒山菩提武学玩法介绍 c语言argc参数在哪里设置? 这个C语言程序为何运行不出 weblogic在centos上jar安装后,没有startWebLogic.sh的脚本,请问这个怎么办啊 linux下运行jar程序,最后一个参数能取到但是值不对 做考研英语阅读题有什么技巧? 请问应该如何做考研英语阅读,遵循什么样的步骤? 有什么软件不用绑定银行卡就可以提现到微信的赚钱软件吗 我没有银行卡怎么在微信上赚钱? 考研英语填空式阅读的基本解题步骤有哪些 幼儿教师观 考研英语复习中,阅读理解总是错很多,想问一下考研英语应该如何做阅读,遵循什么样的步骤? 一部手机登录5个都绑定自己的银行卡能微信辅助赚钱吗? 考研英语阅读应该按什么顺序做题 考研英语阅读正确做题方法 怎么知道手机号有没有注册 美国注册安全师是从哪里报名 用360修补漏洞后安装win7的联想笔记本桌面图标变成这样的了 哪家的短信接口支持回复呀,像那种从接口直接获取回复 短信接口,平台推送回来的信息接收问题。。。 X240S 的蓝牙模块是什么类型的啊?USB?UART?BCSP? 北大青鸟毕业证书是什么学历的? 公司文件数字编号为什么有人说不要按顺序来,是不是的要跳号! 如何在CentOS上搭建 Struts2+Spring+Hibernate的运行环境 centos nexus怎么用命令上传jar包 羊胎素的争议事件 羊胎素对卵巢囊肿有影响吗 打羊胎素怎么样,?有没有什么不好的影响,听说能健康点 甲状腺功能亢进症为什么不能打羊胎素? 都说发芽的土豆不能吃,吃了发芽的土豆真的不健康吗? 发芽的土豆到底可以吃吗?有哪位专家的说法? 羊胎素为什么没有SOD助睡眠效果好? 吃羊胎素为什么会感觉发热 吃了羊胎素胶囊,为什么脸上会起小红点 我为什么用了擦脸的羊胎素过后脸会发红发烫 吃了虫草羊胎素脸为什么发黄?吃了将近一个月,脸发黄。 首都网络安全日京东有怎样的安全变革? made for CSA.inc 什么意思? QQ兴趣部落里怎么把粉丝删除 海ES60H—E9(E(U1))热水器不加热了怎么回事 如何删除QQ兴趣部落里的粉丝? 怎么把qq部落的粉丝弄走 qq部落里,怎么把一个陌生人给拉黑?或者让她的消息发不过来?谢谢