HIVE_第一讲_ HIVE入门 , 搭建 单节点的基于内置的 derby 数据库

2024-05-03 06:32

本文主要是介绍HIVE_第一讲_ HIVE入门 , 搭建 单节点的基于内置的 derby 数据库,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近博主希望优化现有的业务框架,打算搭建一套 以Hive 为存储的数据仓库系统。

之前没有了解过hive , 本次是首次使用Hive, 不足之处欢迎各位指正。


Tips : 

在安装HIVE 之前请确保,已经安装了Hadoop


此种方式存在不足:不能使用多个链接 连接Hive 数据库,会报错!!!!!!

解决方法: 使用外部的元数据库,可以参考我接下来的一篇文章。

HIVE_第二讲_ Hive on MySQL


第一步:下载压缩包

首先我们需要从 Hive 官网上下载一个最新的 tar.gz 的压缩包


我下载的版本是 apache-hive-2.3.3-bin

http://mirrors.shu.edu.cn/apache/hive/hive-2.3.3/



第二步:  解压

下载好之后 ,我们对压缩包进行解压

解压指令

    tar -zxvf xx.tar.gz -C outputDir  



第三步: 修改配置文件


首先我们查看下conf目录,我们需要对其中的配置文件进行修改。


这里对其中2个文件进行讲解:

hive-default.xml.template

hive-env.sh.template

hive-default.xml.template  

   里面写有所有hive 可配置属性的默认设置与解释,如果我们忘了某一个配置的含义,可以来这里面进行查找。

hive-env.sh.template

   描述了hive 所需的环境变量的相关设置


复制一份hive-env.sh 填入以下内容:

hive-env.sh

# 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.# Set Hive and Hadoop environment variables here. These variables can be used
# to control the execution of Hive. It should be used by admins to configure
# the Hive installation (so that users do not have to set environment variables
# or set command line parameters to get correct behavior).
#
# The hive service being invoked (CLI etc.) is available via the environment
# variable SERVICE# Hive Client memory usage can be an issue if a large number of clients
# are running at the same time. The flags below have been useful in 
# reducing memory usage:
#
# if [ "$SERVICE" = "cli" ]; then
#   if [ -z "$DEBUG" ]; then
#     export HADOOP_OPTS="$HADOOP_OPTS -XX:NewRatio=12 -Xms10m -XX:MaxHeapFreeRatio=40 -XX:MinHeapFreeRatio=15 -XX:+UseParNewGC -XX:-UseGCOverheadLimit"
#   else
#     export HADOOP_OPTS="$HADOOP_OPTS -XX:NewRatio=12 -Xms10m -XX:MaxHeapFreeRatio=40 -XX:MinHeapFreeRatio=15 -XX:-UseGCOverheadLimit"
#   fi
# fi# The heap size of the jvm stared by hive shell script can be controlled via:
#
export HADOOP_HEAPSIZE=1024
#
# Larger heap size may be required when running queries over large number of files or partitions. 
# By default hive shell scripts use a heap size of 256 (MB).  Larger heap size would also be 
# appropriate for hive server.# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/usr/local/hadoop# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/usr/local/hive/conf# Folder containing extra libraries required for hive compilation/execution can be controlled by:
export HIVE_AUX_JARS_PATH=/usr/local/hive/lib

我们新创建一个hive-site.xml , 填写一些我们自己定义的配置:

hive-site.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration><property><name>hive.metastore.warehouse.dir</name><value>/usr/local/hive_home/apache-hive-2.3.3-bin/my-warehouse</value><description>Local or HDFS directory where Hive keeps table contents.</description></property><property><name>hive.metastore.local</name><value>true</value><description>Use false if a production metastore server is used.</description></property><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:derby:;databaseName=/usr/local/hive_home/apache-hive-2.3.3-bin/my-metastore;create=true</value><description>The JDBC connection URL.</description></property>
</configuration>


对其中的重要属性进行讲解:

hive.metastore.warehouse.dir  

 描述了spark 中管理表 存放的默认位置。其中 default 库 会存放在根目录下,而其他数据库的表 会存放在 以数据库名开头的 一个子目录下 database/tablename/


hive.metastore.local

 描述了hive 元信息的存放位置,元信息指的是 对hive 中表的描述,存放位置。。等相关信息。


修改完这两个hive 之后我们的配置文件已经配置完成,


第四步.  初始化derby 数据库

对于第一次配置derby,此时的derby 数据库还未完成初始化,我们需要完成初始化服务。

运行 bin 下面的schematool 工具

schematool -dbType derby -initSchema



第五步.  启动hive服务


启动hive服务,bin/hive 

( 默认启动的服务为 hive-cli, 可以通过 --help 进行查找帮助)



我们也可以通过 bin/hive --service cli --help  更具体的cli 服务 的帮助文档



我们尝试操作下 看下所有的数据库集合 show databases 


[root@master hive]# bin/hive --service cli 
which: no hbase in (/usr/local/flume/bin:/usr/local/redis/redis-4.0.1/bin:/usr/local/storm/apache-storm-1.0.1/bin:/usr/local/spark/bin:/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/scala_home/scala-2.12.4/bin:/usr/local/java_home/jdk1.8.0_162/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/git/bin/::/usr/local/nginx/sbin:/usr/local/zookeeper/zookeeper-3.4.5/bin/:/usr/local/kafka/kafka_2.11-0.10.0.1/bin/:/usr/local/kafka/:/usr/local/hive/bin:/usr/local/mongodb/mongodb-linux-x86_64-rhel62-3.2.9/bin/:/usr/local/cassandra/apache-cassandra-2.1.15/bin/:/root/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive_home/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop_home/hadoop-2.9.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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 file:/usr/local/hive_home/apache-hive-2.3.3-bin/conf/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 (default)> show databases;
OK
default
Time taken: 4.938 seconds, Fetched: 1 row(s)


大功告成!!

这篇关于HIVE_第一讲_ HIVE入门 , 搭建 单节点的基于内置的 derby 数据库的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/956041

相关文章

Oracle数据库定时备份脚本方式(Linux)

《Oracle数据库定时备份脚本方式(Linux)》文章介绍Oracle数据库自动备份方案,包含主机备份传输与备机解压导入流程,强调需提前全量删除原库数据避免报错,并需配置无密传输、定时任务及验证脚本... 目录说明主机脚本备机上自动导库脚本整个自动备份oracle数据库的过程(建议全程用root用户)总结

Spring WebClient从入门到精通

《SpringWebClient从入门到精通》本文详解SpringWebClient非阻塞响应式特性及优势,涵盖核心API、实战应用与性能优化,对比RestTemplate,为微服务通信提供高效解决... 目录一、WebClient 概述1.1 为什么选择 WebClient?1.2 WebClient 与

Python极速搭建局域网文件共享服务器完整指南

《Python极速搭建局域网文件共享服务器完整指南》在办公室或家庭局域网中快速共享文件时,许多人会选择第三方工具或云存储服务,但这些方案往往存在隐私泄露风险或需要复杂配置,下面我们就来看看如何使用Py... 目录一、android基础版:HTTP文件共享的魔法命令1. 一行代码启动HTTP服务器2. 关键参

Spring Boot 与微服务入门实战详细总结

《SpringBoot与微服务入门实战详细总结》本文讲解SpringBoot框架的核心特性如快速构建、自动配置、零XML与微服务架构的定义、演进及优缺点,涵盖开发环境准备和HelloWorld实战... 目录一、Spring Boot 核心概述二、微服务架构详解1. 微服务的定义与演进2. 微服务的优缺点三

从入门到精通详解LangChain加载HTML内容的全攻略

《从入门到精通详解LangChain加载HTML内容的全攻略》这篇文章主要为大家详细介绍了如何用LangChain优雅地处理HTML内容,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录引言:当大语言模型遇见html一、HTML加载器为什么需要专门的HTML加载器核心加载器对比表二

虚拟机Centos7安装MySQL数据库实践

《虚拟机Centos7安装MySQL数据库实践》用户分享在虚拟机安装MySQL的全过程及常见问题解决方案,包括处理GPG密钥、修改密码策略、配置远程访问权限及防火墙设置,最终通过关闭防火墙和停止Net... 目录安装mysql数据库下载wget命令下载MySQL安装包安装MySQL安装MySQL服务安装完成

从入门到进阶讲解Python自动化Playwright实战指南

《从入门到进阶讲解Python自动化Playwright实战指南》Playwright是针对Python语言的纯自动化工具,它可以通过单个API自动执行Chromium,Firefox和WebKit... 目录Playwright 简介核心优势安装步骤观点与案例结合Playwright 核心功能从零开始学习

MySQL进行数据库审计的详细步骤和示例代码

《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.