五十九、Hadoop——MapReduce(计数)

删掉文件hadooptmp             rm -rf    hadooptmp
删掉鼠标下方5行                 d5d 
打包:IDEA右侧Maven Projects——test_20211026-Lifecycle——PACKAGE

  stop-all.sh
  jps
  start-all.sh
  jps
  mr-jobhistory-daemon.sh start historyserver
  jps
  打开mapreduce目录     cd /opt/soft/install/hadoop260/share/hadoop/mapreduce       
  把input里的hello.txt文件传到output2里面   
 hadoop jar hadoop-mapreduce-examples-2.6.0-cdh5.14.2.jar  wordcount /input/hello.txt /output2
   ll
   删掉output1  hdfs dfs -rmr /output1
   cd /opt/soft
   ll
    hadoop jar test_20211026-1.0-SNAPSHOT.jar  nj.zb.kb15.demo1.WordCountDriver /input /output
   history


public class WordCountDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(WordCountDriver.class);

        // 配置当前job  执的mapper类
        job.setMapperClass(WordCountMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);


        // 配置当前job  执行的reduce类
        job.setReducerClass(WordCountReduce.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        //指定读取文件的路径
      //  Path path=new Path("D:\\test_20211026\\in\\demo1\\hello.txt");    //1
   //   Path path=new Path("hdfs://gree128:9000/input");           //3
        Path path=new Path(args[0]);                                     //2
        FileInputFormat.setInputPaths(job,path);

        //指定执行任务后输出路径
      //  Path pathout=new Path("D:\\test_20211026\\in\\out1");              //1
    //    Path pathout=new Path("hdfs://gree128:9000/output");       //3
        Path pathout=new Path(args[1]);                                    //2
        FileSystem fileSystem=FileSystem.get(pathout.toUri(),conf);
        if(fileSystem.exists(pathout)){
            fileSystem.delete(pathout,true);
        }
        FileOutputFormat.setOutputPath(job,pathout);

        job.waitForCompletion(true);                                   //1,2

     //   System.out.println(args[0]+""+args[1]);                         //3


    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天地风雷水火山泽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值