Hive| beeline连接的Invalid URL

摘要: 今天在使用hive的client工具beeline时遇到了一个Invalid URL的错误。环境信息如下: hiveclient: bd23 hiveserver2: cloud011 hiveclient所在主机的jdk 1.

今天在使用hive的client工具beeline时遇到了一个Invalid URL的错误。环境信息如下:
hiveclient: bd23
hiveserver2: cloud011

hiveclient所在主机的jdk 1.7_51,hive 0.12和hadoop 2.3.0是从服务器端拷贝过来的,环境变量一切OK.
执行连接报了Invalid URL的错误:
$ beeline
Beeline version 0.12.0 by Apache Hive
beeline> !connect jdbc:hive2://cloud011:10000
scan complete in 2ms
Connecting to jdbc:hive2://cloud011:10000
Enter username for jdbc:hive2://cloud011:10000:
Enter password for jdbc:hive2://cloud011:10000:
Error: Invalid URL: jdbc:hive2://cloud011:10000 (state=08S01,code=0)

开始的一段时间都在纠结这个jdbc的URL格式问题,后来在cloudra论坛上找到了一个方法,
直接调用的jdbc:hive2的驱动测试是正常的,证明CLASSPATH等环境变量没有问题。

$ beeline -u jdbc:hive2://

scan complete in 3ms

Connecting to jdbc:hive2://

14/03/18 00:11:48 INFO HiveMetaStore.audit: ugi=bjdpi ip=unknown-ip-addr cmd=get_databases: default

14/03/18 00:11:48 INFO cli.CLIService: SessionHandle [f8c185f0-e491-4f8a-88fa-7f0be7089d23]: openSession()

14/03/18 00:11:48 INFO cli.CLIService: SessionHandle [f8c185f0-e491-4f8a-88fa-7f0be7089d23]: getInfo()

Connected to: Hive (version 0.12.0)

Driver: Hive (version 0.12.0)

Transaction isolation: TRANSACTION_REPEATABLE_READ

Beeline version 0.12.0 by Apache Hive

|

这时候感觉很可能不是客户端的问题,矛头指向服务器端:

netstat -lanp | grep 10000

tcp 0 0 127.0.0.1:10000 0.0.0.0:* LISTEN 24553/java

发现绑定的主机地址是localhost,而localhost的地址是127.0.0.1。这应该就是问题所在,从服务器本地测试:

$ beeline

Beeline version 0.12.0 by Apache Hive

beeline> !connect jdbc:hive2://172.19.1.11:10000

scan complete in 3ms

Connecting to jdbc:hive2://172.19.1.11:10000

Enter username for jdbc:hive2://172.19.1.11:10000:

Enter password for jdbc:hive2://172.19.1.11:10000:

Error: Invalid URL: jdbc:hive2://172.19.1.11:10000 (state=08S01,code=0)

0: jdbc:hive2://172.19.1.11:10000> !connect jdbc:127.0.0.1:10000

scan complete in 0ms

scan complete in 1100ms

No known driver to handle “jdbc:127.0.0.1:10000”

0: jdbc:hive2://172.19.1.11:10000> !connect jdbc:hive2://127.0.0.1:10000

Connecting to jdbc:hive2://127.0.0.1:10000

Enter username for jdbc:hive2://127.0.0.1:10000:

Enter password for jdbc:hive2://127.0.0.1:10000:

Connected to: Hive (version 0.12.0)

Driver: Hive (version 0.12.0)

Transaction isolation: TRANSACTION_REPEATABLE_READ

1: jdbc:hive2://127.0.0.1:10000>

|

连接成功!

下面就要把参数改一下,然后重启服务

<property>

<name>hive.server2.thrift.bind.host</name>

<value>localhost</value>

<description>Bind host on which to run the HiveServer2 Thrift interface.

Can be overridden by setting $HIVE_SERVER2_THRIFT_BIND_HOST</description>

</property>

|

重启服务后检查监听地址,这次是正确的了。

|

SHELL$ netstat -lanp | grep 10000

tcp 0 0 172.19.1.11:10000 0.0.0.0:* LISTEN 24553/java

|

再次在客户端主机上测试连接:

SHELL$ beeline

Beeline version 0.12.0 by Apache Hive

beeline> !connect jdbc:hive2://172.19.1.11:10000

Connecting to jdbc:hive2://172.19.1.11:10000

Enter username for jdbc:hive2://172.19.1.11:10000:

Enter password for jdbc:hive2://172.19.1.11:10000:

Connected to: Hive (version 0.12.0)

Driver: Hive (version 0.12.0)

Transaction isolation: TRANSACTION_REPEATABLE_READ

0: jdbc:hive2://172.19.1.11:10000>

|

成功。

cloudra论坛上下面有个类似的错误:
cannot connect by beeline
http://community.cloudera.com/t5/Batch-SQL-Apache-Hive/Cannot-connect-to-beeline/td-p/5723/page/3
看来当beeline连接失败的时候都会报这个invalid URL的错误,确实给定位问题带来了不小的困难。

    原文作者:志辉聊码
    原文地址: https://www.jianshu.com/p/47a4b51dc5e5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞