Window下Eclipse远程访问伪分布式hadoop1.2.1测试WordCount
来源:互联网 发布:js scroll属性 编辑:程序博客网 时间:2024/05/21 19:28
hadoop时遇到遇到ERROR security.UserGroupInformation: PriviledgedActionException as:xxxx cause:java.io.I
目前网上找到的资料
Map/Reduce Master
参看hadoop 安装路径下conf 文件夹下的core-site.xml
我在虚拟机上配置为
<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!-- Put site-specific property overrides in this file. --><configuration><property> <name>fs.default.name</name> <!-- <value>hdfs://master.hadoop:9000</value> --> <value>hdfs://192.168.73.100:9000</value></property><property> <name>hadoop.tmp.dir</name> <value>/root/hadoop/hadoop-1.2.1/tmp</value></property></configuration>
DFS Master 的配置路径在mapred-site.xml中
<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!-- Put site-specific property overrides in this file. --><configuration><property> <name>mapred.job.tracker</name><!-- <value>master.hadoop:9001</value> --> <value>192.168.73.100:9001</value></property><property> <name>dfs.permissions</name> <value>false</value></property></configuration>
User name 为hadoop 访问用户名: 网上教程大多为hadoop,master, 我是在CentOS7 root用户下直接创建的hadoop 这里我直接用root
hadoop.tmp.dir 所指向的地址路径也在core-site.xml 中 上面有我配置的core-site.xml 可以参看
在hadoop-1.2.1\src\examples\org\apache\hadoop\examples 路径下 有官方 WordCount 例子
将例子进行修改
要注意
public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); conf.set("mapred.job.tracker", "192.168.73.100:9001"); conf.set("fs.default.name", "hdfs://192.168.73.100:9000"); // in 为你所指向的 上传地址,我这里是in ,可能你那里是input String[] ars = new String[]{"in", "newout"}; //注意下面的ars 已经不再是args String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } Job job = new Job(conf, "word count"); File jarFile = EJob.createTempJar("bin"); //EJob 是其他类, 在下面链接中会给出 EJob.addClasspath("/root/hadoop/conf"); ClassLoader classLoader = EJob.getClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); ((JobConf) job.getConfiguration()).setJar(jarFile.toString()); //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); }
in 中一定要有测试文件 我的是
最后用hadoop 运行 。控制台日志如下图
贴下EJob 代码 。当然如果你有积分的话也可以去下载
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.net.URL;import java.net.URLClassLoader;import java.util.ArrayList;import java.util.List;import java.util.jar.JarEntry;import java.util.jar.JarOutputStream;import java.util.jar.Manifest;public class EJob { // To declare global field private static List<URL> classPath = new ArrayList<URL>(); // To declare method public static File createTempJar(String root) throws IOException { if (!new File(root).exists()) { return null; } Manifest manifest = new Manifest(); manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); final File jarFile = File.createTempFile("EJob-", ".jar", new File( System.getProperty("java.io.tmpdir"))); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { jarFile.delete(); } }); JarOutputStream out = new JarOutputStream( new FileOutputStream(jarFile), manifest); createTempJarInner(out, new File(root), ""); out.flush(); out.close(); return jarFile; } private static void createTempJarInner(JarOutputStream out, File f, String base) throws IOException { if (f.isDirectory()) { File[] fl = f.listFiles(); if (base.length() > 0) { base = base + "/"; } for (int i = 0; i < fl.length; i++) { createTempJarInner(out, fl[i], base + fl[i].getName()); } } else { out.putNextEntry(new JarEntry(base)); FileInputStream in = new FileInputStream(f); byte[] buffer = new byte[1024]; int n = in.read(buffer); while (n != -1) { out.write(buffer, 0, n); n = in.read(buffer); } in.close(); } } public static ClassLoader getClassLoader() { ClassLoader parent = Thread.currentThread().getContextClassLoader(); if (parent == null) { parent = EJob.class.getClassLoader(); } if (parent == null) { parent = ClassLoader.getSystemClassLoader(); } return new URLClassLoader(classPath.toArray(new URL[0]), parent); } public static void addClasspath(String component) { if ((component != null) && (component.length() > 0)) { try { File f = new File(component); if (f.exists()) { URL key = f.getCanonicalFile().toURL(); if (!classPath.contains(key)) { classPath.add(key); } } } catch (IOException e) { } } }}
下载链接
http://download.csdn.net/download/sinat_32867867/10029950
阅读全文
0 0
- Window下Eclipse远程访问伪分布式hadoop1.2.1测试WordCount
- fedora22下hadoop1.2.1wordcount测试
- Eclipse下伪分布式运行hadoop例子wordcount
- hadoop1.2.1伪分布式安装
- hadoop1.2.1伪分布式安装
- hadoop1.2.1伪分布式搭建
- hadoop1.2.1伪分布式安装
- Hadoop1.2.1 伪分布式配置
- Ubuntu下hadoop1.21伪分布式搭建
- win7上搭建hadoop1.2.1伪分布式
- Ubuntu11.10下安装Hadoop1.0.1(单机伪分布式)
- ubuntu12环境下hadoop1.1.2伪分布式配置
- Hadoop1.0.4伪分布式安装
- Hadoop1 Centos伪分布式部署
- hadoop1.1.2 伪分布式安装
- Hadoop1.1.2伪分布式安装
- 伪分布式环境下命令行正确运行hadoop示例wordcount
- Hadoop在Linux下伪分布式的安装以及wordcount实例的运行还有Eclipse的使用
- 【Leetcode-Easy-160】Intersection of Two Linked Lists
- 对信号卷积的理解
- ScrollRect和Grid
- 生于不义,死于耻辱:e租宝被顶格判罚,无期徒刑,财物充公!
- IDEA打开Myeclipse的web项目
- Window下Eclipse远程访问伪分布式hadoop1.2.1测试WordCount
- Android UI渲染总结
- 深入理解Java的接口和抽象类
- Error:Execution failed for task ':app:buildInfoDebugLoader'.
- 启动优化(解决白屏问题)
- spring mvc 的启动过程
- jsp路径问题记录
- spring整合通用Mapper+ PageHelper + log4j2 + maven
- CMD命令提示符窗口基本样式属性设置