apache-hive-1.2.1-bin 安装

本文详细介绍了如何安装和配置 Apache Hive 1.2.1 版本,包括下载安装包、配置 MySQL 存储元数据、设置 HDFS 目录、环境变量配置、初始化元数据数据库等步骤。同时,还提供了常见的问题处理方法。

apache-hive-1.2.1-bin 安装

更多资源:https://github.com/opensourceteams

技能标签

  • 下载apache hive 安装包
  • 进行apache-hive-1.2.1-bin.tar.gz安装
  • 配置mysql存储元数据
  • 配置HDFS存储 /user/hive/warehouse
  • 该Hive版本1.2.1默认集成在(Spark1.6 到 Spark2.4)

下载

  • 下载安装包apache-hive-1.2.1-bin.tar.gz: https://archive.apache.org/dist/hive/hive-1.2.1
  • 由于spark-2.4.0-bin-hadoop2.7 预编译好的捆绑hive版本为hive-1.2.1,为了方便所以选用版本apache-hive-1.2.1-bin
  • 如果spark支持其它版本的hive,需要重新手动编译spark源码也可以实现

安装

解压安装包

tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/module/bigdata/

配置环境变量

export HIVE_HOME=/opt/module/bigdata/apache-hive-1.2.1-bin
export PATH=$HIVE_HOME/lib:#PATH

HDFS新建目录

bin/hadoop fs -mkdir -p  /user/hive/warehouse #创建目录
bin/hadoop fs -chmod -R 777 /user/hive/warehouse #新建的目录赋予读写权限
bin/hadoop fs -mkdir -p /tmp/hive/#新建/tmp/hive/目录
bin/hadoop fs -chmod -R 777 /tmp/hive #目录赋予读写权限
#用以下命令检查目录是否创建成功
bin/hadoop fs -ls /user/hive
bin/hadoop fs -ls /tmp/hive

连接mysql数据库

  • 复制jdbc连接驱动
cp mysql-connector-java-8.0.13.jar  $HIVE_HOME/lib/

新建hive-site.xml数据库相关的配置

  • touch 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>/user/hive/warehouse</value>  
  </property>
  
  <property>
    <name>hive.exec.scratchdir</name>
    <value>/tmp/hive</value>  
  </property>
  
  <property>
    <name>javax.jdo.option.ConnectionURL</name> 
    <value>jdbc:mysql://macbookmysql.com:3306/hive?createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.cj.jdbc.Driver</value>
    <description>Driver class name for a JDBC metastore</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>admin</value>
    <description>username to use against metastore database</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>000000</value>
    <description>password to use against metastore database</description>
  </property>


</configuration>	

新建hive-env.sh

  • cp hive-env.sh.template
# 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/HWI 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 (hwi etc).


# Set HADOOP_HOME to point to a specific hadoop install directory
# HADOOP_HOME=${bin}/../../hadoop

# Hive Configuration Directory can be controlled by:
# export HIVE_CONF_DIR=

# Folder containing extra ibraries required for hive compilation/execution can be controlled by:
# export HIVE_AUX_JARS_PATH=




HADOOP_HOME=/opt/module/bigdata/hadoop-2.9.2
export HIVE_CONF_DIR=/opt/module/bigdata/apache-hive-1.2.1-bin/conf
export HIVE_AUX_JARS_PATH=/opt/module/bigdata/apache-hive-1.2.1-bin/lib

初使化元数据数据库

schematool -initSchema -dbType mysql

启动hive

hive
  • hive启动说明

启动hive metastore服务

  • 启动该服务会开一个 9083端口
  • netstat -ntlup 可以查看服务端占用的端口
hive --service metastore & 

停止hive metastore服务

ps -ef|grep hive

kill -9 pid

启动hiveserver服务 (该服务可以不启动)

hive --service hiveserver2 & 

操作

启动 hive

hive

退出 hive命令

exit;

创建database

create database;

显示所有的database

show databases;

显示所有的表

show tables;

创建表

CREATE TABLE IF NOT EXISTS employee (  name String, salary String) COMMENT 'Employee details' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE;

插入数据

  • 数据文件 employee.txt
小明    100000
小王    50000
小李    60000
  • 插入数据文件到hive上
LOAD DATA LOCAL INPATH '/home/liuwen/temp/employee.txt' OVERWRITE INTO TABLE employee;

查看表数据

 select * from employee;

问题处理

无法访问spark-assembly-*.jar


[liuwen@standalone lib]$ schematool -initSchema -dbType mysql
ls: 无法访问/opt/module/bigdata/spark-2.4.0-bin-without-hadoop/lib/spark-assembly-*.jar: 没有那个文件或目录
Metastore connection URL:        jdbc:mysql://macbookmysql.com:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver :    com.mysql.cj.jdbc.Driver
Metastore connection User:       admin
Starting metastore schema initialization to 1.2.0
Initialization script hive-schema-1.2.0.mysql.sql
Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
*** schemaTool failed ***


  • 处理方法
  • 处理$HIVE_HOME/bin/hive
  #sparkAssemblyPath=`ls ${SPARK_HOME}/lib/spark-assembly-*.jar`
  sparkAssemblyPath=`ls ${SPARK_HOME}/jars/*.jar`

end

### 回答1: 这个错误通常意味着Hive不能找到所需的执行jar包。你可以尝试以下几个步骤: 1. 检查Hive的配置是否正确,并确保`hive-exec-*.jar`文件存在于`/opt/module/apache-hive-1.2.1-bin/lib/`目录中。如果不存在,你可能需要重新安装Hive2. 检查你的环境变量是否正确设置。确保`HIVE_HOME`指向正确的Hive安装目录,并将`$HIVE_HOME/bin`添加到`$PATH`中。 3. 如果你正在使用Hadoop集群,请确保Hive和Hadoop的版本兼容。不同版本的Hive可能需要不同版本的Hadoop支持。 4. 如果你正在使用远程Hive服务器,请确保你的客户端能够访问Hive服务器,并且Hive服务器上的配置正确。 如果以上步骤都没有解决问题,你可能需要查看Hive的日志文件,以确定更具体的错误信息。 ### 回答2: 在Hive中执行任务时,可能会遇到"Missing Hive Execution Jar"错误,表示Hive无法找到所需的hive-exec-*.jar文件。这个问题通常发生在缺少Hive的执行文件或文件位置错误的情况下。 要解决这个问题,可以按照以下步骤进行操作: 1. 首先,确保在指定的路径/opt/module/apache-hive-1.2.1-bin/lib/中存在hive-exec-*.jar文件。如果文件确实存在,那么可能是权限问题导致Hive无法读取该文件。可以使用chmod命令修改文件权限,确保Hive可以访问该文件。 2. 如果文件确实存在,并且权限设置正确,但Hive仍然无法找到该文件,可以尝试重新设置Hive的环境变量。在Hive的配置文件中(通常是hive-env.sh或hive-site.xml),检查hive.exec.jar路径的设置。确保该路径正确地指向hive-exec-*.jar文件所在的位置。 3. 最后,可以通过重新安装Hive来解决该问题。在重新安装之前,确保彻底卸载Hive,并删除掉相关的文件和目录,然后重新安装最新版本的Hive。 总之,解决"Missing Hive Execution Jar"错误的关键是确保hive-exec-*.jar文件存在且位置正确,并检查Hive的环境变量和配置文件中的设置是否正确。如果问题仍然存在,可以尝试重新安装Hive来解决该问题。 ### 回答3: 缺少Hive执行Jar包:/opt/module/apache-hive-1.2.1-bin/lib/hive-exec-*.jar。 这个错误表示在指定的路径中缺少Hive执行Jar包。Hive使用这个Jar包来执行Hive查询和任务。 要解决这个问题,首先需要确认是否正确安装Hive,并且路径设置正确。如果路径不正确,可以在Hive的配置文件中更正路径。 另外,还需要确认是否存在这个Jar包,并且该Jar包的版本与Hive的版本兼容。需要确保Hive执行Jar包与所使用的Hive版本匹配,否则可能会出现兼容性问题。 如果确保了路径和版本都是正确的,但依然缺少该Jar包,可以尝试重新下载并安装Hive。在安装过程中,确保将Hive执行Jar包正确地放置在指定的路径下。 如果还是无法解决问题,可能需要查看Hive的日志文件以获取更多详细的错误信息。根据日志中的具体错误,可以进一步排查可能的原因,并采取相应的解决措施。 总结来说,缺少Hive执行Jar包的错误是由于路径设置不正确或Jar包版本不兼容引起的。通过检查路径配置、重新下载安装和查看日志文件等步骤,可以解决这个问题。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值