hive-2.1.1安装指南

来源:互联网 发布:大连东芝医疗知乎 编辑:程序博客网 时间:2024/06/11 16:21

本文介绍hive版本2安装的整个过程
一、介绍hive metastore的三种配置:
1、内嵌模式:embedded metastore database(derby)
2、本地模式:本地元存储 local metastore database
3、远程模式:远程元存储 remote metastore database
metadata 即元数据。元数据包括用Hive创建的database、table等元数据信息。元数据存储在关系型数据库中,比如:derby、mysql。
Metastore的作用:客户端连接metastore服务,metastore再去连接mysql数据库来存取元数据。有了metastore服务后,就可以有多个客户端同事连接。

区别:
* 内嵌模式使用的是内嵌的Derby数据库来存储元数据,也不需要额外起metastore服务,默认配置并简单,但是只能一个客户端连接,使用实验,不适用生产。
* 本地模式和远程模式都采用外部数据库来存储元数据,在这里我用的是mysql。
* 本地模式和远程模式的区别:本地元数据不需要单独起metastore服务,用的是跟hive在同一进程里的metastore服务。远程元存储需要单独起metastore服务,然后每个客户端都在配置文件里配置连接到metastore服务。远程元存储的metastore服务和hive运行在不同的进程里。
生产环境建议用远程元存储来配置Hive Metastore

这里安装mysql就不在赘述了。直接yum安装mysql就行;
二、安装hive
在apache官网上下载hive http://mirror.bit.edu.cn/apache/hive/hive-2.1.1/

cd /home/bigdata/BIDatatar -zxvf apache-hive-2.1.1-bin.tar.gzmv apache-hive-2.1.1/ hive

将mysql-connector-java-5.1.40.jar包上传至hive的lib目录下面
hive0.12版本之前Hive和Hbase的外表关联需要Hive与Hbase下的lib的jar包版本统一

三、配置
配置mysql
1、service mysqld start
mysql 进入数据库界面
2、创建需要的用户和metadata数据库

mysql> create user 'hive' identified by 'mysql';mysql> grant all privileges on *.* to 'hive'@'%' with grant option;mysql> grant all privileges on *.* to hive@dd1 identified by 'mysql';mysql> flush privileges;mysql> exit``

[root@dd1 ~]# mysql -h dd1 -u hive -p
输入密码:
mysql> create database hive;

配置hdfs:    1、创建hive库:

hadoop fs -mkdir /hive
hadoop fs -mkdir /hive/warehouse
hadoop fs -mkdir /hive/scratchdir
hadoop fs -mkdir /hive/log
hadoop fs -mkdir /hive/tmp

2、修改环境变量HIVE_HOME=/srv/BigData/BIData/hivePATH=$JAVA_HOME/bin:$PATH:$HIVE_HOME/binexport JAVA_HOME  PATH  HIVE_HOME

3、hive配置

cd /srv/BigData/BIData/hive/confcp hive-env.sh.template hive-env.sh vi hive-env.sh 

添加:

export HADOOP_HOME=/srv/BigData/BIData/hadoop-2.7.3export HIVE_CONF_DIR=/srv/BigData/BIData/hive/confexport HIVE_AUX_JARS_PATH=/srv/BigData/BIData/hive/lib

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


hive.metastore.warehouse.dir
hdfs://bi/hive/warehouse
location of default database for the warehouse


hive.exec.scratchdir
hdfs://bi/hive/scratchdir
HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an H
DFS scratch dir: {hive.exec.scratchdir}/<username> is created, with{hive.scratch.dir.permission}.


hive.querylog.location
/srv/BigData/BIData/hive/data/log/hive
Location of Hive run time structured log file


hive.conf.hidden.list
javax.jdo.option.ConnectionPassword,hive.server2.keystore.password
Comma separated list of configuration options which should not be read by normal user like passwords


javax.jdo.option.ConnectionURL
jdbc:mysql://10.20.88.111:3306/hive?characterEncoding=UTF-8&createDatabaseIfNotExist=true

JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.


javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore


javax.jdo.option.ConnectionUserName
hive
Username to use against metastore database


hive.server2.logging.operation.log.location
/srv/BigData/BIData/hive/data/tmp/operation_logs
Top level directory where operation logs are stored if logging functionality is enabled


hive.exec.local.scratchdir
/srv/BigData/BIData/hive/data/tmp/scratchdir
Local scratch space for Hive jobs


hive.downloaded.resources.dir
/srv/BigData/BIData/hive/data/tmp/${hive.session.id}_resources
Temporary local directory for added resources in the remote file system.

cp hive-log4j2.properties.template hive-log4j2.properties
cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
同时把这两个log文件的log.dir改了
vi hive-log4j2.properties && hive-exec-log4j2.properties

property.hive.log.level = INFOproperty.hive.root.logger = DRFAproperty.hive.log.dir = /srv/BigData/BIData/hive/logproperty.hive.log.file = hive.logproperty.hive.perflogger.log.level = INFO

四、初始化和启动hive

1、首次启动hive需要初始化
使用schematool初始化(要保证hadoop集群已经启动)

schematool -dbType mysql -initSchema

2、启动hive的metastore服务

hive  --service metastore

3、输入hive命令打开一个终端,也可以打开多个
测试:
这里写图片描述