前言
之前已经完成了hadoop集群的安装,测试了HDFS的使用,现在准备在此基础上,继续安装Hive。
主要步骤
- 安装mysql
- 安装hive
- 配置hive
安装mysql
brew install mysql;
配置hive元数据库
mysql.server start
mysql -uroot
mysql> CREATE DATABASE hive;
mysql> USE hive;
mysql> CREATE USER \'hive\'@\'localhost\' IDENTIFIED BY \'hive\';
mysql> GRANT ALL PRIVILEGES ON hive.* TO \'hive\'@\'localhost\';
Hive安装
在Mac上我们可以利用Homebrew进行Hive的快速安装
brew update;
brew install hive;
我选择从官网下载压缩包进行安装,步骤如下
sudo tar -C /opt -xvf ~/Downloads/apache-hive-2.3.4-bin.tar.gz
mv apache-hive-2.3.4-bin hive
chown -R lestat:staff hive
设置环境变量
在 /etc/profile 中添加以下环境变量
#Hadoop Cluster
export HADOOP_HOME="/opt/hadoop"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home"
export HIVE_HOME="/opt/hive"
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:$HIVE_HOME/lib
设置配置文件
cd $HIVE_HOME/libexec/conf
cp hive-env.sh.template hive-env.sh;
cp hive-default.xml.template hive-site.xml;
修改 hive-env.sh
export HADOOP_HEAPSIZE=1024
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=$HADOOP_HOME
# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/opt/hive/conf
# Folder containing extra ibraries required for hive compilation/execution can be controlled by:
export HIVE_AUX_JARS_PATH=/opt/hive/lib
修改 hive-site.xml
首先在前面添加如下设置:
<property>
<name>system:java.io.tmpdir</name>
<value>/tmp/</value>
</property>
<property>
<name>system:user.name</name>
<value>${user.name}</value>
</property>
然后修改相应设置
<configuration>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>mysql
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>mysql驱动>程序
<value>com.mysql.jdbc.Driver</value>
</property>
</configuration>
准备mysql-connector-java
cp ~/Downloads/mysql-connector-java-8.0.15.jar /opt/hive/lib/
初始化元数据
$HIVE_HOME/bin/schematool -dbType mysql -initSchema
启动metastore
$HIVE_HOME/bin/hive --service metastore &
测试
进入hive
show databases;