删掉文件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 } }
五十九、Hadoop——MapReduce(计数)
于 2021-10-27 19:09:43 首次发布