程序在YARN上的运行的windows和Linux测试

1,Windows本地测试

项目打成jar包在windows本地

public class WordCountMain {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        // 1 配置对象
        System.setProperty("HADOOP_USER_NAME", "root");
        // 设置访问文件系统
        conf.set("fs.defaultFS", "hdfs://linux01:9000");
        // 设置MR程序运行模式  yarn
        conf.set("mapreduce.framework.name", "yarn");
        // yarn的resourcemanager的位置
        conf.set("yarn.resourcemanager.hostname", "linux01");
        // 设置MapReduce程序运行在windows上的跨平台参数
        conf.set("mapreduce.app-submission.cross-platform","true");

        Job job = Job.getInstance(conf);
        // 1、封装参数:jar包所在的位置
        job.setJar("F:\\WorkSpace\\MapReducePro\\target\\MapReducePro-1.0-SNAPSHOT.jar");
        //job.setJarByClass(WordCountMain.class);

        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

        job.setNumReduceTasks(1);

        job.setMapOutputKeyClass(Text .class);
        job.setMapOutputValueClass(IntWritable.class);

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

        FileInputFormat.setInputPaths(job, new Path("/wc/"));
        FileOutputFormat.setOutputPath(job, new Path("/output"));

        job.waitForCompletion(true);
    }
}

2 ,Linux

      项目打包后上传到Linux磁盘上

  命令:hadoop jar  指定jar包和主类

hadoop jar ./MapReducePro-1.0-SNAPSHOT.jar com.demo.mapreduce.wordCount.WordCountMain

配置代码:

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.set("mapreduce.framework.name", "yarn");
        // yarn的resourcemanager的位置
        conf.set("yarn.resourcemanager.hostname", "linux01");
        // 2 创建任务对象
        Job job = Job.getInstance(conf);
        job.setJarByClass(WordCountMain.class);
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

        job.setNumReduceTasks(1);

        job.setMapOutputKeyClass(Text .class);
        job.setMapOutputValueClass(IntWritable.class);

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

        FileInputFormat.setInputPaths(job, new Path("/wc/"));
        FileOutputFormat.setOutputPath(job, new Path("/output"));

        job.waitForCompletion(true);
    }

运行中:

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值