hive启动异常:RuntimeException,RemoteException,User: root is not allowed to impersonate anonymous

root用户下启动Hive的多用户访问模式时,hiveserver2服务能够正常启动,但是使用beeline -u jdbc:hive2://localhost:10000启动hive客户端时,报一下错误:
并且通过jdbc操作hive时,控制台也会返回这个错误:

[root@centos ~]# beeline -u jdbc:hive2://localhost:10000
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/myapp/dev/hadoop/apache-hive-2.3.5-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/myapp/dev/hadoop/hadoop-2.8.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Connecting to jdbc:hive2://localhost:10000
19/07/30 14:22:33 [main]: WARN jdbc.HiveConnection: Failed to connect to localhost:10000
Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate anonymous (state=08S01,code=0)
Beeline version 2.3.5 by Apache Hive
beeline> 

主要报错内容是:

java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate anonymous
译:用户root不允许伪装成anonymous(hive的默认用户,默认配置可以查看)。
主要原因:是hadoop引入了一个安全伪装机制,使得hadoop 不允许上层系统直接将实际用户传递到hadoop层,而是将实际用户传递给一个超级代理,由此代理在hadoop上执行操作,避免任意客户端随意操作hadoop。

解决办法:

来自于:博文:https://www.cnblogs.com/lijinze-tsinghua/p/8331563.html

通过httpfs协议访问rest接口,以root用户包装自己用户的方式操作HDFS
首先需要开启rest接口,在hdfs-site.xml文件中加入:

<property>  
	<name>dfs.webhdfs.enabled</name>  
	<value>true</value>  
</property>

然后在core-site.xml文件中加入:

<property>
	<name>hadoop.proxyuser.root.hosts</name>
	<value>*</value>
</property>
<property>
	<name>hadoop.proxyuser.root.groups</name>
	<value>*</value>
</property>

注意配置中的root代表的是一个用户,异常[User: root is not allowed to impersonate anonymous]中User后面的用户是什么,在这里就配置什么。

hadoop.proxyuser.root.hosts 配置成*的意义,表示任意节点使用 hadoop 集群的代理用户 root 都能访问 hdfs 集群,hadoop.proxyuser.root.groups 表示代理用户的组所属。

如异常:User lisi is not allowed to impersonate…
就配置为:

<property>
    <name>hadoop.proxyuser.lisi.hosts</name>
    <value>*</value>
</property>
<property>
	<name>hadoop.proxyuser.lisi.groups</name>
	<value>*</value>
</property>

配置完成后,重启HDFS与YARN服务!!!

[root@centos hadoop-2.8.5]# sbin/stop-dfs.sh
[root@centos hadoop-2.8.5]# sbin/stop-yarn.sh
[root@centos hadoop-2.8.5]# sbin/start-dfs.sh
[root@centos hadoop-2.8.5]# sbin/start-yarn.sh

如果使用了yarn,一定要记得重启yarn服务!!!重启yarn服务!!!重启yarn服务!!!

本人就是只重启hdfs而忘了重启yarn服务,导致浪费大量时间。直到看到这篇博文才恍然醒悟!!!

posted @ 2019-07-30 14:37  IT-小浣熊  阅读(211)  评论(0)    收藏  举报