我是靠谱客的博主 害羞往事,这篇文章主要介绍mapreduce在本地编写调试过程中经常遇到的异常总结mapreduce在本地编写调试过程中经常遇到的异常总结,现在分享给大家,希望可以做个参考。

mapreduce在本地编写调试过程中经常遇到的异常总结

mapreduce的编程逻辑很清晰,初期学习的时候更多的时间是在出现异常-百度异常-解决异常上面,所以进行了总结,从运行方式切入,mapreduce的运行有三种:

  1. 打jar包,上传到集群运行

    复制代码
    1
    2
    hadoop -fs jar **/**/**.jar 主类限定名 参数1(输入的文件的目录) 参数2(输出的目录)

    **注意:**一般参数2的输出目录不能是已经存在的目录。

    ps: 这样的要求是对应于如下的代码:

    复制代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    //这是驱动程序,标记(/**/)代表目录要求的原因 public class Driver { public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { Configuration conf = new Configuration(); Job job = Job.getInstance(conf); job.setJarByClass(Driver.class); job.setMapperClass(WordCountMapper.class); job.setReducerClass(WordCountReducer.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); /**************************************************/ //args[1]--不可是已存在的目录 FileOutputFormat.setOutputPath(job, new Path(args[1])); job.waitForCompletion(true); } }

    如果想避免因为目录导致的报错

    Exception in thread “main” org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory hdfs://bd/scoreoutput already exists

    代码要修改一下:

    复制代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    //这是驱动程序,标记(/**/)代表修改处 public class Driver { public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { Configuration conf = new Configuration(); Job job = Job.getInstance(conf); job.setJarByClass(Driver.class); job.setMapperClass(WordCountMapper.class); job.setReducerClass(WordCountReducer.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); /**************************************************/ FileSystem fs = FileSystem.get(conf); Path out=new Path(args[1]); if (fs.exists(out)) { fs.delete(out, true); } FileOutputFormat.setOutputPath(job, out); job.waitForCompletion(true); } }
  2. 本地连接集群,文件在集群上,但代码在本地运行。这种运行方式在我学习的过程中给我造成了挺多麻烦,所以总结起来。

    (1)HA集群如何在本地连接到集群的hdfs上处理文件

    core-site.xml和hdfs-site.xml要放到src或者resource文件夹下,否则出现的异常是:

    Exception in thread “main” java.lang.IllegalArgumentException: java.net.UnknownHostException: bd

    并且driver代码如下:

    复制代码
    1
    2
    3
    4
    System.setProperty("HADOOP_USER_NAME", "hadoop"); Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://bd/");

    (2)如果想本地文件本地运行的话,情况与(1)相反,不能有)core-site.xml和hdfs-site.xm。否则出现的异常是:

    java.io.IOException: Could not locate executable nullbinwinutils.exe in the Hadoop binaries.

    Exception in thread “main” java.lang.IllegalArgumentException: Pathname /E:/BaiduYunDownload/Cache/data from E:/BaiduYunDownload/Cache/data is not a valid DFS filename.

    (3)本地文件本地运行,输入目录要写全,一直要写到文件(这和连接到集群的情况不一样),否则出现的异常是:

    Exception in thread “main” java.lang.RuntimeException: Error while running command to get file permissions : java.io.IOException: (null) entry in command string: null ls -F E:BaiduYunDownloadCacheflow.log

    错误代码如下:

    复制代码
    1
    2
    3
    FileInputFormat.addInputPath(job, new Path("E:\BaiduYunDownload\Cache")); //没写到文件,只写到了目录

    (4)出现perminessed denied类似的异常是权限问题,解决的方法:设置HADOOP_NAME=集群用户名的环境变量,或者代码中写入:

    复制代码
    1
    2
    System.setProperty("HADOOP_USER_NAME", "hadoop");

    (5)eclipse 中运行 Hadoop2.7.3 map reduce程序 出现错误(null) entry in command string: null chmod 0700。参考:https://blog.csdn.net/qq_33252988/article/details/81611300

最后

以上就是害羞往事最近收集整理的关于mapreduce在本地编写调试过程中经常遇到的异常总结mapreduce在本地编写调试过程中经常遇到的异常总结的全部内容,更多相关mapreduce在本地编写调试过程中经常遇到内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部