一、版本信息
二、安装部署Mysql
三、安装部署Hive
1. 安装准备
1) 把 apache-hive-3.1.3-bin.tar.gz 上传到 linux 的/opt/src 目录下并解压
tar -zxvf /opt/src/apache-hive-3 .1.3-bin. tar .gz
|
2) 修改 apache-hive-3.1.3-bin 的名称为 hive-3.1.3
mv /opt/src/apache-hive-3 .1.3-bin /data/hive-3 .1.3
|
3) 修改/etc/profile.d/my_env.sh, 添加环境变量
vim /etc/profile .d /my_env .sh
|
4) 添加内容
export HIVE_HOME= /data/hive-3 .1.3
export PATH=$PATH:$HIVE_HOME /bin
|
5) 解决 guava Jar 包冲突
mv $HIVE_HOME /lib/guava-19 .0.jar $HIVE_HOME /lib/guava-19 .0.jar.bak
|
6) 解决日志 Jar 包冲突
mv $HIVE_HOME /lib/log4j-slf4j-impl-2 .17.1.jar $HIVE_HOME /lib/log4j-slf4j-impl-2 .17.1.jar_bak
|
2. 配置元数据到 MySQL
1) 拷贝驱动
cp mysql-connector-java-8.0.30.jar $HIVE_HOME /lib/mysql-connector-java-8 .0.30.jar
|
2) 配置 Metastore 到 MySQL
vim $HIVE_HOME /conf/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://192.168.0.0:3306/metastore?useSSL=false</ 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 >username</ value >
</ property >
< property >
< name >javax.jdo.option.ConnectionPassword</ name >
< value >password</ value >
</ property >
< property >
< name >hive.metastore.schema.verification</ name >
< value >false</ value >
</ property >
< property >
< name >hive.metastore.event.db.notification.api.auth</ name >
< value >false</ value >
</ property >
< property >
< name >hive.metastore.warehouse.dir</ name >
< value >/user/hive/warehouse</ value >
</ property >
< property >
< name >hive.metastore.uris</ name >
< value >thrift://hive01:9083</ value >
</ property >
< property >
< name >hive.server2.thrift.bind.host</ name >
< value >hive01</ value >
</ property >
< property >
< name >hive.server2.thrift.port</ name >
< value >10000</ value >
</ property >
< property >
< name >hive.cli.print.header</ name >
< value >true</ value >
</ property >
< property >
< name >hive.cli.print.current.db</ name >
< value >true</ value >
</ property >
</ configuration >
|
3) 登陆 MySQL, 新建 Hive 元数据库
mysql> create database metastore;
mysql> quit;
|
4) 初始化 Hive 元数据库
schematool -initSchema -dbType mysql -verbose
|
3. 使用 JDBC 方式访问 Hive
1) 启动 metastore
2)启动 hiveserver2
hive --service hiveserver2
|
3)启动 beeline 客户端(需要多等待一会)
bin /beeline -u jdbc:hive2: //hive01 :10000 -n root
|
4) 编写 hive 服务启动脚本
vim $HIVE_HOME /bin/hiveservices .sh
|
写入下面内容
#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME /logs
if [ ! -d $HIVE_LOG_DIR ]; then
mkdir -p $HIVE_LOG_DIR
fi
function check_process(){
pid=$( ps -ef 2> /dev/null | grep - v grep | grep -i $1 | awk '{print $2}' )
ppid=$( netstat -nltp 2> /dev/null | grep $2 | awk '{print $7}' | cut -d '/' -f 1)
echo $pid
[[ "$pid" =~ "$ppid" ]] && [ "$ppid" ] && return 0 || return 1
}
function hive_start(){
metapid=$(check_process HiveMetastore 9083)
cmd= "nohup hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
[ -z "$metapid" ] && eval $cmd || echo "Metastroe 服务已启动"
server2pid=$(check_process HiveServer2 10000)
cmd= "nohup hiveserver2 >$HIVE_LOG_DIR/hiveServer2.log 2>&1 &"
[ -z "$server2pid" ] && eval $cmd || echo "HiveServer2 服务已启动"
}
function hive_stop(){
metapid=$(check_process HiveMetastore 9083)
[ "$metapid" ] && kill $metapid || echo "Metastore 服务未启动"
server2pid=$(check_process HiveServer2 10000)
[ "$server2pid" ] && kill $server2pid || echo "HiveServer2 服务未启动"
}
case $1 in
"start" )
hive_start
;;
"stop" )
hive_stop
;;
"restart" )
hive_stop
sleep 2
hive_start
;;
"status" )
check_process HiveMetastore 9083 > /dev/null && echo "Metastore 服务运行正常" || echo "Metastore 服务运行异常"
;;
*)
echo Invalid Args!
echo 'Usage: ' $( basename $0) ' start|stop|restart|status'
;;
esac
|
添加执行权限
chmod +x $HIVE_HOME /bin/hiveservices .sh
|
启动 Hive 后台服务