hadoop window 遠端提交job到叢集並執行
1.複製Hadoop的4個配置檔案放到src目錄下面:core-site.xml,hdfs-site.xml,log4j.properties,mapred-site.xml,yarn-site.xml
2.配置mapred-site.xml
<configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>mapred.remote.os</name> <value>Linux</value> </property> <property> <name>mapreduce.app-submission.cross-platform</name> <value>true</value> </property> <property> <name>mapreduce.application.classpath</name> <value> /opt/hadoop-2.6.0/etc/hadoop, /opt/hadoop-2.6.0/share/hadoop/common/*, /opt/hadoop-2.6.0/share/hadoop/common/lib/*, /opt/hadoop-2.6.0/share/hadoop/hdfs/*, /opt/hadoop-2.6.0/share/hadoop/hdfs/lib/*, /opt/hadoop-2.6.0/share/hadoop/mapreduce/*, /opt/hadoop-2.6.0/share/hadoop/mapreduce/lib/*, /opt/hadoop-2.6.0/share/hadoop/yarn/*, /opt/hadoop-2.6.0/share/hadoop/yarn/lib/* </value> </property> <property> <name>mapreduce.jobhistory.address</name> <value>master:10020</value> </property> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>master:19888</value> </property> </configuration>
3:修改yarn-site.xml
<configuration> <!-- Site specific YARN configuration properties --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> </property> <property> <name>yarn.application.classpath</name> <value> /opt/hadoop-2.6.0/etc/hadoop, /opt/hadoop-2.6.0/share/hadoop/common/*, /opt/hadoop-2.6.0/share/hadoop/common/lib/*, /opt/hadoop-2.6.0/share/hadoop/hdfs/*, /opt/hadoop-2.6.0/share/hadoop/hdfs/lib/*, /opt/hadoop-2.6.0/share/hadoop/mapreduce/*, /opt/hadoop-2.6.0/share/hadoop/mapreduce/lib/*, /opt/hadoop-2.6.0/share/hadoop/yarn/*, /opt/hadoop-2.6.0/share/hadoop/yarn/lib/* </value> </property> </configuration>
4:看下我的程式碼
package com.gaoxing.hadoop; import java.io.IOException; import java.security.PrivilegedExceptionAction; 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.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.GenericOptionsParser; public class WordCount { //繼承mapper介面,設定map的輸入型別為<Object,Text> //輸出型別為<Text,IntWritable> public static class Map extends Mapper<Object,Text,Text,IntWritable>{ //one表示單詞出現一次 private static IntWritable one = new IntWritable(1); //word儲存切下的單詞 private Text word = new Text(); public void map(Object key,Text value,Context context) throws IOException,InterruptedException{ //對輸入的行切詞 StringTokenizer st = new StringTokenizer(value.toString()); while(st.hasMoreTokens()){ word.set(st.nextToken());//切下的單詞存入word context.write(word, one); } } } //繼承reducer介面,設定reduce的輸入型別<Text,IntWritable> //輸出型別為<Text,IntWritable> public static class Reduce extends Reducer<Text,IntWritable,Text,IntWritable>{ //result記錄單詞的頻數 private static IntWritable result = new IntWritable(); public void reduce(Text key,Iterable<IntWritable> values,Context context) throws IOException,InterruptedException{ int sum = 0; //對獲取的<key,value-list>計算value的和 for(IntWritable val:values){ sum += val.get(); } //將頻數設定到result result.set(sum); //收集結果 context.write(key, result); } } /** * @param args */ public static void main(String[] args) throws Exception{ Configuration conf = new Configuration(); // conf.set("mapred.remote.os","Linux"); // conf.set("yarn.resourcemanager.address","master:8032"); // conf.set("mapreduce.framework.name","yarn"); conf.set("mapred.jar","D:\\IdeaProjects\\hadooplearn\\out\\artifacts\\hadoo.jar"); //conf.set("mapreduce.app-submission.cross-platform","true"); Job job = Job.getInstance(conf); job.setJobName("test"); //配置作業各個類 job.setJarByClass(WordCount.class); job.setMapperClass(Map.class); job.setCombinerClass(Reduce.class); job.setReducerClass(Reduce.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path("hdfs://master:9000/tmp/hbase-env.sh")); FileOutputFormat.setOutputPath(job, new Path("hdfs://master:9000/tmp/out11")); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
由我就是曹總最後編輯於:4年前
內容均為作者獨立觀點,不代表八零IT人立場,如涉及侵權,請及時告知。
相關文章
- Hadoop-叢集執行Hadoop
- hadoop叢集遠端拷貝資料Hadoop
- oracle建立job並執行jobOracle
- hadoop叢集篇--從0到1搭建hadoop叢集Hadoop
- 遠端啟動HADOOP+YARN叢集Shell指令碼HadoopYarn指令碼
- windows下使用eclipse向linux叢集提交hadoop job問題與解決方法WindowsEclipseLinuxHadoop
- 在oracle 叢集多例項中執行並行操作Oracle並行
- Docker中提交任務到Spark叢集DockerSpark
- 提交原本地專案到遠端gitGit
- 利用遠端桌面管理winserver叢集Server
- 遠端執行命令
- window遠端開機
- idea配置dashboard並原始碼啟動叢集執行nacosIdea原始碼
- Hadoop叢集搭建Hadoop
- Hadoop搭建叢集Hadoop
- Hadoop 叢集命令Hadoop
- IDEA本地執行hadoop程式成功,叢集執行找不到自定義的Mapper類IdeaHadoopAPP
- Hadoop MapReduce Job提交後的互動日誌Hadoop
- ClusterShell:一個在叢集節點上並行執行命令的好工具並行
- Hadoop叢集面試題Hadoop面試題
- 4.4 Hadoop叢集搭建Hadoop
- Hadoop叢集搭建(一)Hadoop
- 如何部署hadoop叢集Hadoop
- 五行命令使用docker搭建hadoop叢集DockerHadoop
- xcall叢集執行命令指令碼指令碼
- Spark叢集和任務執行Spark
- 執行hadoop作業 No job jar file set. User classes may not be found. See Job orHadoopJAR
- Go實現ssh執行遠端命令及遠端終端Go
- 使用git初始化本地倉庫並提交到遠端分支Git
- Jmeter(四十四) - 從入門到精通高階篇 - Jmeter遠端啟動(本地執行+遠端執行)(詳解教程)JMeter
- SSH 遠端執行任務
- X window遠端登入(轉)
- hadoop分散式叢集搭建Hadoop分散式
- 使用docker部署hadoop叢集DockerHadoop
- Hadoop叢集搭建文件Hadoop
- Hadoop - Ambari叢集管理剖析Hadoop
- hadoop叢集環境搭建Hadoop
- hadoop2.2.0叢集搭建Hadoop