hive安装

本文档详细介绍了Hive的安装过程,包括上传和解压缩软件包,修改配置文件如hive-env.sh和hive-site.xml,解决Jline包版本冲突问题以及处理MySQL权限设置。在配置过程中,需要将MySQL的JAR包复制到lib路径,并替换hadoop中的jline.2.12.jar以确保版本一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上传、解压

修改配置

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/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=/root/app/hadoop-2.6.4 #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=

vi hive-site.xml

<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost: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.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>

<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>

<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>

将mysql的jar包拷贝到lib路径下

Jline包版本不一致的问题

需要拷贝hive的lib目录中jline.2.12.jar的jar包替换掉hadoop中的

mysql 权限问题

   #执行下面的语句  * . *:所有库下的所有表   %:任何IP地址或主机都可以连接)
	GRANT ALL PRIVILEGES ON * . * TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
	FLUSH PRIVILEGES;
### Hive 安装教程概述 Hive 是一种建立在 Hadoop 上的数据仓库工具,支持结构化数据的查询和分析。以下是基于多种资料整理而成的一份完整的 Hive 安装指南。 --- #### 1. 准备工作 在安装 Hive 之前,需要完成以下准备工作: - **Java 环境配置** Hive 需要 Java 环境的支持。可以通过以下命令安装 JDK 并设置环境变量[^2]: ```bash mkdir -p /opt/module tar -zxvf /tmp/jdk-8u391-linux-x64.tar.gz -C /opt/module/ echo "export JAVA_HOME=/opt/module/jdk1.8.0_391" >> /etc/profile echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile source /etc/profile ``` - **Hadoop 环境准备** Hive 查询依赖于 Hadoop 提供的分布式计算能力。因此,在安装 Hive 前需先部署好 Hadoop 集群或单机版环境[^3]。 - **MySQL 数据库配置(可选)** 如果希望将 Hive 的元数据存储到 MySQL 中,则需要提前安装并初始化 MySQL 数据库[^4]。可以参考以下命令进行最小化安装: ```bash sudo apt-get update sudo apt-get install mysql-server service mysql start ``` --- #### 2. Hive 下载与解压 下载最新版本的 Hive 并将其解压至目标目录。例如,对于 Hive 3.1.3 版本,操作如下[^4]: ```bash cd /usr/local sudo wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-3.1.3/apache-hive-3.1.3-bin.tar.gz sudo tar -zxvf apache-hive-3.1.3-bin.tar.gz sudo mv apache-hive-3.1.3-bin hive ``` --- #### 3. 环境变量配置 为了方便调用 Hive 工具,建议修改系统的环境变量文件 `~/.bashrc` 或 `/etc/profile`,添加以下内容: ```bash export HIVE_HOME=/usr/local/hive export PATH=$PATH:$HIVE_HOME/bin source ~/.bashrc ``` --- #### 4. 配置 Hive 参数 进入 Hive 的配置目录 (`$HIVE_HOME/conf`),并将默认模板文件复制为实际使用的配置文件[^5]: ```bash cp $HIVE_HOME/conf/hive-default.xml.template $HIVE_HOME/conf/hive-site.xml ``` 随后,编辑 `hive-site.xml` 文件以指定必要的参数。例如,定义本地临时目录的位置: ```xml <property> <name>hive.exec.local.scratchdir</name> <value>/path/to/hive/local/scratchdir</value> <description>Local scratch space for Hive jobs</description> </property> ``` 如果使用 MySQL 存储元数据,还需额外配置 JDBC 连接信息。具体示例如下: ```xml <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/metastore?createDatabaseIfNotExist=true&useSSL=false</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>password</value> </property> ``` --- #### 5. 启动 Hive 和验证 完成以上步骤后,即可启动 Hive 并验证其功能。首先确保 Hadoop 集群已正常运行[^3]: ```bash cd /usr/local/hadoop ./sbin/start-dfs.sh ``` 接着尝试启动 Hive CLI 或 Beeline 接口: ```bash cd /usr/local/hive ./bin/hive ``` 或者通过 Beeline 方式连接: ```bash ./bin/beeline -u jdbc:hive2://localhost:10000 ``` --- #### 6. 常见问题排查 在安装过程中可能会遇到一些常见的错误提示。例如,JDBC 驱动缺失时需要手动下载对应的驱动包,并放置到 `$HIVE_HOME/lib` 目录下。 --- ### 结论 按照上述流程,能够顺利完成 Hive安装与基本配置过程。需要注意的是,生产环境中通常还需要进一步优化性能参数以及增强安全性措施。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值