安装HIve
# cd 安装包文件夹目录
tar -zxvf apache-hive-2.1.1-bin.tar.gz
mkdir /opt/hive
mv apache-hive-2.1.1-bin /opt/hive/hive2.1
配置环境变量
# 配置环境变量
vim /etc/profile
# Hive Config
export HIVE_HOME=/opt/hive/hive2.1
export HIVE_CONF_DIR=${HIVE_HOME}/conf
export PATH=.:${JAVA_HOME}/bin:${SCALA_HOME}/bin:${SPARK_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:${ZK_HOME}/bin:${HBASE_HOME}/bin:${HIVE_HOME}/bin:${KAFKA_HOME}/bin:${SQOOP_HOME}/bin:${FLUME_HOME}/bin:${STORM_HOME}/bin:$PATH
使用hive默认的元数据
# 初始化默认元数据
/opt/hive/hive2.1/bin/schematool -dbType derby -initSchema
使用MySQL作为元数据
# 配置属性信息
cd /opt/hive/hive2.1/conf
mv hive-default.xml.template hive-default.xml
vim hive-site.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://mysqlip: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>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>
</configuration>
添加MySQL的jdbc jar包到hive
cd jar包目录
cp mysql-connector-java-5.1.41.jar /opt/hive/hive2.1/lib/
Linux远程连接MySQL (5.1.41版本)
service mysql start #启动mysql服务
mysql -u root -p #登陆shell界面
#这个hive数据库与hive-site.xml中localhost:3306/hive的hive对应,用来保存hive元数据
mysql> create database hive;
#将所有数据库的所有表的所有权限赋给hive用户,后面的hive是配置hive-site.xml中配置的连接密码
mysql> grant all on *.* to hive@localhost identified by 'hive';
#刷新mysql系统权限关系表
mysql> flush privileges;
mysql> quit;
start-all.sh #启动hadoop
需要hive元数据库初始化
schematool -dbType mysql -initSchema
#启动hive
hive
启动hive
hive
参考:
大数据技术原理与应用 第十四章 基于Hadoop的数据仓库Hive 学习指南
关于hive异常:Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStor