1. 程式人生 > 其它 >User: root is not allowed to impersonate root (state=08S01,code=0)

User: root is not allowed to impersonate root (state=08S01,code=0)

問題描述:

hadoop叢集和hive安裝成功以後,在hive安裝目錄下使用bin/hive命令進入hive介面,在裡面增刪改查都沒有問題,但是

使用bin/hiveserver2啟動hiveserver2服務,然後使用beeline(bin/beeline -u jdbc:hive2://hdp01:10000 -n xx -p xxx)連線hiveserver2報錯:

Error: Could not open client transport with JDBC Uri: jdbc:hive2://hdp01: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)

然後到網上查了一下資料,都是清一色的在hadoop的core-site.xml檔案中加入以下配置(其中root需要替換成你使用beeline命令時-n指定的值):

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

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

確實,改了core-site.xml檔案配置以後重啟hadoop叢集,使用beeline進入hiveser2服務能成功,但是在裡面對錶資料進行更改時(eg: insert),同樣還是報

Error: Could not open client transport with JDBC Uri: jdbc:hive2://hdp01: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)

顯然使用這種辦法是不行的,後來我去官方文件檢視hiveserver2配置時發現了關於impersonate (冒充)的配置選項。

解決辦法

按照官方文件配置了以後,能夠正常運行了,即使將上述配置移除以後,單獨使用hive官方文件的配置也能正常使用。

網址:https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2

關鍵字:Impersonation

原文:

By default HiveServer2 performs the query processing as the user who submitted the query. But if the following parameter is set tofalse, the query will run as the user that thehiveserver2process runs as.

hive.server2.enable.doAs – Impersonate the connected user, defaulttrue.

這句話的意思是:預設情況下HiveServer2 執行查詢時使用的使用者是提交查詢的使用者.但是如果將這個選項設定為false,查詢將會使用執行hiveserver2的使用者。

在conf/hive-site.xml中加入以下配置:

<property>
<name>hive.server2.enable.doAs </name>
<value>false</value>
</property>

然後使用命令bin/hiveserver2重新啟動hiveserver2服務,然後使用beeline連線hiveser2,然後對錶進行增刪改查都不會報錯了,同時使用beeline時都可以不用指定使用者和密碼了(bin/beeline -u jdbc:hive2://hdp01:10000)。

在此記錄和共享出來。