hive服务启动的几种方式

hive的两种后台服务,到底是干什么的

hive是hadoop的客户端,所以第一步是启动hadoop集群。

希望大家可以关注下公众号,会定期分享自己从业经历、技术积累及踩坑经验,支持一下,鞠躬感谢~
在这里插入图片描述


hive连元数据有两种方式连接。

第一种是直连,就是直接去mysql的metastore库里去连接。

另一种通过服务去连接,hive有个服务叫metastore,还有一个服务叫hiveserver2。hive去启动metastore服务,然后服务去连接mysql,找到元数据。

怎么控制hive连接元数据的方式呢?

就看hive-site.xml配置文件里是否有hive.metastore.uris 这行相关的配置命令。如果有,就是用metastore服务去连接。

如果没有这个配置命令,但是有下面的关于jdbc的配置命令,那就是通过直连mysql的方式。

<!-- jdbc连接的URL -->
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://hadoop102:3306/metastore?useSSL=false</value>
</property>

    <!-- jdbc连接的Driver-->
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.jdbc.Driver</value>
</property>

	<!-- jdbc连接的username-->
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
    </property>

    <!-- jdbc连接的password -->
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>123456</value>
    </property>

可以直接执行命令[atguigu@hadoop103 hive]$ bin/hive,然后进行一系列查询数据的操作,结果正常展示。

  1. 使用metastore服务连接mysql服务
<!-- 指定存储元数据要连接的地址 -->
<property>
		<name>**hive.metastore.uris**</name>
		<value>thrift://hadoop102:9083</value>
</property>

如果hive-site.xml文件中配置里有以上命令。在shell命令行中,输入hive,然后show databases,就会报错。

这是因为我没有启动metastore这个服务。

输入如下命令,就前台启动了metastore 服务(只有这个服务一直存在,才能保证hive一直能够连接到mysql的元数据)。

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

这样在重新试一试show databases命令,正常显示结果。

hive比较特殊,它既是自己的客户端,又是服务端。

在公司里,很可能有不止一个hive客户端,比如,mysql在100机器上,而机器102 103 104上都有hive客户端,而mysql ip地址只对102机器暴露,103、104机器访问不了mysql。这样103就只能通过metastore这种方式来连接mysql的元数据。就是在102 上启动metastore服务,然后用103来连接102。103 104 上有hive相关文件,同时hive-site.xml文件中只配置**hive.metastore.uris**相关命令就行了。

在102上启动metastore服务,命令hive --service metastore ,然后103上使用命令[atguigu@hadoop103 hive]$ bin/hive,然后进行一系列查询数据的操作,正常展示。

  1. hiveserver2服务 hive客户端连接客户端

hive是hadoop的客户端,同时hive本身也有客户端。

两种启动方式。

[atguigu@hadoop202 hive]$ hive --service hiveserver2

另一种方式:

[atguigu@hadoop102 bin]$ pwd
/opt/module/hive/bin

[atguigu@hadoop102 bin]$ cat hiveserver2 
#!/usr/bin/env bash

# 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.

bin=`dirname "$0"`
bin=`cd "$bin"; pwd`

. "$bin"/hive --service hiveserver2 "$@"

可以看到,系统自带脚本hiveserver2 的命令最后一行就是启动命令。

这个hiveserver2 服务启动以后,就能通过hive的客户端来连接hive了。

单独启动hiveserver2服务,比较费窗口,就是那个窗口不能进行任何的命令输入。

可以用下面的写法,后台方式启动:

[atguigu@hadoop102 bin]$ nohup hiveserver2 &
[1] 3565
[atguigu@hadoop102 bin]$ nohup: 忽略输入并把输出追加到"nohup.out"

nohup: 放在命令开头,表示不挂起,也就是关闭终端进程也继续保持运行状态

&: 放在命令结尾,表示后台运行

然后多回车几下,就可以继续输入命令了。

但是这样的话,进程比较多,万一有两个RunJar进程,怎么关闭自己想关闭的RunJar进程呢?

[atguigu@hadoop102 bin]$ jpsall
=============== hadoop102 ===============
2003 JobHistoryServer
1413 NameNode
1834 NodeManager
3565 RunJar
1534 DataNode
=============== hadoop103 ===============
1572 NodeManager
1429 ResourceManager
1239 DataNode
=============== hadoop104 ===============
1335 SecondaryNameNode
1451 NodeManager
1244 DataNode
[atguigu@hadoop102 bin]$

可以用脚本

jpsall - l 如果不行,就用jpsall - m,根据详细显示信息,进行kill -9 进程号

[atguigu@hadoop102 bin]$ **jpsall -m**
=============== hadoop102 ===============
2003 JobHistoryServer
1413 NameNode
1834 NodeManager
**3565 RunJar /opt/module/hive/lib/hive-service-3.1.2.jar org.apache.hive.service.server.HiveServer2**
1534 DataNode
=============== hadoop103 ===============
1572 NodeManager
1429 ResourceManager
1239 DataNode
=============== hadoop104 ===============
1335 SecondaryNameNode
1451 NodeManager
1244 DataNode
[atguigu@hadoop102 bin]$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值