Hive安装部署

 Hive安装部署

 1、Hive安装及配置

(1)把apache-hive-3.1.2-bin.tar.gz上传到linux的/opt/software目录下

(2)解压apache-hive-3.1.2-bin.tar.gz到/opt/module/目录下面

tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /opt/module/

(3)修改apache-hive-3.1.2-bin.tar.gz的名称为hive

mv /opt/module/apache-hive-3.1.2-bin/ /opt/module/hive

(4)修改/etc/profile.d/my_env.sh,添加环境变量

sudo vim /etc/profile.d/my_env.sh
#添加内容
#HIVE_HOME
export HIVE_HOME=/opt/module/hive
export PATH=$PATH:$HIVE_HOME/bin
#重启Xshell对话框使环境变量生效

(5)替换hive中的guava.jar

cp $HADOOP_HOME/share/hadoop/common/lib/guava-27.0-jre.jar $HIVE_HOME/lib/
rm $HIVE_HOME/lib/guava-19.0.jar

(6)解决日志Jar包冲突

mv $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.jar $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.bak

2、Hive元数据配置到MySql 

2.1 拷贝驱动

将MySQL的JDBC驱动拷贝到Hive的lib目录下

cp /opt/software/mysql-connector-java-5.1.48.jar $HIVE_HOME/lib

2.2 配置Metastore到MySql

在$HIVE_HOME/conf目录下新建hive-site.xml文件

vim $HIVE_HOME/conf/hive-site.xml

添加如下内容

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://hadoop102:3306/metastore?useSSL=false</value>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.jdbc.Driver</value>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>000000</value>
    </property>

    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive/warehouse</value>
    </property>

    <property>
        <name>hive.metastore.schema.verification</name>
        <value>false</value>
    </property>

    <property>
        <name>datanucleus.schema.autoCreateAll</name>
        <value>true</value> 
    </property>

    <property>
        <name>hive.metastore.uris</name>
        <value>thrift://hadoop102:9083</value>
    </property>

    <property>
    <name>hive.server2.thrift.port</name>
    <value>10000</value>
    </property>

    <property>
        <name>hive.server2.thrift.bind.host</name>
        <value>hadoop102</value>
    </property>

    <property>
        <name>hive.metastore.event.db.notification.api.auth</name>
        <value>false</value>
    </property>

</configuration>

3、安装Tez引擎

(1) 将tez安装包拷贝到集群

(2) 解压tar包

tar -zxvf /opt/software/apache-tez-0.9.2-bin.tar.gz -C /opt/module

(3) 重命名

mv /opt/module/apache-tez-0.9.2-bin /opt/module/tez

(4) 上传tez依赖到HDFS

hadoop fs -mkdir /tez
hadoop fs -put /opt/module/tez/share/tez.tar.gz /tez

(5) 新建tez-site.xml

vim $HADOOP_HOME/etc/hadoop/tez-site.xml

添加如下内容:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
  <property>
    <name>tez.lib.uris</name>
    <value>${fs.defaultFS}/tez/tez.tar.gz</value>
  </property>
  <property>
    <name>tez.use.cluster.hadoop-libs</name>
    <value>true</value>
  </property>
  <property>
    <name>tez.history.logging.service.class</name>
    <value>org.apache.tez.dag.history.logging.ats.ATSHistoryLoggingService</value>
  </property>
  <property>
    <name>tez.am.resource.memory.mb</name>
    <value>1024</value>
  </property>
  <property>
    <name>tez.am.resource.cpu.vcores</name>
    <value>1</value>
  </property>
  <property>
    <name>tez.container.max.java.heap.fraction</name>
    <value>0.4</value>
  </property>
  <property>
    <name>tez.task.resource.memory.mb</name>
    <value>1024</value>
  </property>
  <property>
    <name>tez.task.resource.cpu.vcores</name>
    <value>1</value>
  </property>
</configuration>

 

(6) 修改Hadoop环境变量

编辑hadoop-env.sh

vim $HADOOP_HOME/etc/hadoop/hadoop-env.sh

添加Tez的Jar包相关信息

export TEZ_CONF_DIR=$HADOOP_HOME/etc/hadoop
export TEZ_JARS=/opt/module/tez
export HADOOP_CLASSPATH=${HADOOP_CLASSPATH}:${TEZ_CONF_DIR}:${TEZ_JARS}/*:${TEZ_JARS}/lib/*

(7) 修改Hive的计算引擎

vim $HIVE_HOME/conf/hive-site.xml

添加

<property>
<name>hive.execution.engine</name>
<value>tez</value>
</property>

(8) 解决日志Jar包冲突

rm /opt/module/tez/lib/slf4j-log4j12-1.7.10.jar

4、启动Hive  

4.1 初始化元数据库

登陆MySQL

mysql -uroot -pxxxx

新建Hive元数据库

create database metastore;
quit;

初始化Hive元数据库

schematool -initSchema -dbType mysql -verbose

4.2 启动metastore和hiveserver2

Hive 2.x以上版本,要先启动这两个服务,否则会报错:

FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

编写hive服务启动脚本

vim $HIVE_HOME/bin/hiveservices.sh

 

内容如下:

#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME/logs

mkdir -p $HIVE_LOG_DIR

#检查进程是否运行正常,参数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 hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
    cmd=$cmd" sleep 4; hdfs dfsadmin -safemode wait >/dev/null 2>&1"
    [ -z "$metapid" ] && eval $cmd || echo "Metastroe服务已启动"
    server2pid=$(check_process HiveServer2 10000)
    cmd="nohup 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 2
    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 $HIVE_HOME/bin/hiveservices.sh

启动Hive后台服务

hiveservices.sh start

4.3 HiveJDBC访问  

##xxx标识用户名
beeline -u jdbc:hive2://hadoop102:10000 -n xxx

  

posted @ 2020-12-31 16:06  coolid  阅读(178)  评论(1编辑  收藏  举报