栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

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

目录

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

2.使用 JDBC 方式访问 Hive


首先一定要开启hadoop集群!!!如果报错连接拒绝,注意有没有开启

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

1)在 /opt/module/hive/conf/hive-site.xml 文件中添加如下配置信息

[atguigu@hadoop102 software]$ vim $HIVE_HOME/conf/hive-site.xml

//添加的内容

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

2)启动 metastore

[atguigu@hadoop202 hive]$ bin/hive --service metastore 2020-04-24 16:58:08: Starting Hive metastore Server 注意 : 启动后窗口不能再操作,需打开一个新的 shell 窗口做别的操作

3)启动 hive

只有启动了metastore才能启动hive,如果直接启动hive会报错 

[atguigu@hadoop202 hive]$ bin/hive 

2.使用 JDBC 方式访问 Hive

1)在 hive-site.xml 文件中添加如下配置信息
hive.server2.thrift.bind.host hadoop102 hive.server2.thrift.port 10000

2)启动 metastore 

hiveserver2依赖于metastore

[atguigu@hadoop202 hive]$ bin/hive --service metastore 2020-04-24 16:58:08: Starting Hive metastore Server 注意 : 启动后窗口不能再操作,需打开一个新的 shell 窗口做别的操作
3)启动 hiveserver2

[atguigu@hadoop102 hive]$ bin/hive --service hiveserver2 

一定要多等,可能会很久, 至少出现4个ID可能才开启hiveserver2,如下图:

 为了确保hiveserver2开启,再打开一个shell窗口,查看是否有端口号信息出现

[atguigu@Hadoop102 hive]$ netstat -anop | grep 10000
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::10000                :::*                    LISTEN      12616/java           off (0.00/0/0)
 

 4)启动 beeline 客户端

[atguigu@hadoop102 hive]$ bin/beeline -u jdbc:hive2://hadoop102:10000 -n atguigu 如果报错:Error: Could not open client transport with JDBC Uri: jdbc:hive2://hadoop102:10000: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: atguigu is not allowed to impersonate atguigu (state=08S01,code=0)

解决方案: 报错:Error: Could not open client transport with JDBC Uri: jdbc:hive2://hadoop102:10000_不爱研究的研究僧的博客-CSDN博客

5)看到如下界面即成功 

Connecting to jdbc:hive2://hadoop102:10000 Connected to: Apache Hive (version 3.1.2) Driver: Hive JDBC (version 3.1.2) Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 3.1.2 by Apache Hive 0: jdbc:hive2://hadoop102:10000>
3.编写 hive 服务启动脚本

1)为了方便使用,可以直接编写脚本来管理服务的启动和关闭

[atguigu@hadoop102 hive]$ vim bin/hiveservices.sh

#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME/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 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 服务运行异常"
	check_process HiveServer2 10000 >/dev/null && echo "HiveServer2 服务运行正常" || echo "HiveServer2 服务运行异常"
	;;
*)
	echo Invalid Args!
	echo 'Usage: '$(basename $0)' start|stop|restart|status'
	;;
esac

2)添加执行权限

[atguigu@hadoop102 hive]$ chmod 777 bin/hiveservices.sh

3)启动 Hive 后台服务 

[atguigu@hadoop102 hive]$ hiveservices.sh start

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/735959.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号