一、安装环境
操作系统:CentOS7.6
Hadoop版本:Hadoop3.2.0
MySQL版本:MySQL5.7
Hive的安装基于Hadoop,因此需要先搭建好Hadoop环境,详细可见:CentOS7 + Hadoop 3.2.0集群搭建;
其次以MySQL作为Hive的元数据库,所以也要先安装好MySQL,详见:CentOS7下yum方式安装MySQL5.7
二、安装配置Hive
官网链接找到对应版本的Hive安装包,我选择的是Hive3.1.1.
利用xshell等工具将安装包上传到/usr/local/hive/下,并解压:
(base) [root@DW1 hive]# tar -zxvf apache-hive-3.1.1-bin.tar.gz
(base) [root@DW1 hive]# cd apache-hive-3.1.1-bin
(base) [root@DW1 apache-hive-3.1.1-bin]# ll
total 56
drwxr-xr-x 3 root root 157 Aug 5 13:31 bin
drwxr-xr-x 2 root root 4096 Aug 5 13:31 binary-package-licenses
drwxr-xr-x 2 root root 4096 Aug 5 13:31 conf
drwxr-xr-x 4 root root 34 Aug 5 13:31 examples
drwxr-xr-x 7 root root 68 Aug 5 13:31 hcatalog
drwxr-xr-x 2 root root 44 Aug 5 13:31 jdbc
drwxr-xr-x 4 root root 12288 Aug 5 13:31 lib
-rw-r--r-- 1 root root 20798 Oct 23 2018 LICENSE
-rw-r--r-- 1 root root 230 Oct 23 2018 NOTICE
-rw-r--r-- 1 root root 222 Oct 23 2018 RELEASE_NOTES.txt
drwxr-xr-x 4 root root 35 Aug 5 13:31 scripts
在/etc/profile中添加环境变量:
(base) [root@DW1 apache-hive-3.1.1-bin]# vi /etc/profile
#添加以下内容
export HIVE_HOME=/usr/local/hadoop/apache-hive-3.1.1-bin
export PATH=$PATH:HIVE_HOME/bin
(base) [root@DW1 apache-hive-3.1.1-bin]# source /etc/profile
在 /usr/local/hadoop/apache-hive-3.1.1-bin/conf/ 下创建hive-site.xml 文件:
(base) [root@DW1 conf]# ls
beeline-log4j2.properties.template hive-env.sh.template ivysettings.xml metastore_db
derby.log hive-exec-log4j2.properties.template llap-cli-log4j2.properties.template parquet-logging.properties
hive-default.xml.template hive-log4j2.properties.template llap-daemon-log4j2.properties.template
# 复制hive-default.xml.template并更名为hive-site.xml
(base) [root@DW1 conf]# cp hive-default.xml.template hive-site.xml
(base) [root@DW1 conf]# ls
beeline-log4j2.properties.template hive-env.sh.template hive-site.xml llap-daemon-log4j2.properties.template
derby.log hive-exec-log4j2.properties.template ivysettings.xml metastore_db
hive-default.xml.template hive-log4j2.properties.template llap-cli-log4j2.properties.template parquet-logging.properties
创建HDFS文件夹
因为在hive-site.xml 中如下HDFS相关设置,因此我们需要现在HDFS中创建对应的目录:
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>/tmp/hive</value>
<description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.</description>
</property>
创建两个对应的目录并赋予读写权限:
(base) [root@DW1 apache-hive-3.1.1-bin]# hadoop fs -mkdir -p /user/hive/warehouse