hive部署
1. 前置条件
安装hive前需先安装mysql及hadoop
a)在mysql中创建用户及数据库
create user 'hive' identified by 'hive';
grant all privileges on *.* to 'hive'@'%' with grant option;
create database hive character set latin1;
b)hadoop环境变量需要需要
/etc/profile文件中存在以下变量并加入到path中
export HADOOP_HOME=/data/hadoop
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
2.获取hive及相关安装包
可通过清华镜像中下载,https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.9/
a)解压缩并重命名目录
tar -zxvf apache-hive-2.3.9-bin.tar.gz
mv apache-hive-2.3.9-bin hive-2.3.9
b)配置环境变量
vi /etc/profile
在文件末尾加入以下内容后保存退出
#HIVE_HOME
export HIVE_HOME=/data/hive-2.3.9
export PATH=$PATH:$HIVE_HOME/bin
文件使之生效
source /etc/profile
c)下载mysql jar包,将jar包放入hive lib目录下
cd /data/hive-2.3.9/lib
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.21/mysql-connector-java-8.0.21.jar
d)检查hive与hadoop中guava版本(保证hive中的guava版本大于hadoop中的版本)
ll /data/hive-2.3.9/lib/guava-*
ll /data/hadoop/share/hadoop/hdfs/lib/guava-*
若hive中的guava版本小于hadoop
cd /data/hive-2.3.9/lib/
mv guava-14.0.1.jar guava-14.0.1.jar.bak #备份
#设置软链接
ln -s /data/hadoop/share/hadoop/hdfs/lib/guava-27.0-jre.jar /data/hive-2.3.9/lib/
3.hive配置
a)创建hive数仓目录
hdfs dfs -mkdir tmp
hdfs dfs -mkdir warehouse
hdfs dfs -chmod 777 warehouse
hdfs dfs -chmod 777 tmp
b)配置conf目录中的文件
配置日志文件
cd /data/hive-2.3.9/conf/
cp hive-log4j2.properties.template hive-log4j2.properties
vim hive-log4j2.properties
#修改property.hive.log.dir目录为
property.hive.log.dir = /data/hive-2.3.9/log
cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
vim hive-exec-log4j2.properties
#修改property.hive.log.dir目录
property.hive.log.dir = /data/hive-2.3.9/exelog
配置hive-site文件
cp hive-default.xml.template hive-site.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>hive.cli.print.header</name> <value>true</value> <description>Whether to print the names of the columns in query output.</description> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/hive</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.cj.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://localhost:9083</value> <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description> </property> </configuration>
4.启动服务
a)初始化Metastore元信息Schema
cd /data/hive-2.3.9/bin
./schematool -initSchema -dbType mysql
b)启动metastore
nohup hive --service metastore > metastore.log &
c)登录hive客户端
5.beeline配置
a)配置hadoop
cd /data/hadoop/etc/hadoop/
vim core-site.xml
<property> <name>hadoop.proxyuser.hadoop.hosts</name> <value>*</value> </property> <property> <name>hadoop.proxyuser.hadoop.groups</name> <value>*</value> </property>
检查hdfs-site.xml文件存在以下配置
<property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property>
重启hadoop
b)启动hiveserver2
cd /data/hive-2.3.9/bin
nohup hive --service hiveserver2 >hiveserver.log &
c)启动 beeline客户端
beeline --color=true
进入客户端,执行连接命令,其中100.86.13.xx是安装hadoop的节点ip
!connect jdbc:hive2://100.86.13.xx:10000
输入100.86.13.xx这台机器的hadoop用户名和密码