hadoop2.x如何在本地用eclipse运行远程服务器的job并且查看job列表进度

牛逼飞飞 2015-11-27 09:34:18

package test;
import java.io.IOException;
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.mapred.JobConf;
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.util.GenericOptionsParser;

public class WordCount {

public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{

private final static IntWritable one = new IntWritable(1);
private Text word = new Text();

public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}

public static class IntSumReducer
extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();

public void reduce(Text key, Iterable<IntWritable> values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}

public static void main(String[] args) throws Exception {

//System.setProperty("HADOOP_USER_NAME", "hadoop");

JobConf conf = new JobConf();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}

//conf.set("hadoop.job.ugi", "hadoop");
//conf.set("hadoop.job.user", "hadoop");
// conf.set("mapred.job.tracker", hostIp + ":9001");
//conf.set("fs.defaultFS", "hdfs://n1:9000");
// conf.set("mapred.map.tasks", "2");

System.setProperty("HADOOP_USER_NAME", "hadoop");

//conf.set("mapreduce.job.queuename", "test");
//conf.set("fs.default.name", "hdfs://n1:8020");
conf.set("fs.defaultFS", "hdfs://n1:8020");
conf.set("hadoop.job.user","hadoop");

conf.set("mapreduce.framework.name","yarn");
conf.set("mapreduce.jobtracker.address","n1:9001"); //这个端口配置文件如果不设置默认是多少啊,官方文档写的默认是"local" 后面的英文说明也没看明白。端口实在太多了 好乱。

conf.set("yarn.resourcemanager.hostname", "n1");
conf.set("yarn.resourcemanager.scheduler.address", "n1:8030");
conf.set("yarn.resourcemanager.resource-tracker.address", "n1:8031");
conf.set("yarn.resourcemanager.address", "n1:8032"); //
conf.set("yarn.resourcemanager.admin.address", "n1:8033");

//conf.set("mapred.jar", "/Users/chenlong/Documents/hadoop_root/hadoop-2.7.1/myjar.jar");

//Job job = new Job(conf, "word count");
Job job = Job.getInstance(conf, "wordcount11");
job.setJarByClass(WordCount.class);

job.setMapperClass(TokenizerMapper.class);
//Uncomment this to
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);

job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);

String input = "hdfs://n1:8020/user/hadoop/input/wordcount.txt";
String output = "hdfs://n1:8020/user/hadoop/output/wordcount5";
FileInputFormat.addInputPath(job, new Path(input));
FileOutputFormat.setOutputPath(job, new Path(output));

//FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
//FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));

System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}


运行后一直挂死,不结束。如图。



配置文件:

core:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://n1:8020</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/data/hadoop2/tmp</value>
</property>

</configuration>

dfs:
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///data/hadoop2/dfs/name</value>
</property>

<property>
<name>dfs.datanode.data.dir</name>
<value>file:///data/hadoop2/dfs/data</value>
</property>

<property>
<name>dfs.replication</name>
<value>2</value>
</property>

<property>
<name>dfs.permissions</name>
<value>false</value>
</property>

<property>
<name>dfs.namenode.secondary.http-address</name>
<value>n1:50090</value>
</property>

<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>

</configuration>

map:
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>

<property>
<name>mapreduce.jobtracker.address</name>
<value>n1:9001</value>
</property>

<property>
<name>mapreduce.jobtracker.http.address</name>
<value>n1:50030</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>n1:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>n1:19888</value>
</property>

<property>
<name>mapreduce.jobhistory.done-dir</name>
<value>${yarn.app.mapreduce.am.staging-dir}/history/done</value>
</property>

<property>
<name>mapreduce.jobhistory.intermediate-done-dir</name>
<value>${yarn.app.mapreduce.am.staging-dir}/history/done_intermediate</value>
</property>

<property>
<name>yarn.app.mapreduce.am.staging-dir</name>
<value>/tmp/hadoop-yarn/staging</value>
</property>

</configuration>


yarn:
<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>n1:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>n1:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>n1:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>n1:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>n1:8088</value>
</property>
</configuration>
...全文
78 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

20,810

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧