转至:https://i.cnblogs.com/EditPosts.aspx?opt=1

一、Hive 运行模式

与 Hadoop 类似,Hive 也有 3 种运行模式:

1. 内嵌模式

将元数据保存在本地内嵌的 Derby 数据库中,这是使用 Hive 最简单的方式。但是这种方式缺点也比较明显,因为一个内嵌的 Derby 数据库每次只能访问一个数据文件,这也就意味着它不支持多会话连接。

2. 本地模式

这种模式是将元数据保存在本地独立的数据库中(一般是 MySQL),这用就可以支持多会话和多用户连接了。

3. 远程模式

此模式应用于 Hive 客户端较多的情况。把 MySQL 数据库独立出来,将元数据保存在远端独立的 MySQL 服务中,避免了在每个客户端都安装 MySQL 服务从而造成冗余浪费的情况。

二、下载安装 Hive

http://hive.apache.org/downloads.html

tar -xzvf apache-hive-2.1.1-bin.tar.gz    ##解压

三、配置系统环境变量
修改 /etc/profile 文件  vi /etc/profile 来修改(root用户操作):
  1. 设置 Hive环境变量
  2. # Hive environment
  3. export HIVE_HOME=/home/hadoop/cloud/apache-hive-2.1.1-bin
  4. export PATH=$HIVE_HOME/bin:$HIVE_HOME/conf:$PATH
  1. 使环境变量生效:
  2. source /etc/profile

四、内嵌模式

(1)修改 Hive 配置文件

$HIVE_HOME/conf 对应的是 Hive 的配置文件路径,类似于之前学习的Hbase, 该路径下的 hive-site.xml 是 Hive 工程的配置文件。默认情况下,该文件并不存在,我们需要拷贝它的模版来实现:

  1. cp hive-default.xml.template hive-site.xml

hive-site.xml 的主要配置有:

  • hive.metastore.warehouse.dir
    该参数指定了 Hive 的数据存储目录,默认位置在 HDFS 上面的 /user/hive/warehouse 路径下。

  • hive.exec.scratchdir
    该参数指定了 Hive 的数据临时文件目录,默认位置为 HDFS 上面的 /tmp/hive 路径下。

同时我们还要修改 Hive 目录下 /conf/hive-env.sh 文件(请根据自己的实际路径修改),该文件默认也不存在,同样是拷贝它的模版来修改:
cp hive-env.sh.template  hive-env.sh
  1. # Set HADOOP_HOME to point to a specific hadoop install directory
  2. HADOOP_HOME=/home/hadoop/cloud/hadoop-2.7.3
  3. # Hive Configuration Directory can be controlled by:
  4. export HIVE_CONF_DIR=/home/hadoop/cloud/apache-hive-2.1.1-bin/conf
  5. # Folder containing extra ibraries required for hive compilation/execution can be controlled by:
  6. export HIVE_AUX_JARS_PATH=/home/hadoop/cloud/apache-hive-2.1.1-bin/lib
(2)创建必要目录

前面我们看到 hive-site.xml 文件中有两个重要的路径,切换到 hadoop 用户下查看 HDFS 是否有这些路径:

  1. hadoop fs -ls /
没有发现上面提到的路径,因此我们需要自己新建这些目录,并且给它们赋予用户写(W)权限。
  1. $HADOOP_HOME/bin/hadoop fs -mkdir -p /user/hive/warehouse
  2. $HADOOP_HOME/bin/hadoop fs -mkdir -p /tmp/hive/
  3. hadoop fs -chmod 777 /user/hive/warehouse
  4. hadoop fs -chmod 777 /tmp/hive
检查是否新建成功 hadoop fs -ls / 以及 hadoop fs -ls /user/hive/ :

(3)修改 io.tmpdir 路径

同时,要修改 hive-site.xml 中所有包含 ${system:java.io.tmpdir} 字段的 value 即路径(vim下 / 表示搜索,后面跟你的关键词,比如搜索 hello,则为 /hello , 再回车即可),你可以自己新建一个目录来替换它,例如 /home/Hadoop/cloud/apache-hive-2.1.1-bin/iotmp

  1. mkdir /home/hadoop/cloud/apache-hive-2.1.1-bin/iotmp
  2. chmod 777 /home/hadoop/cloud/apache-hive-2.1.1-bin/iotmp
  3. 把hive-site.xml 中所有包含 ${system:Java.io.tmpdir}替换成/home/hadoop/cloud/apache-hive-2.1.1-bin/iotmp
全局替换命令 先按Esc键  再同时按shift+:把以下替换命令粘贴按回车即可全局替换
  1. %s#${system:java.io.tmpdir}#/home/hadoop/cloud/apache-hive-2.1.1-bin/iotmp#g
修改${system:user.name}为自己的用户名
(4)运行 Hive
  1. ./bin/hive
报错

解决办法:./bin/schematool -initSchema -dbType derby

报错

解决方法:删除/home/hadoop/cloud/apache-hive-2.1.1-bin目录下 rm -rf metastore_db/ 在初始化:./bin/schematool -initSchema -dbType derby
重新运行

./bin/hive

报错

/tem/hive 没写的权限

Hive本身自带一个数据库,但是有弊端,hive本身数据库,每次只允许一个用户登录

mysql安装:http://blog.csdn.net/u014695188/article/details/51532410

设置mysql关联hive

修改配置文件

### 创建hive-site.xml文件 
在hive/conf/目录下创建hive-site.xml文件

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <configuration>
  4. <property>
  5. <name>javax.jdo.option.ConnectionURL</name>
  6. <value>jdbc:mysql://192.168.169.134:3306/hive?createDatabaseIfNotExist=true</value>
  7. </property>
  8. <property>
  9. <name>javax.jdo.option.ConnectionDriverName</name>
  10. <value>com.mysql.jdbc.Driver</value>
  11. </property>
  12. <property>
  13. <name>javax.jdo.option.ConnectionUserName</name>
  14. <value>root</value>
  15. </property>
  16. <property>
  17. <name>javax.jdo.option.ConnectionPassword</name>
  18. <value>123456</value>
  19. </property>
  20. <property>
  21. <name>hive.metastore.schema.verification</name>
  22. <value>false</value>
  23. <description>
  24. Enforce metastore schema version consistency.
  25. True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic
  26. schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures
  27. proper metastore schema migration. (Default)
  28. False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
  29. </description>
  30. </property>
  31. </configuration>

报错:Caused by: MetaException(message:Version information not found in metastore. )

解决:hive-site.xml加入

  1. <property>
  2. <name>hive.metastore.schema.verification</name>
  3. <value>false</value>
  4. <description>
  5. Enforce metastore schema version consistency.
  6. True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic
  7. schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures
  8. proper metastore schema migration. (Default)
  9. False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
  10. </description>
  11. </property>

报错:缺少mysql jar包

解决:将其(如mysql-connector-Java-5.1.15-bin.jar)拷贝到$HIVE_HOME/lib下即可。

报错:

  1. Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized.
  2. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed,
  3. don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)

解决:

  1. #数据库的初始化。
  2. bin/schematool -initSchema -dbType mysql

启动:

  1. bin/hive

启动后mysql 多了hive 数据库

测试

创建数据库

create database db_hive_test;
 

创建测试表

use db_hive_test;

create table student(id int,name string) row format delimited fields terminated by '\t';

加载数据到表中

新建student.txt 文件写入数据(id,name 按tab键分隔)

vi student.txt

  1. 1001    zhangsan
  2. 1002    lisi
  3. 1003    wangwu
  4. 1004    zhaoli

load data local inpath '/home/hadoop/student.txt' into table  db_hive_test.student

查询表信息

select * from student;

查看表的详细信息

desc formatted student;

通过ui页面查看创建的数据位置

http://192.168.169.132:50070/explorer.html#/user/hive/warehouse/db_hive_test.db

通过Mysql查看创建的表

查看hive的函数

show functions;

查看函数详细信息

desc function sum; 
desc function extended

hive2.1.1安装部署的更多相关文章

  1. Ubuntu16.04 和 hadoop2.7.3环境下 hive2.1.1安装部署

    参考文献: http://blog.csdn.NET/reesun/article/details/8556078 http://blog.csdn.Net/zhongguozhichuang/art ...

  2. Hive之一:hive2.1.1安装部署

    一.Hive 运行模式 与 Hadoop 类似,Hive 也有 3 种运行模式: 1. 内嵌模式 将元数据保存在本地内嵌的 Derby 数据库中,这是使用 Hive 最简单的方式.但是这种方式缺点也比 ...

  3. CentOS下SparkR安装部署:hadoop2.7.3+spark2.0.0+scale2.11.8+hive2.1.0

    注:之前本人写了一篇SparkR的安装部署文章:SparkR安装部署及数据分析实例,当时SparkR项目还没正式入主Spark,需要自己下载SparkR安装包,但现在spark已经支持R接口,so更新 ...

  4. Hive基础概念、安装部署与基本使用

    1. Hive简介 1.1 什么是Hive Hives是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能. 1.2 为什么使用Hive ① 直接使用 ...

  5. Hive 系列(一)安装部署

    Hive 系列(一)安装部署 Hive 官网:http://hive.apache.org.参考手册 一.环境准备 JDK 1.8 :从 Oracle 官网下载,设置环境变量(JAVA_HOME.PA ...

  6. 【Hadoop离线基础总结】Hive的安装部署以及使用方式

    Hive的安装部署以及使用方式 安装部署 Derby版hive直接使用 cd /export/softwares 将上传的hive软件包解压:tar -zxvf hive-1.1.0-cdh5.14. ...

  7. Apache Ranger安装部署

    1.概述 Apache Ranger提供了一个集中式的安全管理框架,用户可以通过操作Ranger Admin页面来配置各种策略,从而实现对Hadoop生成组件,比如HDFS.YARN.Hive.HBa ...

  8. Oracle安装部署,版本升级,应用补丁快速参考

    一.Oracle安装部署 1.1 单机环境 1.2 Oracle RAC环境 1.3 Oracle DataGuard环境 1.4 主机双机 1.5 客户端部署 二.Oracle版本升级 2.1 单机 ...

  9. KVM安装部署

    KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...

随机推荐

  1. 【leetcode刷题笔记】Add Binary

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  2. HTTPS与HTTP

    HTTP HyperText Transfer Protocol超文本传输协议 HTTPS HyperText Transfer Protocol over Secure Socket Layer 基 ...

  3. mono上运行程序常见问题

    1. System.BadImageFormatException: Invalid method header local vars signature token 0x 65d5b2File na ...

  4. HDU 4417 Super Mario(2012杭州网络赛 H 离线线段树)

    突然想到的节约时间的方法,感觉6翻了  给你n个数字,接着m个询问.每次问你一段区间内不大于某个数字(不一定是给你的数字)的个数 直接线段树没法做,因为每次给你的数字不一样,父节点无法统计.但是离线一 ...

  5. Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??错误

    启动项目的时候发现tomcat跑不起来.后台输出错误Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í?? 发现是ecli ...

  6. 纯CSS3实现的动感菜单效果

    1. [代码] 纯CSS3实现的动感菜单效果 <!DOCTYPE html><head><meta http-equiv="Content-Type" ...

  7. Linux配置redis服务器

    1.安装redis 2.开启6379端口,使外部机器能够访问 3.

  8. 机器学习(十七)— SVD奇异值分解

    奇异值分解(Singular Value Decomposition,以下简称SVD)是在机器学习领域广泛应用的算法,它不光可以用于降维算法中的特征分解,还可以用于推荐系统,以及自然语言处理等领域.是 ...

  9. hibernate复习第(4)天

    1.hibernate的映射类型.hbm.xml中property中的type属性.这个type属性是表示持久化类中的属性对应数据库中的什么数据类型,用来构建一种映射type的可选值:hibernat ...

  10. windows下安装 postgresql

    1. 下载PostgreSQL的源代码.解压. 2. 在Windows平台下编译需要跳过一个权限的检测,否则在编译的时候可能会出现错误. 在\src\backend\main\main.c文件中将   ...