赞
踩
目录
首先一定要开启hadoop集群!!!如果报错连接拒绝,注意有没有开启
1)在 /opt/module/hive/conf/hive-site.xml 文件中添加如下配置信息
[atguigu@hadoop102 software]$ vim $HIVE_HOME/conf/hive-site.xml
//添加的内容
<!-- 指定存储元数据要连接的地址 --><property><name>hive.metastore.uris</name><value>thrift://hadoop102:9083</value></property>
2)启动 metastore
[atguigu@hadoop202 hive]$ bin/hive --service metastore2020-04-24 16:58:08: Starting Hive Metastore Server注意 : 启动后窗口不能再操作,需打开一个新的 shell 窗口做别的操作
3)启动 hive
只有启动了metastore才能启动hive,如果直接启动hive会报错
[atguigu@hadoop202 hive]$ bin/hive
<!-- 指定 hiveserver2 连接的 host --><property><name>hive.server2.thrift.bind.host</name><value> hadoop102 </value></property><!-- 指定 hiveserver2 连接的端口号 --><property><name>hive.server2.thrift.port</name><value> 10000 </value></property>
2)启动 metastore
hiveserver2依赖于metastore
[atguigu@hadoop202 hive]$ bin/hive --service metastore2020-04-24 16:58:08: Starting Hive Metastore Server注意 : 启动后窗口不能再操作,需打开一个新的 shell 窗口做别的操作
[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:10000Connected to: Apache Hive (version 3.1.2)Driver: Hive JDBC (version 3.1.2)Transaction isolation: TRANSACTION_REPEATABLE_READBeeline version 3.1.2 by Apache Hive0: jdbc:hive2://hadoop102:10000>
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。