Skip to content

Instantly share code, notes, and snippets.

@Saya47
Forked from kymtwyf/solution.md
Created April 29, 2023 08:27
Show Gist options
  • Save Saya47/1ab9591f6c861e24fea9f5d22cbe0c40 to your computer and use it in GitHub Desktop.
Save Saya47/1ab9591f6c861e24fea9f5d22cbe0c40 to your computer and use it in GitHub Desktop.
org.apache.hadoop.security.AccessControlException): Permission denied: user=Yongfeng, access=WRITE, inode="/user/hadoop/test.txt

有几种解决办法

  1. 去掉hdfs的permissions:
<property>
  <name>dfs.permissions</name>
  <value>false</value>
</property>

这个一定有效...

  1. 设置系统HADOOP_USER_NAME

System.setProperty("HADOOP_USER_NAME", "hduser")

  1. 使用UserGroupInformation
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hduser"); 
ugi.doAs(new PrivilegedExceptionAction<Void>() {
    public Void run() throws Exception {
        Configuration configuration = new Configuration(); 
        // 写一些东西
        FileSystem fs = FileSystem.get(new URI("hdfs://192.168.1.108:9000"), configuration);
        Path outFile = new Path("/user/hadoop/test.txt");
        FSDataOutputStream out = fs.create(outFile);
        BufferedWriter br=new BufferedWriter(new OutputStreamWriter(out));
        br.write("This is test string");
        br.close();
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment