脚本宝典收集整理的这篇文章主要介绍了org.apache.hadoop.security.AccessControlException: Permission denied,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
访问HDFS报错:org.apache.hadoop.securITy.AccessControlException: PErmission denied
import org.apache.hadoop.conf.configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class testHDFS { public static void main(String[] args) throws Exception{ Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://192.168.0.104:9000"); FileSystem fs = FileSystem.get(conf); //存在的情况下会覆盖之前的目录 boolean success = fs.mkdirs(new Path("/xiaol")); System.out.PRintln(success); } }
Exception in thread "main" org.apache.hadoop.security.AccessControlException: Permission denied: user=xiaol, access=WRITE, inode="/xiaol":root:supergroup:drwxr-xr-x
在hdfs的配置文件中,将dfs.permissions.enabled修改为False
hadoop fs -chmod 777 /
hadoop在访问hdfs的时候会进行权限认证,取用户名的过程是这样的:
读取HADOOP_USER_NamE系统环境变量,如果不为空,那么拿它作username,如果为空
读取HADOOP_USER_NAME这个java环境变量,如果为空
从com.sun.security.auth.NTUserPrincipal或者com.sun.security.auth.Unixprincipal的实例获取username。
如果以上尝试都失败,那么抛出异常LoginException("Can’t find user name")
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import java.util.Properties; public class TestHDFS { public static void main(String[] args) throws Exception{ Properties properties = System.getProperties(); properties.setProperty("HADOOP_USER_NAME", "root"); Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://192.168.0.104:9000"); FileSystem fs = FileSystem.get(conf); //存在的情况下会覆盖之前的目录 boolean success = fs.mkdirs(new Path("/xiaol")); System.out.println(success); } }
这其实是个漏洞,如果用户使用root或者其他目录的用户名,就可以对相应的目录进行任何操作,所以还是很危险的。
以上是脚本宝典为你收集整理的org.apache.hadoop.security.AccessControlException: Permission denied全部内容,希望文章能够帮你解决org.apache.hadoop.security.AccessControlException: Permission denied所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。