Hive安装部署

一、简介

Hive官网

二、搭建

准备

  • Hadoop集群(必须搭建完),Hadoop搭建

Hive 安装(注意切换用户hadoop)

  • 下载 Hive
cd /home/hadoop/soft
wget https://dlcdn.apache.org/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz
  • 解压
tar -zxvf apache-hive-3.1.2-bin.tar.gz
  • 下载 Mysql 驱动
cd /home/hadoop/soft/hive/lib
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.49/mysql-connector-java-5.1.49.jar

修改配置

解压成功后,进入/home/hadoop/soft/hive/conf目录,所有的配置文件都在这里,需要进行配置。

  • 新建 hive-site.xml



        
       
             javax.jdo.option.ConnectionURL
             jdbc:mysql://hadoop0001:3306/metastore?useSSL=false
       
        
             javax.jdo.option.ConnectionDriverName
             com.mysql.jdbc.Driver
       
        
             javax.jdo.option.ConnectionUserName
             root
       
        
             javax.jdo.option.ConnectionPassword
             root
       
        
             hive.metastore.schema.verification
             false
       
        
       
             hive.metastore.event.db.notification.api.auth
             false
       
        
       
             hive.metastore.warehouse.dir
             /hive/warehouse
       
       
      
             hive.cli.print.header
             true
      
      
             hive.cli.print.current.db
             true
      

  • 修改 hive 的 log 存放日志到/home/hadoop/hive/logs
cd /home/hadoop/hive/conf
mv hive-log4j2.properties.template hive-log4j2.properties
# 添加
hive.log.dir=/home/hadoop/hive/logs
  • 连接 Mysql 新建 Hive 元数据库
mysql -uroot -p000000
create database metastore
  • 初始化 Hive 元数据库
cd /home/hadoop/soft/hive/bin
schematool -initSchema -dbType mysql -verbose
  • 启动 Hive
bin/hive
  • 测试 Hive
hive> show databases;
hive> show tables;
hive> create table test (id int);
hive> insert into test values(1);
hive> select * from test;

使用元数据服务的方式访问 Hive

  • 在 hive-site.xml 文件中添加如下配置信息
 

   hive.metastore.uris
   thrift://hadoop0001:9083

  • 启动 metastore
hive --service metastore

使用 JDBC 方式访问 Hive

  • 在 hive-site.xml 文件中添加如下配置信息
 

    hive.server2.thrift.bind.host 
    hadoop0001


 
   hive.server2.thrift.port
   10000

  • 启动 hiveserver2
bin/hive --service hiveserver2
  • 启动 beeline 客户端
bin/beeline -u jdbc:hive2://hadoop0001:10000 -n hadoop
  • Hive 服务启动脚本
#!/bin/bash
HIVE_LOG_DIR=/home/hadoop/soft/hive/logs
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 /home/hadoop/soft/hive/bin/hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
[ -z "$metapid" ] && eval $cmd || echo "Metastroe 服务已启动"
server2pid=$(check_process HiveServer2 10000)
cmd="nohup /home/hadoop/soft/hive/bin/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

你可能感兴趣的:(Hive安装部署)