1 安装JDK
请参照jdk的安装步骤。

2 安装Hadoop
请参照hadoop安装步骤。

3 下载Hive
下载地址:http://mirrors.tuna.tsinghua.edu.cn/apache/hive/
在该地址下载稳定版本的hive,我下载的版本是:apache-hive-2.1.1-bin.tar.gz
将下载的hive安装包上传到服务器上的~/Downloads目录下。

4 安装Hive
4.1 解压hive安装包
$>tar -xzvf apache-hive-2.1.1-bin.tar.gz
4.2 拷贝hive文件到/software目录
$>mv apache-hive-2.1.1-bin /software
注意:为了方便使用,我们创建一个hive的链接:
$>ln -s /software/ apache-hive-2.1.1-bin /software/hive
4.3 配置hive的环节变量
$>sudo vim /etc/profile
export JAVA_HOME=/software/jdk
export HADOOP_HOME=/software/hadoop
export HIVE_HOME=/software/hive
export PATH=$HIVE_HOME/bin:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PA
TH
$>source /etc/profile

5 配置Hive
$ cd $HIVE_HOME/conf
$ cp hive-env.sh.template hive-env.sh
5.1 编辑hive-env.sh文件
export HADOOP_HOME=/software/hadoop
5.2 配置hive的元数据库
$ cd $HIVE_HOME/conf
$ cp hive-default.xml.template hive-site.xml
编辑hive-site.xml文件,修改元数据库连接:
因为我们这里使用的hive内置的derby数据库,故配置不变

javax.jdo.option.ConnectionURL
jdbc:derby:;databaseName=metastore_db;create=true

JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.


如果需要修改,则配置例子如下:

javax.jdo.option.ConnectionURL
jdbc:derby://localhost:1527/metastore_db;create=true
JDBC connect string for a JDBC metastore

5.3 修改hive-site.xml文件中的配置变量
替换所有的 ${system:java.io.tmpdir}=/home/hadoop/hive
替换所有的 ${system:user.name}=hadoop

6 验证hive
6.1 启动hadoop
$ start-dfs.sh
$ start-yarn.sh
6.2 初始化schema库
$>/software/hive/bin/schematool -initSchema -dbType derby
完程后,在当前目录下创建一个文件夹metastore_db(元数据库)
6.3 进入hive shell
$>hive

7 将Hive中的schema存放到外部的MySql
7.1 配置mysql数据库连接信息
编辑hive-site.xml,添加mysql连接信息
[hive/conf/hive-site.xml]


hive.metastore.warehouse.dir
/user/hive/warehouse


javax.jdo.option.ConnectionURL
jdbc:mysql://192.168.137.1:3306/myhive?createDatabaseIfNotExist=true


javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver


javax.jdo.option.ConnectionUserName
root


javax.jdo.option.ConnectionPassword
Admin@3er



hive.metastore.local
false


hive.metastore.uris
thrift://s200:9083

7.2 在mysql中创建myhive数据库
$>create database myhive ;
7.3 mysql驱动程序(jar)放置到hive classpath下
将mysql驱动包放置到$HIVE_HOME/lib/目录下
7.4 重新初始化hive schema元数据库
$ schematool -initSchema -dbType mysql
7.5 启动hive服务端
$ hive --service metastore &
7.6 验证Hive
参考步骤6