一、配置MySQL
- 创建数据库
create database hive;
- 创建hive用户
create user 'hive'@'%' identified by 'hive';
- 授权
grant all on *.* to hive@'%' identified by 'hive';
flush privileges;
- 重启
sudo service mysql restart
二、安装hive
- 解压安装
sudo tar -zxvf ./apache-hive-2.3.7-bin.tar.gz -C /opt/bigdata
cd /opt/bigdata/
sudo mv apache-hive-2.3.7-bin hive-2.3.7
sudo chown -R hadoop:hadoop hive-2.3.7
- 配置环境变量
export HIVE_HOME=/opt/bigdata/hive-2.3.7
export PATH=${HIVE_HOME}/bin:$PATH
保存退出
source /etc/profile
- 修改配置文件hive-env.sh.template
cp hive-env.sh.template hive-env.sh
sudo vim hive-env.sh
如下
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/opt/bigdata/hadoop-2.9.2
# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/opt/bigdata/hive-2.3.7/conf
# Folder containing extra libraries required for hive compilation/execution can be controlled by:
export HIVE_AUX_JARS_PATH=/opt/bigdata/hive-2.3.7/lib
-
将mysql-connector-java-5.1.48.jar驱动拷贝到hive安装目录的lib下。
-
配置MySQL数据库信息
cp hive-default.xml.template hive-default.xml
sudo vim hive-default.xml
如下
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&useSSL=false</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>hive</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
<description>
Enforce metastore schema version consistency.
True: Verify that version information stored in is compatible with one from Hive jars. Also disable automatic
schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures
proper metastore schema migration. (Default)
False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
</description>
</property>
<property>
<name>datanucleus.schema.autoCreateAll</name>
<value>true</value>
<description>Auto creates necessary schema on a startup if one doesn't exist. Set this to false, after creating it once.To enable auto create also set hive.metastore.schema.verification=false. Auto creation is not recommended for production use cases, run schematool command instead.</description>
</property>
</configuration>
- 启动服务
# 启动hadoop
/hadoop/sbin/start-dfs.sh
# 后台启动元数据服务
hive --service metastore &
# 启动hive
hive