之前运行hadoop的方式是首先编写好程序,然后再将程序打包成jar包,然后上传到服务器中运行。
现在的有一种方法是通过在本地idea中可以将jar包提交到远程集群中运行。
简单的代码
一个简单的例子:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
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 java.io.IOException;
import java.net.URI;
public class WordCount {
public static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
private final static IntWritable result = new IntWritable(1);
private final static Text Key = new Text();
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
// super.map(key, value, context);
String line = value.toString();
String[] words = line.split(" ");
for(String word: words){
Key.set(word);
context.write(Key, result);
}
}
}
public static class WordCountReduce extends Reducer<Text, IntWritable, Text, Int

本文介绍了如何在IDEA中直接将Java程序以jar包形式提交到远程YARN集群运行,无需手动上传。主要内容包括:编写简单代码,设置关键参数如`yarn.resourcemanager.hostname`和`mapreduce.app-submission.cross-platform`,添加Hadoop和YARN的依赖,配置`yarn-site.xml`和`mapred-site.xml`,以及如何查看运行的job状态。

5563

被折叠的 条评论
为什么被折叠?



