下载地址:https://downloads.apache.org/hive/hive-3.1.2/
解压在指定目录
tar -zxvf /opt/software/apache-hive-3.1.2-bin.tar.gz -C /opt/module/ mv /opt/module/apache-hive-3.1.2-bin/ /opt/module/hive3.1.2
修改/etc/profile.d/my_env.sh,添加环境变量
#HIVE_HOME export HIVE_HOME=/opt/module/hive3.1.2 export PATH=$PATH:$HIVE_HOME/bin
3.1.2版本执行bin/schematool -dbType derby -initSchema的时候会报一个错误:
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
at org.apache.hadoop.conf.Configuration.set(Configuration.java:1357)
删除掉hive里面的guava-19.0.jar,将hadoop里面的guava-27.0-jre.jar复制到hive里即可。
默认的hive使用内置的derby,不好用,这里修改为mysql。
vim $HIVE_HOME/conf/hive-site.xml
javax.jdo.option.ConnectionURL javax.jdo.option.ConnectionDriverName com.mysql.cj.jdbc.Driver javax.jdo.option.ConnectionUserName pupbook javax.jdo.option.ConnectionPassword pbFeZ^SCWmKg@Jar hive.metastore.schema.verification false hive.metastore.event.db.notification.api.auth false
初始化 Hive 元数据库 schematool -initSchema -dbType mysql -verbose
完整的hive-site.xml的配置
javax.jdo.option.ConnectionURL javax.jdo.option.ConnectionDriverName com.mysql.cj.jdbc.Driver javax.jdo.option.ConnectionUserName pupbook javax.jdo.option.ConnectionPassword pbFeZ^SCWmKg@Jar hive.metastore.schema.verification false hive.metastore.event.db.notification.api.auth false hive.metastore.warehouse.dir /user/hive/warehouse hive.metastore.uris thrift://node101:9083 hive.cli.print.header true hive.cli.print.current.db true hive.server2.thrift.bind.host node101 hive.server2.thrift.port 10000
创建hive启动脚本 vim ~/bin.myhive.sh
#!/bin/bash
HIVE_LOG_DIR=/data_disk/hive/logs
# 配置hive日志目录
if [ ! -d $HIVE_LOG_DIR ]
then
mkdir -p $HIVE_LOG_DIR
fi
#检查进程是否运行正常,参数 1 为进程名,参数 2 为进程端口
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 /opt/module/hive3.1.2/bin/hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
cmd=$cmd" sleep 3; hdfs dfsadmin -safemode wait >/dev/null 2>&1"
[ -z "$metapid" ] && eval $cmd || echo "metastroe 服务已启动"
server2pid=$(check_process HiveServer2 10000)
cmd="nohup /opt/module/hive3.1.2/bin/hive --service 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 3
hive_start
;;
"status")
check_process Hivemetastore 9083 >/dev/null && echo "metastore 服务运行正常" || echo "metastore 服务运行异常"
check_process HiveServer2 10000 >/dev/null && echo "HiveServer2 服务运行正常" || echo "HiveServer2 服务运行异常"
;;
*)
echo Invalid Args!
echo 'Usage: '$(basename $0)' start|stop|restart|status'
;;
esac
chmod +x myhive.sh



