HiveServer2

基本概念介绍

1、HiveServer2基本介绍

HiveServer2 (HS2) is a server interface that enables remote clients to execute queries against Hive and retrieve the results (a more detailed intro here). The current implementation, based on Thrift RPC, is an improved version of HiveServer and supports multi-client concurrency and authentication. It is designed to provide better support for open API clients like JDBC and ODBC.

​ HiveServer2是一个服务接口,能够允许远程的客户端去执行SQL请求且得到检索结果。HiveServer2的实现,依托于Thrift RPC,是HiveServer的提高版本,它被设计用来提供更好的支持对于open API例如JDBC和ODBC。

HiveServer is an optional service that allows a remote client to submit requests to Hive, using a variety of programming languages, and retrieve results. HiveServer is built on Apache ThriftTM (http://thrift.apache.org/), therefore it is sometimes called the Thrift server although this can lead to confusion because a newer service named HiveServer2 is also built on Thrift. Since the introduction of HiveServer2, HiveServer has also been called HiveServer1.

​ HiveServer是一个可选的服务,只允许一个远程的客户端去提交请求到hive中。(目前已被淘汰)

2、Beeline

​ HiveServer2 supports a command shell Beeline that works with HiveServer2. It's a JDBC client that is based on the SQLLine CLI 。

​ HiveServer2提供了一种新的命令行接口,可以提交执行SQL语句。

hiveserver2的搭建使用

​ 在搭建hiveserver2服务的时候需要修改hdfs的超级用户的管理权限,修改配置如下:

--在hdfs集群的core-site.xml文件中添加如下配置文件
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
--配置完成之后重新启动集群,或者在namenode的节点上执行如下命令
hdfs dfsadmin -fs hdfs://node01:8020 -refreshSuperUserGroupsConfiguration
hdfs dfsadmin -fs hdfs://node02:8020 -refreshSuperUserGroupsConfiguration

1、独立hiveserver2模式

​ 1、将现有的所有hive的服务停止,不需要修改任何服务,在node03机器上执行hiveserver2或者hive --service hiveserver2的命令,开始启动hiveserver2的服务,hiveserver2的服务也是一个阻塞式窗口,当开启服务后,会开启一个10000的端口,对外提供服务。

​ 2、在node04上使用beeline的方式进行登录

2、共享metastore server的hiveserver2模式搭建

​ 1、在node03上执行hive --service metastore启动元数据服务

​ 2、在node04上执行hiveserver2或者hive --service hiveserver2两个命令其中一个都可以

​ 3、在任意一台包含beeline脚本的虚拟机中执行beeline的命令进行连接

HiveServer2的访问方式

1、beeline的访问方式

​ (1)beeline -u jdbc:hive2://:/ -n name

​ (2)beeline进入到beeline的命令行

​ beeline> !connect jdbc:hive2://:/ root 123

​ 注意:

​ 1、使用beeline方式登录的时候,默认的用户名和密码是不验证的,也就是说随便写用户名和密码即可

​ 2、使用第一种beeline的方式访问的时候,用户名和密码可以不输入

​ 3、使用第二种beeline方式访问的时候,必须输入用户名和密码,用户名和密码是什么无所谓

2、jdbc的访问方式

​ 1、创建普通的java项目,将hive的jar包添加到classpath中,最精简的jar包如下:

commons-lang-2.6.jar
commons-logging-1.2.jar
curator-client-2.7.1.jar
curator-framework-2.7.1.jar
guava-14.0.1.jar
hive-exec-2.3.4.jar
hive-jdbc-2.3.4.jar
hive-jdbc-handler-2.3.4.jar
hive-metastore-2.3.4.jar
hive-service-2.3.4.jar
hive-service-rpc-2.3.4.jar
httpclient-4.4.jar
httpcore-4.4.jar
libfb303-0.9.3.jar
libthrift-0.9.3.jar
log4j-1.2-api-2.6.2.jar
log4j-api-2.6.2.jar
log4j-core-2.6.2.jar
log4j-jul-2.5.jar
log4j-slf4j-impl-2.6.2.jar
log4j-web-2.6.2.jar
zookeeper-3.4.6.jar

​ 2、编辑如下代码:

package com.mashibing;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class HiveJdbcClient { private static String driverName = "org.apache.hive.jdbc.HiveDriver"; public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn = DriverManager.getConnection("jdbc:hive2://node04:10000/default", "root", "");
Statement stmt = conn.createStatement();
String sql = "select * from psn limit 5";
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1) + "-" + res.getString("name"));
}
}
}

运行之后,即可得到最终结果。

Hive Server2(五)的更多相关文章

  1. Hive扩展功能(五)--HiveServer2服务高可用

    软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...

  2. 大数据学习(12)—— Hive Server2服务

    什么是Hive Server2 上一篇我们启动了hive --service metastore服务,可以通过命令行来访问hive服务,但是它不支持多客户端同时访问,参见官网说明:HiveServer ...

  3. Hive(五)数据类型与库表操作以及中文乱码

    一.数据类型 1.基本数据类型 Hive 支持关系型数据中大多数基本数据类型 类型 描述 示例 boolean true/false TRUE tinyint 1字节的有符号整数 -128~127 1 ...

  4. Hive的五个基础介绍

    一.什么是Hive? 1.Hive是一个翻译器,SQL ---> Hive引擎 ---> MR程序 2.Hive是构建在HDFS上的一个数据仓库(Data Warehouse) Hive ...

  5. supervisor管理hive metastore和hive server2进程

    1. hive_metastore.ini [program:hive_metastore] environment = JAVA_HOME=/usr/java/jdk1..0_172-amd64,H ...

  6. Hive Tuning(五) 标准调优清单

    Hive的标准调优清单,我们可以对照着来做我们的查询优化!

  7. Hive(五)hive的高级应用

    一.视图 视图:享用基本表的数据,不会生成另外一份数据创建视图:create view view_name as select * from carss;create view carss_view ...

  8. hive学习(五) 应用案例

    1.实现struct数据结构例子 1.1创建student表 create table student( id int, info struct<name:string,age:int> ...

  9. Apache Hive (五)DbVisualizer配置连接hive

    转自:https://www.cnblogs.com/qingyunzong/p/8715250.html 一.安装DbVisualizer 下载地址http://www.dbvis.com/ 也可以 ...

随机推荐

  1. Git(5):其他用法

    分支操作 (1) 删除远程分支 $git remote add origin ssh://git@xxx.git ##如果未连接远程分支要先连接 $git push origin :<remot ...

  2. C# List方法中存储的问题

    遇到一个bug,抓耳挠塞好久都没有解决,有必要记录一下. 现在我使用了一个多维list. IList<IList<int>> list = new List<IList& ...

  3. Django模板系统-母板和继承

    母板和继承 母版 html页面,提取多个页面的公共部分 定义多个block块,需要让子页面进行填充 <head> {% block page-css %} {% endblock %} & ...

  4. 【Linux-驱动】在sysfs下创建对应的class节点---class_create

    在编写简单字符设备驱动的时候,可以使用宏class_create在sysfs下创建对应的class节点,便于用户管理设备: #define class_create(owner, name) \ ({ ...

  5. DBGridEh列宽自动适应内容的简单方法

    ///////Begin   Source      uses          Math;            function   DBGridRecordSize(mColumn:   TCo ...

  6. Java第六周课堂示例总结

    一.如果一个类中既有初始化块,又有构造方法,同时还设定了字段的初始值,谁说了算? public class InitializeBlockDemo { /** * @param args */ pub ...

  7. 面试35-删除字符串重复字符-删除出现在第二个字符串中的字符-第一个只出现一次的字符-hash表计数

    #include<iostream>#include<algorithm>#include<functional>using namespace std;char ...

  8. FFmpeg4.0笔记:采集系统声音

    Github https://github.com/gongluck/FFmpeg4.0-study/tree/master/Cff // 采集系统声音 void test_systemsound() ...

  9. C++练习 | 类的继承与派生练习(1)

    #include <iostream> #include <cmath> #include <cstring> #include <string> #i ...

  10. python_0基础开始_day09

    第九节 1,函数初始 s = "qwertyuiop"n = 0for i in s:    n += 1print(n)​lst = [1,2,3,4,5]n = 0for i ...