安装Hive

Posted y_zilong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装Hive相关的知识,希望对你有一定的参考价值。

前提:已配置好Hadoop,具体跟上篇Hadoop搭建

5、Hive下载安装

5.1hive下载安装

#下载链接
https://mirror.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.9/apache-hive-2.3.9-bin.tar.gz

tar -xvf apache-hive-2.3.9-bin.tar.gz

#mysql 8的java启动jar包
https://mirror.tuna.tsinghua.edu.cn/mysql/downloads/Connector-J/mysql-connector-java-8.0.26.tar.gz


#配置全局hive_home路径
[root@hadoop01 ~]$cat /etc/profile.d/hive.sh 
export HIVE_HOME=/opt/apache-hive-2.3.9-bin
export PATH=$PATH:$HIVE_HOME/bin

source /etc/profile.d/hive.sh

5.2MYSQL创建hive用户并授权

mysql> create user 'hive' identified by 'hive';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'hive'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

#使用hive用户登陆测试连接
[root@hadoop01 ~]$mysql -uhive -phive

--创建数据库
mysql> 
mysql> create database hive;
Query OK, 1 row affected (0.00 sec)

mysql> alter database hive character set latin1;
Query OK, 1 row affected (0.01 sec)
mysql> 

#下载mysql jar包,将jar包放在hive lib目录下
[root@hadoop01 ~]$cd /opt/apache-hive-2.3.9-bin/lib/
[root@hadoop01 lib]$wget https://mirror.tuna.tsinghua.edu.cn/mysql/downloads/Connector-J/mysql-connector-java-8.0.26.tar.gz
[root@hadoop01 lib]$ls mysql-connector-java-8.0.26.jar 
mysql-connector-java-8.0.26.jar

5.3Hive配置

1、升级hive中的guava依赖为hadoop版本
先备份了将hive自带的guava依赖包,然后将hadoop自带的更高版本软链过来,如果不做该操作hive命令会出错,官方一直存在这个问题
#备份
[root@hadoop01 ~]$cd /opt/apache-hive-2.3.9-bin/lib/
[root@hadoop01 lib]$mv guava-14.0.1.jar guava-14.0.1.jar-bak

#查看hadoop中guava版本
[root@hadoop01 lib]$cd /opt/hadoop-2.7.7/share/hadoop/hdfs/lib/
[root@hadoop01 lib]$ls guava-11.0.2.jar 
guava-11.0.2.jar

#建立软链接
[root@hadoop01 lib]$ln -s /opt/hadoop-2.7.7/share/hadoop/hdfs/lib/guava-11.0.2.jar /opt/apache-hive-2.3.9-bin/lib/guava-11.0.2.jar
2、创建hive数仓目录
让hadoop新建/opt/apache-hive-2.3.9-bin/warehouse 和/opt/apache-hive-2.3.9-bin/tmp
[root@hadoop01 ~]$hadoop fs -mkdir -p /opt/apache-hive-2.3.9-bin/warehouse
[root@hadoop01 ~]$hadoop fs -mkdir -p /opt/apache-hive-2.3.9-bin/tmp

#授权
[root@hadoop01 ~]$hadoop fs -chmod 777 /opt/apache-hive-2.3.9-bin/warehouse
[root@hadoop01 ~]$hadoop fs -chmod 777 /opt/apache-hive-2.3.9-bin/tmp

#检查这两个目录是否成功创建
[root@hadoop01 ~]$hadoop fs -ls /opt/apache-hive-2.3.9-bin/
3、配置hive环境
[root@hadoop01 ~]$cd /opt/apache-hive-2.3.9-bin/conf/
[root@hadoop01 conf]$cp hive-log4j2.properties.template hive-log4j2.properties
[root@hadoop01 conf]$vim hive-log4j2.properties
property.hive.log.dir = /opt/apache-hive-2.3.9-bin/log

[root@hadoop01 conf]$cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
[root@hadoop01 conf]$vim hive-exec-log4j2.properties
property.hive.log.dir = /opt/apache-hive-2.3.9-bin/exelog

5.4配置hive-site文件

[root@hadoop01 conf]$cp hive-default.xml.template hive-site.xml

[root@hadoop01 conf]$cat hive-site.xml 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <!--Hive用来存储不同阶段的MR作业的执行计划的目录,同时也存储中间输出结果 -->
    <property>
        <name>hive.exec.scratchdir</name>
        <value>/opt/apache-hive-2.3.9-bin/tmp</value>
    </property>
    <!--Hive用来存储不同阶段的MR作业的执行计划的目录,创建写权限 -->
    <property>
        <name>hive.scratch.dir.permission</name>
        <value>733</value>
    </property>
    <!--Default数据仓库原始位置是在hdfs上:/user/hive/warehouse路径下 -->
    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/opt/apache-hive-2.3.9-bin/warehouse</value>
    </property>
    <!--连接hive元数据数据库地址,名称 -->
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://10.0.7.1:3306/hive?createDatabaseIfNotExist=true</value>
    </property>
    <!--连接数据库驱动 -->
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.cj.jdbc.Driver</value>
    </property>
    <!--连接数据库用户名称 -->
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
    </property>
    <!--连接数据库用户密码 -->
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>hive</value>
    </property>
    <!--客户端显示当前查询表的头信息 -->
    <property>
        <name>hive.cli.print.header</name>
        <value>true</value>
    </property>
    <!--客户端显示当前数据库名称信息 -->
    <property>
        <name>hive.cli.print.current.db</name>
        <value>true</value>
    </property>
    <property>
        <name>hive.server2.enable.doAs</name>
        <value>false</value>
    </property>
    <property>
        <name>hive.metastore.sasl.enabled</name>
        <value>false</value>
    </property>
    <property>
        <name>hive.server2.authenication</name>
        <value>NONE</value>
    </property>
</configuration>
[root@hadoop01 conf]$

5.5启动服务

#启动前先检查hadoop是否已经启动
#初始化Metastore元信息Schema
[root@hadoop01 apache-hive-2.3.9-bin]$./bin/schematool -initSchema -dbType mysql
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apache-hive-2.3.9-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-2.7.7/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]
Metastore connection URL:	 jdbc:mysql://10.0.7.1:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver :	 com.mysql.cj.jdbc.Driver
Metastore connection User:	 root
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed
#后台启动hiveserver2
nohup /opt/hive-2.3.9/bin/hiveserver2 >> /opt/apache-hive-2.3.9-bin/log/nohup.hs2.log 2>&1 &

#后台启动metastore
nohup hive --service metastore >> /opt/apache-hive-2.3.9-bin/log/metastore.log 2>&1 &

#查看hive的两个进程
ps -ef |grep hive

#启动验证
hive
show databases;
show tables;
select current_database();

以上是关于安装Hive的主要内容,如果未能解决你的问题,请参考以下文章

Hive-安装

Hive学习:Hive安装

hadoop安装hive及java调用hive

Hive 2.1.1安装配置

Hive的安装和部署

搭建hadoop+spark+hive环境(配置安装hive)