远程提交Map/Reduce任务

1. 将开发好MR代码打包成jar。添加到distributed cache中。

 

Xml代码  
  1. bin/hadoop fs -copyFromLocal /root/stat-analysis-mapred-1.0-SNAPSHOT.jar /user/root/lib  
bin/hadoop fs -copyFromLocal /root/stat-analysis-mapred-1.0-SNAPSHOT.jar /user/root/lib

 

2.  在服务器端创建和你客户端一模一样的用户。创建目录 /tmp/hadoop-root/stagging/用户 

 

3.  客户端提交job的代码

 

Java代码  
  1. Configuration conf = HBaseConfiguration.create();   
  2.         conf.set("hbase.zookeeper.quorum""node.tracker1");   
  3.         conf.set("fs.default.name""hdfs://node.tracker1:9000/hbase");   
  4.         conf.set("mapred.job.tracker""node.tracker1:9001");   
  5.           
  6.         Job job = new Job(conf, "Hbase_FreqCounter1");   
  7.          
  8.         job.setJarByClass(FreqCounter1.class);   
  9.         Scan scan = new Scan();   
  10.         String columns = "details"// comma seperated   
  11.         scan.addFamily(Bytes.toBytes(columns));   
  12.         scan.setFilter(new FirstKeyOnlyFilter());   
  13.         TableMapReduceUtil.initTableMapperJob("access_logs", scan, Mapper1.class, ImmutableBytesWritable.class,   
  14.                 IntWritable.class, job);   
  15.         TableMapReduceUtil.initTableReducerJob("summary_user", Reducer1.class, job);   
  16. /           TableMapReduceUtil.addDependencyJars(job);   
  17.            
  18.         DistributedCache.addFileToClassPath(new Path("hdfs://node.tracker1:9000/user/root/lib/stat-analysis-mapred-1.0-SNAPSHOT.jar"),job.getConfiguration());   
  19.         job.submit();  
	Configuration conf = HBaseConfiguration.create();
	        conf.set("hbase.zookeeper.quorum", "node.tracker1");
	        conf.set("fs.default.name", "hdfs://node.tracker1:9000/hbase");
	        conf.set("mapred.job.tracker", "node.tracker1:9001");
	       
	        Job job = new Job(conf, "Hbase_FreqCounter1");
	      
	        job.setJarByClass(FreqCounter1.class);
	        Scan scan = new Scan();
	        String columns = "details"; // comma seperated
	        scan.addFamily(Bytes.toBytes(columns));
	        scan.setFilter(new FirstKeyOnlyFilter());
	        TableMapReduceUtil.initTableMapperJob("access_logs", scan, Mapper1.class, ImmutableBytesWritable.class,
	                IntWritable.class, job);
	        TableMapReduceUtil.initTableReducerJob("summary_user", Reducer1.class, job);
//	        TableMapReduceUtil.addDependencyJars(job);
	        
	        DistributedCache.addFileToClassPath(new Path("hdfs://node.tracker1:9000/user/root/lib/stat-analysis-mapred-1.0-SNAPSHOT.jar"),job.getConfiguration());
	        job.submit();
 

 

4.运行java application,登陆node的MR管理页面,可以看到


远程提交Map/Reduce任务_第1张图片

你可能感兴趣的:(远程提交Map/Reduce任务)