hive安装与配置详解
时间: 2023-10-17 18:14:34 浏览: 125
Hive是一个基于Hadoop的数据仓库工具,可以将SQL语句转换为MapReduce任务来处理大数据。以下是Hive的安装与配置详解:
1. 环境准备
在安装Hive之前,需要安装和配置Java、Hadoop和MySQL数据库。确保以下环境已经准备好:
- Java 8或更高版本
- Hadoop 2.7或更高版本
- MySQL 5.6或更高版本
2. 下载和解压缩Hive
从Hive官方网站下载最新版本的Hive,并将其解压缩到你想要安装Hive的目录中。
例如,将Hive解压缩到/opt/hive目录中:
```
tar -xzvf apache-hive-3.1.2-bin.tar.gz -C /opt
```
3. 配置Hive
进入Hive的conf目录,将hive-default.xml.template文件重命名为hive-site.xml,并编辑hive-site.xml文件。
```
cd /opt/apache-hive-3.1.2-bin/conf
cp hive-default.xml.template hive-site.xml
vim hive-site.xml
```
在hive-site.xml文件中,添加以下配置:
- 配置Hive的JDBC连接URL:
```
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
```
- 配置Hive的JDBC驱动程序:
```
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
```
- 配置Hive的JDBC用户名和密码:
```
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveuser</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hivepassword</value>
<description>password to use against metastore database</description>
</property>
```
其中,hiveuser和hivepassword是连接MySQL数据库的用户名和密码。
- 配置Hive的数据存储路径:
```
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
```
- 配置Hive的Hadoop安装路径:
```
<property>
<name>hive.exec.scratchdir</name>
<value>/tmp/hive-${user.name}</value>
<description>Scratch space for Hive jobs</description>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/tmp/${user.name}</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/tmp/hive-${user.name}/resources</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
<property>
<name>hive.querylog.location</name>
<value>/tmp/hive-${user.name}</value>
<description>Location of Hive run-time structured log file</description>
</property>
<property>
<name>hive.exec.compress.output</name>
<value>true</value>
<description>Enable compression for the output files</description>
</property>
<property>
<name>hive.exec.dynamic.partition</name>
<value>true</value>
<description>Enable dynamic partitioning</description>
</property>
<property>
<name>hive.exec.dynamic.partition.mode</name>
<value>nonstrict</value>
<description>Set dynamic partition mode to strict or non-strict</description>
</property>
<property>
<name>hive.mapred.mode</name>
<value>nonstrict</value>
<description>Set Hive and MapReduce interaction mode to strict or non-strict</description>
</property>
<property>
<name>hive.server2.logging.operation.enabled</name>
<value>true</value>
<description>Log Hive operation information</description>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/var/log/hive/operation_logs</value>
<description>Location of Hive operation logs</description>
</property>
<property>
<name>hive.server2.tez.initialize.default.sessions</name>
<value>false</value>
<description>Set to false to disable automatic Tez session initialization</description>
</property>
<property>
<name>hive.zookeeper.quorum</name>
<value>localhost:2181</value>
<description>Location of ZooKeeper server</description>
</property>
```
其中,/user/hive/warehouse是Hive的默认数据存储路径。
4. 配置环境变量
将以下环境变量添加到~/.bashrc文件中:
```
export HIVE_HOME=/opt/apache-hive-3.1.2-bin
export PATH=$PATH:$HIVE_HOME/bin
```
5. 启动Hive
启动Hive之前,需要启动Hadoop和MySQL数据库。
```
start-all.sh
service mysql start
```
然后,启动Hive:
```
hive
```
如果一切正常,将看到Hive的命令行提示符。
以上就是Hive的安装和配置详解。
阅读全文