安装Hive

安装Hive

准备

安装Java环境:Hive需要Java环境支持,所以需要先安装Java。安装文档:http://t.csdn.cn/deBJu

安装MySQL数据库。http://t.csdn.cn/d24pN

下载Hive

下载Hive的二进制文件。

链接:https://pan.baidu.com/s/1fdg76k9kvd896pMpfYEG5w
提取码:8888

解压Hive

将下载的Hive压缩包解压到指定目录。

[root@master ~]# cd /usr/local
[root@master local]# ll
总用量 279464
-rw-r--r--.  1 root  root  286170958 67 11:18 apache-hive-2.3.9-bin.tar.gz
drwxr-xr-x. 11  1000  1000       272 525 08:49 hadoop-3.3.1
drwxr-xr-x.  8 10143 10143       273 48 2021 jdk1.8.0_291

# 解压
[root@master local]# tar -zxvf apache-hive-2.3.9-bin.tar.gz
[root@master local]# ll
总用量 279464
drwxr-xr-x. 10 root  root        184 67 11:22 apache-hive-2.3.9-bin
-rw-r--r--.  1 root  root  286170958 67 11:18 apache-hive-2.3.9-bin.tar.gz
drwxr-xr-x. 11  1000  1000       272 525 08:49 hadoop-3.3.1
drwxr-xr-x.  8 10143 10143       273 48 2021 jdk1.8.0_291

配置Hive环境变量

将Hive的bin目录添加到系统环境变量中。

[root@master local]# vi /etc/profile
# Hive
export HIVE_HOME=/usr/local/apache-hive-2.3.9-bin
export PATH=$PATH:$HIVE_HOME/bin

[root@master local]# source /etc/profile

配置Hive配置文件

[root@master conf]# vi hive-env.sh.template
HADOOP_HOME=$HADOOP_HOME
export HIVE_CONF_DIR=$HIVE_HOME/conf

配置hive-config.sh

[root@master ~]# cd /usr/local/apache-hive-2.3.9-bin/bin
[root@master bin]# vi hive-config.sh
# 配置hive
export JAVA_HOME=/usr/local/jdk1.8.0_291
export HIVE_HOME=/usr/local/apache-hive-2.3.9-bin
export HADOOP_HOME=/usr/local/hadoop-3.3.1
export HIVE_CONF_DIR=/usr/local/apache-hive-2.3.9-bin/conf

拷贝Hive配置文件

[root@master ~]# cd /usr/local/apache-hive-2.3.9-bin/conf/
[root@master conf]# cp hive-default.xml.template hive-site.xml


配置hive-site.xml

[root@master conf]# vi hive-site.xml

修改Hive的配置文件hive-site.xml,设置Hive的元数据存储方式、Hadoop的配置文件路径等。

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=UTC</value>
    <description>MYSQL连接协议</description>
</property>
<property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>JDBC连接驱动</description>
</property>
<property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>root</value>
    <description>用户名</description>
</property>
<property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>123456</value>
    <description>密码</description>
    </property>
<property>
    <name>datanucleus.schema.autoCreatAll</name>
    <value>true</value>
    <description>自动更新数据库</description>
</property>
<property>
    <name>hive.metastore.schema.verification</name>
    <value>false</value>
</property>
<property>
    <name>hive.exec.local.scratchdir</name>
    <value>/usr/local/apache-hive-2.3.9-bin/tmp/${user.name}</value>
    <description>Local scratch space for Hive jobs</description>
</property>
<property>
    <name>system:java.io.tmpdir</name>
    <value>/usr/local/apache-hive-2.3.9-bin/iotmp</value>
</property>
<property>
    <name>hive.downloaded.resources.dir</name>
    <value>/usr/local/apache-hive-2.3.9-bin/tmp/${hive.session.id}_resources</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
</property>
<property>
    <name>hive.querylog.location</name>
    <value>/usr/local/apache-hive-2.3.9-bin/tmp/${system:user.name}</value>
    <description>Location of Hive run time structured log file</description>
</property>
<property>
    <name>hive.server2.logging.operation.log.location</name>
    <value>/usr/local/apache-hive-2.3.9-bin/tmp/${system:user.name}/operation_logs</value>
    <description>Top level directory where operation logs are stored if logging functionality is enabled</description>
</property>
<property>
    <name>hive.metastore.db.type</name>
    <value>mysql</value>
</property>
<property>
    <name>hive.cli.print.current.db</name>
    <value>true</value>
<description>Whether to include the current database in the Hive prompt.</description>
</property>

<property>
    <name>hive.cli.print.header</name>
    <value>true</value>
    <description>Whether to print the names of the columns in query output.</description>
</property>

mysq-comnector-java-5.1.32.jar驱动包上传至bin目录下

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Waog7K8k-1686895673588)(E:\Java笔记\大数据\Hadoop\Hive\安装Hive\安装Hive.assets\image-20230616140723463.png)]

初始化元数据库

[root@master ~]# schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/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:/usr/local/hadoop-3.3.1/share/hadoop/common/lib/slf4j-log4j12-1.7.30.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://localhost:3306/hive?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
Metastore Connection Driver :    com.mysql.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

启动Hive

在命令行中输入hive命令,启动Hive。

[root@master conf]# hdfs namenode -format
[root@master conf]# start-dfs.sh
[root@master conf]# start-yarn.sh
[root@master conf]# hive
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_291/bin:/usr/local/jdk1.8.0_291/jre/bin:/usr/local/hadoop-3.3.1/bin:/usr/local/hadoop-3.3.1/sbin:/root/bin:/usr/local/jdk1.8.0_291/bin:/usr/local/jdk1.8.0_291/jre/bin:/usr/local/hadoop-3.3.1/bin:/usr/local/hadoop-3.3.1/sbin:/usr/local/apache-hive-2.3.9-bin/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/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:/usr/local/hadoop-3.3.1/share/hadoop/common/lib/slf4j-log4j12-1.7.30.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]

Logging initialized using configuration in jar:file:/usr/local/apache-hive-2.3.9-bin/lib/hive-common-2.3.9.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> 


测试Hive:

在Hive命令行中输入一些Hive查询语句,测试Hive是否正常工作。文章来源地址https://uudwc.com/A/Je5O

# 查看数据库
hive (default)> show databases;
OK
database_name
default
Time taken: 6.772 seconds, Fetched: 1 row(s)
# 创建数据表
hive (default)> create table student(
              > id int
              > );
OK
Time taken: 1.294 seconds
# 查看数据表
hive (default)> show tables;
OK
tab_name
student
Time taken: 0.06 seconds, Fetched: 1 row(s)

原文地址:https://blog.csdn.net/qq_44715376/article/details/131220008

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年06月17日 06:37
盒子水平垂直居中常用的六种方法
下一篇 2023年06月17日 06:37