Hive架构简介与安装

一.Hive的出现

如何实现对SQL技术比较熟悉的程序设计人员在Hadoop平台上对海量数据进行分析?如何实现传统数据格式到Hadoop上的迁徙,如基于传统关系型数据库格式和SQl处理技术?如何实现传统数据库设计人员在Hadoop平台上使用其所熟悉的SQL技术展现其才能?如何在分布式环境下采用数据仓库技术从更多的数据中快速的获取数据的有效价值?

————Hive应景而生。

作为一种数据仓库技术,Hive能很好地查询和管理存储在分布环境下的大数据集,它提供了一系列工具,可以用来进行数据提取和转化加载,这是一种可以存储、查询和分析存储在Hadoop中的大规模数据的机制。Hive定义了简单的类SQL查询语言,称为 HQL,它允许熟悉SQL的用户查询数据。同时,这个语言也允许熟悉MapReduce开发者的开发自定义的mapper和reducer来处理内建的mapper和reducer无法完成的复杂的分析工作。

二.hive的优缺点

1.优点

1)操作接口采用类SQL语法,降低了传统数据库分析人员使用Hadoop进入大数据时代的障碍。

2)任务提交有高延迟性,适合用来处理相对静态,对实时性要求不高或离线的海量数据库集。

3)支持用户自定义函数,用户可以根据自己的需求来设计函数。

2.缺点

1)HQL表达能力有限,迭代算法无法表达

2)基于传统SQL的技术领域限制,并不适合构建复杂的机器学习算法。

3)Hive自动生成的mapreduce程序通常不够智能化

4)调优比较困难,粒度较粗

三.Hive的架构原理

(1)客户端组件:

  ①CLI:command line interface,Hive Shell命令行接口。

  ②Thrift客户端:上面的架构图里没有写上Thrift客户端,但是Hive架构的许多客户端接口是建立在Thrift客户端之上,包括JDBC和ODBC接口。

  ③WEBGUI:Hive客户端提供了一种通过网页的方式访问Hive所提供的服务。这个接口对应Hive的hwi组件(hive web interface),使用前要启动hwi服务。

  (2)服务端组件:

  Driver组件:该组件包括SQL Parser、Physical Plan、Query Optimizer和Executor,它的作用是将我们写的HiveQL(类SQL)语句进行解析、编译优化,生成执行计划,然后调用底层的mapreduce计算框架

  ②Metastore组件:元数据服务组件,其中存储的元数据又称为作用于Hive和Hadoop之间的抽象接口属性内容,以metastore内容的形式存储在数据库中,用来限定Hive如何进行格式化操作Hadoop中获取到任何非结构化数据,hive支持的关系数据库有derby、mysql。元数据对于hive十分重要,因此hive支持把metastore服务独立出来,安装到远程的服务器集群里,从而解耦hive服务和metastore服务,保证hive运行的健壮性

  ③Thrift服务:Thrift是facebook开发的一个软件框架,它用来进行可扩展且跨语言的服务的开发,hive集成了该服务,能让不同的编程语言调用hive的接口。

四.Hive的基本安装与使用

1.安装

系统:centos6.5 Hadoop2.7.1

准备:apache-hive-1.2.2-bin.tar.gz

将该tar解压到/root/apps目录下,并mv重命名:

 配置HIVE_HOME。

配置hive-env.sh

 

hive启动成功。

2.将本地文件导入Hive

在本地创建一张student.txt

在Hive中创建一个student表

导入本地student.txt到student表

五.将metastore配置在mysql中

metastore包括两部分:服务和后台数据的存储。默认情况下,metastore服务和Hive服务运行在同一JVM中,它包含一个内嵌的以本地磁盘作为存储的Derby数据库实例。

使用内嵌metastore是Hive入门最简单的方法。但是每次只有一个内嵌Derby数据库可以访问某个磁盘上的书库文件,这意味着一次只能为每个metastore打开一个Hive会话。如果试着启动第二个会话,在它试图连接metastore时,会得到以下错误信息:

Failed to start database 'metastore_db' 

如果要支持多会话,需要使用一个独立的数据库,因为metastore服务仍然和Hive服务运行在同一个进程中,但连接的确实另一个进程中运行的数据库,在同一台机器上或在远程机器上。

这就是我们要为metastore单独配置mysql的原因。

 1.安装mysql

在安装之前,我们需要将虚拟机上的mysql删除,有的话删除掉 

yum list installed | grep mysql

在线安装

yum install mysql

yum install mysql-server

 在Hive的lib目录下导入mysql-connector-java-5.1.6.jar包

安装成功后便可使用mysql

service mysqld start

mysql -uroot -p

新安装的数据库没有密码,我们enter就能进去,然后自行改密码。

set password=password("your password") 

 然后我们配置hive.site.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
--><configuration>
<property>
       <name>hive.exec.scratchdir</name>
       <value>/tmp/hive</value>
       <description>Scratch space for Hive jobs</description>
       </property>
<property>

<property>
       <name>javax.jdo.option.Multithreaded</name>
       <value>true</value>
       <description>Set this to true if multiple threads access metastore through JDO concurrently.</description>
</property>
<property>
       <name>hive.metastore.warehouse.dir</name>
       <value>hdfs://node1:9000/hive/warehouse</value>
       <description>location of default database for the warehouse</description>
</property>

       <name>javax.jdo.option.ConnectionURL</name>
       <value>jdbc:mysql://node1:3306/metastore?createDatabaseIfNotExist=true</value>
       <description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
       <name>javax.jdo.option.ConnectionDriverName</name>
       <value>com.mysql.jdbc.Driver</value>
       <description>Driver class name for a JDBC metastore</description>
</property>

<property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
        <description>username to use against metastore database</description>
</property>
<property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>############</value>
        <description>password to use against metastore database</description>
</property>
</configuration>

jdbc:mysql://node1:3306/metastore?createDatabaseIfNotExist=true 这一行的作用就是将metastore配置在mysql

然后我们重新开启mysql,发现多了这么一个数据库:

说明配置成功。 

参考:《Hadoop权威指南》

https://www.cnblogs.com/lyr999736/p/9468012.html

https://www.cnblogs.com/edisonchou/p/4426096.html

猜你喜欢

转载自blog.csdn.net/qq_39327985/article/details/84888627