首页 > Windows开发 > 详细

[Hadoop] - Win7下提交job到集群上去

时间:2015-09-28 11:38:10      阅读:306      评论:0      收藏:0      [点我收藏+]

一般我们采用win开发+linux hadoop集群的方式进行开发,使用插件:hadoop-***-eclipse-plugin。


 

运行程序的时候,我们一般采用run as application或者选择run as hadoop。按照这个字面理解,我们可以认为第一种是运行在本地,第二种是运行在hadoop集群上。但是实际情况是一般如果不进行配置的话,全部是在本地进行运行的。如果需要将job提交到集群上,那么需要进行必要的设置和添加部分代码。

1、copy mapred-site.xml && yarn-site.xml文件,并修改必要的信息,将yarn指向集群。

2、给mapred-site.xml文件中添加参数mapreduce.app-submission.cross-platform,参数值为true。

3、打包本地代码提交到集群上,如果不进行该操作,会出现ClassNotFoundException。打包代码如下:

技术分享
 1 import java.io.File;
 2 import java.io.FileInputStream;
 3 import java.io.FileOutputStream;
 4 import java.io.IOException;
 5 import java.util.jar.JarEntry;
 6 import java.util.jar.JarOutputStream;
 7 
 8 public class EJob {
 9 
10     public static File createTempJar(String root) throws IOException {
11         if (!new File(root).exists()) {
12             return null;
13         }
14 
15         final File jarFile = File.createTempFile("EJob-", ".jar", new File(System
16                 .getProperty("java.io.tmpdir")));
17 
18         Runtime.getRuntime().addShutdownHook(new Thread() {
19             @Override
20             public void run() {
21                 jarFile.delete();
22             }
23         });
24 
25         JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
26         createTempJarInner(out, new File(root), "");
27         out.flush();
28         out.close();
29         return jarFile;
30     }
31 
32     private static void createTempJarInner(JarOutputStream out, File f,
33             String base) throws IOException {
34         if (f.isDirectory()) {
35             File[] fl = f.listFiles();
36             if (base.length() > 0) {
37                 base = base + "/";
38             }
39             for (int i = 0; i < fl.length; i++) {
40                 createTempJarInner(out, fl[i], base + fl[i].getName());
41             }
42         } else {
43             out.putNextEntry(new JarEntry(base));
44             FileInputStream in = new FileInputStream(f);
45             byte[] buffer = new byte[1024];
46             int n = in.read(buffer);
47             while (n != -1) {
48                 out.write(buffer, 0, n);
49                 n = in.read(buffer);
50             }
51             in.close();
52         }
53     }
54  }
EJob 打包代码工具类
 File jarFile = EJob.createTempJar("target/classes");
((JobConf) job.getConfiguration()).setJar(jarFile.toString());
// 其他创建job的代码不进行任何的修改

至此,就可以将job提交到集群上去了。

[Hadoop] - Win7下提交job到集群上去

原文:http://www.cnblogs.com/liuming1992/p/4843562.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!