hadoop之java接口常见问题

版权声明:test https://blog.csdn.net/weixin_37275456/article/details/83142041

1.Wrong FS: hdfs://192.168.117.101:9000/JAVA_learing.jar, expected: file:///

        Path path = new Path(str);
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        FSDataInputStream in = fs.open(path);

当使用如上代码配置时,会报该错,原因是系统不识别hdfs://地址系统
解决方案:

  • 方案一:将core-site.xml,hdfs-site.xml文件拷贝到java源文件同级目录下,当new Configuration()的时候会读取这些配置文件,创建和hdfs系统相匹配的Configuration
  • 方案二:在new Configuration()之后使用conf.set(“fs.defaultFS”,“hdfs://hadoop101:9000/”)配置
  • 方案三:使用FileSystem fs = FileSystem.get(URI.create(str),conf);

2.Permission denied: user=great, access=WRITE, inode="/":chen:supergroup:drwxr-xr-x

解决方案:

  • 方案一:修改VM运行参数 “-DHADOOP_USER_NAME=chen”
  • 在这里插入图片描述
  • 方案二:在配置config的时候导入
    this.fileSystem = FileSystem.get(URI.create("hdfs://hadoop101:9000/"), conf, "chen");

猜你喜欢

转载自blog.csdn.net/weixin_37275456/article/details/83142041