linux进程map,LInux环境运行mapReduce程序
將工程整體打成一個(gè)jar包并上傳到linux機(jī)器上,
準(zhǔn)備好要處理的數(shù)據(jù)文件放到hdfs的指定目錄中
用命令啟動(dòng)jar包中的Jobsubmitter,讓它去提交jar包給yarn來(lái)運(yùn)行其中的mapreduce程序 ?:hadoop jar wc.jar cn.edu360.mr.wordcount.JobSubmitter .....
去hdfs的輸出目錄中查看結(jié)果
import java.io.IOException;
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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
/**
* 如果要在hadoop集群的某臺(tái)機(jī)器上啟動(dòng)這個(gè)job提交客戶端的話
* conf里面就不需要指定 fs.defaultFS mapreduce.framework.name
*
* 因?yàn)樵诩簷C(jī)器上用 hadoop jar xx.jar cn.edu360.mr.wc.JobSubmitter2 命令來(lái)啟動(dòng)客戶端main方法時(shí),
* hadoop jar這個(gè)命令會(huì)將所在機(jī)器上的hadoop安裝目錄中的jar包和配置文件加入到運(yùn)行時(shí)的classpath中
*
* 那么,我們的客戶端main方法中的new Configuration()語(yǔ)句就會(huì)加載classpath中的配置文件,自然就有了
* fs.defaultFS 和 mapreduce.framework.name 和 yarn.resourcemanager.hostname 這些參數(shù)配置
*
* @author ThinkPad
*
*/
public class JobSubmitterLinuxToYarn {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://hdp-01:9000");
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
// 沒(méi)指定默認(rèn)文件系統(tǒng)
// 沒(méi)指定mapreduce-job提交到哪運(yùn)行
Job job = Job.getInstance(conf);
job.setJarByClass(JobSubmitterLinuxToYarn.class);
job.setMapperClass(WordcountMapper.class);
job.setReducerClass(WordcountReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.setInputPaths(job, new Path("/wordcount/input"));
FileOutputFormat.setOutputPath(job, new Path("/wordcount/output"));
job.setNumReduceTasks(3);
boolean res = job.waitForCompletion(true);
System.exit(res?0:1);
}
}
總結(jié)
以上是生活随笔為你收集整理的linux进程map,LInux环境运行mapReduce程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql optimizer组件_My
- 下一篇: Linux切换用户