热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Hive远程链接(hiveserver2/beeline)

前言在生产中,我们不可能每次都登陆到Hive安装的机器上进行操作.在本章内,我们就介绍下Hive远程链接操作.远程链接HiveServerHive服务器是通过Thrift协议进

前言

在生产中, 我们不可能每次都登陆到Hive安装的机器上进行操作. 在本章内, 我们就介绍下Hive远程链接操作.



远程链接Hive Server

Hive服务器是通过Thrift协议进行约定调用的. 我们通过启动bin/hiveserver2来启动服务端的操作. 通过bin/beeline来启动客户端.

PS: 历史版本貌似通过hive hiveserver来启动版本1, 个人猜测可能是因为Hadoop2.x的架构上使用Yarn作为资源调度了, 导致Hive也跟着升级了.

服务端

^Clocalhost:bin Sean$ ./hiveserver2
2019-04-07 17:20:11: Starting HiveServer2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/Sean/Software/Hive/apache-hive-2.3.4-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/Sean/Software/hadoop/hadoop-2.7.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]

客户端

localhost:bin Sean$ ./beeline
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/Sean/Software/Hive/apache-hive-2.3.4-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/Sean/Software/hadoop/hadoop-2.7.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]
Beeline version 2.3.4 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000
Connecting to jdbc:hive2://localhost:10000
Enter username for jdbc:hive2://localhost:10000: Sean
Enter password for jdbc:hive2://localhost:10000: *********
Connected to: Apache Hive (version 2.3.4)
Driver: Hive JDBC (version 2.3.4)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000> show databases;
+----------------+
| database_name |
+----------------+
| default |
| flow |
+----------------+
2 rows selected (1.556 seconds)
0: jdbc:hive2://localhost:10000> use flow;
No rows affected (0.384 seconds)
0: jdbc:hive2://localhost:10000> show tables;
+---------------+
| tab_name |
+---------------+
| flowcount |
| t_phone_type |
+---------------+
2 rows selected (0.155 seconds)

  • 链接 !connect jdbc:hive2://localhost:10000
  • 输入当前用户的用户名与密码.(启动hiveserver2程序的用户.)(当然使用其他的配置也可以.)



Others

看到有配置Hive的运行目录等的配置. 一并记录如下:




Q & A

当然, 我在试验的过程中, 也不是一帆风顺的. 也稍微遇到一些的问题.

Q1: 远程登陆用户验证异常

Enter username for jdbc:hive2://localhost:10000:
Enter password for jdbc:hive2://localhost:10000:
19/04/07 16:17:36 [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: Sean is not allowed to impersonate anonymous (state=08S01,code=0)

解决办法: 本来以为,默认用户登陆就不需要任何配置的. 后来发现想多了. 还是要输入某些用户的. 输入hiveserver2运行程序的当前用户重试即可.


Q2: 远程登陆用户验证异常

beeline> !connect jdbc:hive2://localhost:10000
Connecting to jdbc:hive2://localhost:10000
Enter username for jdbc:hive2://localhost:10000: Sean
Enter password for jdbc:hive2://localhost:10000: *********
19/04/07 16:19:57 [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: Sean is not allowed to impersonate Sean (state=08S01,code=0)

解决办法: 更改了,输入用户的用户名和密码后. 它还是不让我登陆. 有点难受. 查询后, 原有有2点:

  1. 是因为到Hive到Hadoop的超级用户配置没有配置.
  2. Hive默认端口没开.(这个应该不用开, 只是我的电脑上有这个问题.)

具体操作:
解决1. 更改hadoop/etc/core-site.xml文件的配置. (中间的proxyuser.x.hostx为你的用户.)

hadoop.proxyuser.Sean.hosts*hadoop.proxyuser.Sean.groups*

解决2. hive-site.xml

hive.server2.thrift.port10000Port number of HiveServer2 Thrift interface when hive.server2.transport.mode is 'binary'.


Q2: 删除表操作报错.
服务端报错:

localhost:bin Sean$ ./hiveserver2
2019-04-07 17:13:30: Starting HiveServer2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/Sean/Software/Hive/apache-hive-2.3.4-b in/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/Sean/Software/hadoop/hadoop-2.7.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]
FAILED: Execution Error, return code 1 from >org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:You have >an error in your SQL syntax; check the manual that corresponds to your >MySQL server version for the right syntax to use near 'OPTION >SQL_SELECT_LIMIT=DEFAULT' at line 1)
FAILED: SemanticException Unable to fetch table t_phone_type. You have an >error in your SQL syntax; check the manual that corresponds to your MySQL >server version for the right syntax to use near 'OPTION >SQL_SELECT_LIMIT=DEFAULT' at line 1

客户端报错:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1at sun.reflect.GeneratedConstructorAccessor60.newInstance(Unknown Source)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)at com.mysql.jdbc.Util.getInstance(Util.java:381)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)at com.mysql.jdbc.StatementImpl.executeSimpleNonQuery(StatementImpl.java:1531)at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1433)at com.mysql.jdbc.ConnectionImpl.getTransactionIsolation(ConnectionImpl.java:3216)at com.jolbox.bonecp.ConnectionHandle.getTransactionIsolation(ConnectionHandle.java:825)at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:427)at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getXAResource(ConnectionFactoryImpl.java:361)at org.datanucleus.store.connection.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:316)at org.datanucleus.store.connection.AbstractConnectionFactory.getConnection(AbstractConnectionFactory.java:84)at org.datanucleus.store.AbstractStoreManager.getConnection(AbstractStoreManager.java:347)at org.datanucleus.store.AbstractStoreManager.getConnection(AbstractStoreManager.java:310)at org.datanucleus.store.rdbms.query.JDOQLQuery.performExecute(JDOQLQuery.java:591)at org.datanucleus.store.query.Query.executeQuery(Query.java:1855)at org.datanucleus.store.query.Query.executeWithArray(Query.java:1744)at org.datanucleus.api.jdo.JDOQuery.executeInternal(JDOQuery.java:368)... 53 more (state=08S01,code=1)
0: jdbc:hive2://localhost:10000> DROP TABLE t_phone_type;

解决办法: 读异常, 感觉是Mysql关键字问题. 经过网上搜索, 发现是Mysql-conncetor包的问题.hive/lib mysql-connector-java-5.1.08.jar 替换为 mysql-connector-java-5.1.44.jar后. 重启hiveserver2解决.
Reference :
[1]. 使用hive OPTION SQL_SELECT_LIMIT=DEFAULT
[2]. 【mysql案例】Java程序访问Mysql报错’OPTION SQL_SELECT_LIMIT=XXX’
[3]. check the manual that corresponds to your MySQL server version for the right syntax to use near
[4]. Hive删除表




Reference

[1]. [Hive]那些年我们踩过的Hive坑

[2]. beeline连接hiveserver2报错:User: root is not allowed to impersonate root

[3]. hadoop组件—数据仓库(五)—通过JDBC连接hive的thrift或者hiveserver2

[4]. HIVE2 :beeline连接设置用户名和密码注意问题

Hive设置连接用户名和密码


推荐阅读
  • HDFS2.x新特性
    一、集群间数据拷贝scp实现两个远程主机之间的文件复制scp-rhello.txtroothadoop103:useratguiguhello.txt推pushscp-rr ... [详细]
  •     这里使用自己编译的hadoop-2.7.0版本部署在windows上,记得几年前,部署hadoop需要借助于cygwin,还需要开启ssh服务,最近发现,原来不需要借助cy ... [详细]
  • Hadoop源码解析1Hadoop工程包架构解析
    1 Hadoop中各工程包依赖简述   Google的核心竞争技术是它的计算平台。Google的大牛们用了下面5篇文章,介绍了它们的计算设施。   GoogleCluster:ht ... [详细]
  • 【转】腾讯分析系统架构解析
    TA(TencentAnalytics,腾讯分析)是一款面向第三方站长的免费网站分析系统,在数据稳定性、及时性方面广受站长好评,其秒级的实时数据更新频率也获得业界的认可。本文将从实 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 基于Axis、XFire、CXF的webservice客户端调用示例
    本文介绍了如何使用Axis、XFire、CXF等工具来实现webservice客户端的调用,以及提供了使用Java代码进行调用的示例。示例代码中设置了服务接口类、地址,并调用了sayHello方法。 ... [详细]
  • 一次上线事故,30岁+的程序员踩坑经验之谈
    本文主要介绍了一位30岁+的程序员在一次上线事故中踩坑的经验之谈。文章提到了在双十一活动期间,作为一个在线医疗项目,他们进行了优惠折扣活动的升级改造。然而,在上线前的最后一天,由于大量数据请求,导致部分接口出现问题。作者通过部署两台opentsdb来解决问题,但读数据的opentsdb仍然经常假死。作者只能查询最近24小时的数据。这次事故给他带来了很多教训和经验。 ... [详细]
  • 本文介绍了在sqoop1.4.*版本中,如何实现自定义分隔符的方法及步骤。通过修改sqoop生成的java文件,并重新编译,可以满足实际开发中对分隔符的需求。具体步骤包括修改java文件中的一行代码,重新编译所需的hadoop包等。详细步骤和编译方法在本文中都有详细说明。 ... [详细]
  • 本文整理了Java中org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc.getTypeInfo()方法的一些代码示例,展 ... [详细]
  • Hadoop2.6.0 + 云centos +伪分布式只谈部署
    3.0.3玩不好,现将2.6.0tar.gz上传到usr,chmod-Rhadoop:hadophadoop-2.6.0,rm掉3.0.32.在etcp ... [详细]
  • Maven构建Hadoop,
    Maven构建Hadoop工程阅读目录序Maven安装构建示例下载系列索引 序  上一篇,我们编写了第一个MapReduce,并且成功的运行了Job,Hadoop1.x是通过ant ... [详细]
  • 什么是大数据lambda架构
    一、什么是Lambda架构Lambda架构由Storm的作者[NathanMarz]提出,根据维基百科的定义,Lambda架构的设计是为了在处理大规模数 ... [详细]
  • LVS-DR直接路由实现负载均衡示例
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • CentOS 7配置SSH远程访问及控制
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • MR程序的几种提交运行模式本地模型运行1在windows的eclipse里面直接运行main方法,就会将job提交给本地执行器localjobrunner执行-- ... [详细]
author-avatar
我很丑但我可以很温柔
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有