使用hive客户端的hdfs权限认证: Permission denied: user=root...

时间:2025-05-15 07:48:33

原因:hdfs上没有root用户,也没有对应的文件夹/user/root

会默认以root身份去将作业写入hdfs文件系统中,对应的也就是 HDFS 上的/user/xxx , 我的为/user/root,   由于 root用户对hdfs目录并没有写入权限,所以导致异常的发生。而hdfs才有权限创建/user/root

解决方法:

1、第一种

在hdfs的配置文件中,将修改为False(不推荐)

2、第二种

执行这样的操作,使用hdfs用户(最高权限)

hadoop dfs -mkdir -p /user/root(如果路径存在可不执行)

hadoop dfs -chown root:hdfs /user/root(如果所属用户一致可不执行)
hadoop dfs -chmod 777 /user/root(如果执行上面操作已解决可不执行,我没有走)

3.第三种

vim /etc/profile

添加:export HADOOP_USER_NAME=hdfs(hdfs为最高权限)
source /etc/profile(记得执行,以保证立即生效)

也可以执行 sed -i '$a export HADOOP_USER_NAME=hdfs' ,记得也要source一下

注意:root可以是其他的用户(路径),如报错是/user/xxx,将root换成xxx即可。

第二种与第三种区别

  第二种 第三种
host 全集群的hosts都可以访问没有问题 只有做了环境变量配置的主机可用
root用户调用资源 root用户可以调用hdfs资源 root不能调用资源,如果计算是出现需要使用root用户调用的资源一样会报错
root执行hdfs命令 不能

我这里采用的是2,但是我有一个的后台与需要root执行hdfs命令,所以在采用2的同时,在所在的机器也采用了3,也就是2+3的模式。

成功:

[root@pc1 ~]# hive
WARNING: Use "yarn jar" to launch YARN applications.

Logging initialized using configuration in file:/etc/hive/2.4.2.0-258/0/
hive>

报错:

[root@pc1 ~]# hive
WARNING: Use "yarn jar" to launch YARN applications.

Logging initialized using configuration in file:/etc/hive/2.4.2.0-258/0/
Exception in thread "main" : : Permission denied: user=root, access=WRITE, inode="/user/root":hdfs:hdfs:drwxr-xr-x
    at (:319)
    at (:292)
    at (:213)
    at (:190)
    at (:1780)
    at (:1764)
    at (:1747)
    at (:71)
    at (:3972)
    at (:1081)
    at (:630)
    at $ClientNamenodeProtocol$()
    at $Server$(:616)
    at $(:969)
    at $Handler$(:2206)
    at $Handler$(:2202)
    at (Native Method)
    at (:422)
    at (:1709)
    at $(:2200)

    at (:516)
    at (:680)
    at (:624)
    at .invoke0(Native Method)
    at (:62)
    at (:43)
    at (:498)
    at (:221)
    at (:136)
Caused by: : Permission denied: user=root, access=WRITE, inode="/user/root":hdfs:hdfs:drwxr-xr-x
    at (:319)
    at (:292)
    at (:213)
    at (:190)
    at (:1780)
    at (:1764)
    at (:1747)
    at (:71)
    at (:3972)
    at (:1081)
    at (:630)
    at $ClientNamenodeProtocol$()
    at $Server$(:616)
    at $(:969)
    at $Handler$(:2206)
    at $Handler$(:2202)
    at (Native Method)
    at (:422)
    at (:1709)
    at $(:2200)

    at .newInstance0(Native Method)
    at (:62)
    at (:45)
    at (:423)
    at (:106)
    at (:73)
    at (:3066)
    at (:3034)
    at $(:1105)
    at $(:1101)
    at (:81)
    at (:1101)
    at (:1094)
    at (:1877)
    at (:783)
    at (:877)
    at (:341)
    at (:162)
    at (:117)
    at (:513)
    ... 8 more
Caused by: (): Permission denied: user=root, access=WRITE, inode="/user/root":hdfs:hdfs:drwxr-xr-x
    at (:319)
    at (:292)
    at (:213)
    at (:190)
    at (:1780)
    at (:1764)
    at (:1747)
    at (:71)
    at (:3972)
    at (:1081)
    at (:630)
    at $ClientNamenodeProtocol$()
    at $Server$(:616)
    at $(:969)
    at $Handler$(:2206)
    at $Handler$(:2202)
    at (Native Method)
    at (:422)
    at (:1709)
    at $(:2200)

    at (:1426)
    at (:1363)
    at $(:229)
    at .$(Unknown Source)
    at (:560)
    at .invoke0(Native Method)
    at (:62)
    at (:43)
    at (:498)
    at (:256)
    at (:104)
    at .$(Unknown Source)
    at (:3064)
    ... 21 more