远程模式搭建Hive

171 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第8天,点击查看活动详情

 远程模式即服务端与客户端在不同的机器上。在之前的博客中已经记录了三台节点搭建的hadoop集群,并在hadoop02上安装了hive,在hadoop03上安装了mysql。这里我们将hadoop01节点作为hive的客户端,hadoop02作为hive的服务端。

  • 要使用远程模式,需要在Hadoop的每个节点上的core-site.xml中添加如下配置:
[root@hadoop01 hadoop]# pwd
/usr/local/wyh/hadoop-2.7.5/etc/hadoop

[root@hadoop01 hadoop]# vi core-site.xml
#添加如下配置
        <property>
                <name>hadoop.proxyuser.root.hosts</name>
                <value>*</value>
        </property>
        <property>
                <name>hadoop.proxyuser.root.groups</name>
                <value>*</value>
        </property>
  • 修改完配置之后,需要重启hadoop服务
[root@hadoop01 hadoop]# stop-all.sh
[root@hadoop01 hadoop]# start-all.sh
  • 在hadoop01上安装Hive

解压:

[root@hadoop01 wyh]# tar -zxvf apache-hive-2.3.9-bin.tar.gz

配置环境变量:

[root@hadoop01 wyh]# vi /etc/profile
#添加
HIVE_HOME=/usr/local/wyh/apache-hive-2.3.9-bin
PATH=$PATH:$HIVE_HOME/bin
export HIVE_HOME PATH

#使配置生效
[root@hadoop01 wyh]# source /etc/profile
  • 在hadoop02上开启hiveserver2服务

开启hive服务端可以有两种方式,这里我采用hiveserver2的这种方式。

[root@hadoop02 hadoop]# hive --service hiveserver2 &

  • 在hadoop01上使用beeline直连的方式连接hive服务端

由于hive服务端开启服务有两种不同的方式,所以在客户端连接hive服务端时,也对应了不同的连接方式。由于前面使用的是hiveserver2的方式启动的服务端,所以这里就需要使用beeline的方式连接服务端。

[root@hadoop01 wyh]# beeline -u jdbc:hive2://hadoop02:10000 -n root

 连接成功:

 退出客户端:

0: jdbc:hive2://hadoop02:10000> !quit

#########################  hive 服务的第二种方式  #############################

先将用第一种方式启动的hive服务停掉:

  •  在hadoop02上启动metastore服务
[root@hadoop02 hadoop]# hive --service metastore &

 

  •  在hadoop01上添加metastore配置

使用metastore这种方式启动hive服务时,在客户端连接时需要先添加配置:

[root@hadoop01 conf]# pwd
/usr/local/wyh/apache-hive-2.3.9-bin/conf

#新建一个hive-site.xml文件
[root@hadoop01 conf]# cat hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<configuration>
        <property>
                <name>hive.metastore.uris</name>
                <value>thrift://hadoop02:9083</value>
        </property>
</configuration>


#thrift为协议名称,后面跟的是metastore服务所在的主机ip,9083为默认端口号

配置好之后直接启动hive即可连接:

[root@hadoop01 conf]# hive

连接成功:

退出客户端:

hive> quit
    > ;

############################################################################

以上就是远程模式搭建Hive的过程。