Hive三大安装模式详解
hive的安装分为三种模式 : 内嵌模式(derby)、本地模式(mysql)、远程模式
安装模式取决于hive元数据存放的存放位置
内嵌模式:内嵌的 Derby 数据库(与 Hive 服务在同一 JVM 进程内)
本地模式:外部独立数据库(如 MySQL、PostgreSQL),通常与 Hive 装在同一台机器上
远程模式:外部独立数据库(通常部署在独立的服务器或使用云数据库)
一 本地模式安装
第一步:安装hive到本地
启动 Hadoop分布式集群 (start-dfs.sh start-yarn.sh zk.sh)
将hive压缩包上传到 /opt/modules
tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /opt/installs/
重命名:
mv apache-hive-3.1.2-bin/ hive
第二步:配置环境变量
以sh为文件后缀即可
配置环境变量:vi /etc/profile.d/custom_env.sh
export HIVE_HOME=/opt/installs/hive
export PATH=$HIVE_HOME/bin:$PATH
刷新环境变量:
source /etc/profile
第三步:配置hive-env.sh
进入这个文件夹下:/opt/installs/hive/conf
cp hive-env.sh.template hive-env.sh
修改hive-env.sh 中的内容:
export HIVE_CONF_DIR=/opt/installs/hive/conf
export JAVA_HOME=/opt/installs/jdk1.8
export HADOOP_HOME=/opt/installs/hadoop3.1.4
export HIVE_AUX_JARS_PATH=/opt/installs/hive/lib
export HADOOP_HEAPSIZE=2048
第四步:给hdfs创建文件夹
hdfs dfs -mkdir -p /user/hive/warehouse
hdfs dfs -mkdir -p /tmp/hive/
hdfs dfs -chmod 777 /user/hive/warehouse
hdfs dfs -chmod 777 /tmp/hive
第五步:检查mysql是否正常
systemctl status mysqld
第六步:
进入到conf 文件夹下,创建这个文件hive-site.xml
修改配置文件 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 athttp://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><!--配置MySql的连接字符串-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<!--配置MySql的连接驱动-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<!--配置登录MySql的用户-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<!--配置登录MySql的密码-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
<description>password to use against metastore database</description>
</property>
<!-- 以下两个不需要修改,只需要了解即可 -->
<!-- 该参数主要指定Hive的数据存储目录 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<!-- 该参数主要指定Hive的临时文件存储目录 -->
<property>
<name>hive.exec.scratchdir</name>
<value>/tmp/hive</value>
</property>
</configuration>
第七步:将mysql的驱动包,上传至 hive 的lib 文件夹下
将mysql的驱动包上传到 /opt/installs/hive/lib 中
第八步:初始化元数据(本质就是在mysql中创建数据库,并且添加元数据)
schematool --initSchema -dbType mysql
第九步: 测试是否成功
输入hive
进入之后 show databases;
看到ok 表明成功
二 远程模式
要通过远程客户端进行操作,则要配置远程模式
第一步:创建临时目录
[root@hadoop11 ~]# cd /opt/installs/hive/
[root@hadoop11hive]# mkdir iotmp
[root@hadoop11hive]# chmod 777 iotmp
第二步:hive 的日志的位置:
cd conf
mv hive-log4j2.properties.template hive-log4j2.properties
第三步:修改配置文件
追加配置 hive-site.xml
<!--Hive工作的本地临时存储空间-->
<property>
<name>hive.exec.local.scratchdir</name>
<value>/opt/installs/hive/iotmp/root</value>
</property>
<!--如果启用了日志功能,则存储操作日志的顶级目录-->
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/opt/installs/hive/iotmp/root/operation_logs</value>
</property>
<!--Hive运行时结构化日志文件的位置-->
<property>
<name>hive.querylog.location</name>
<value>/opt/installs/hive/iotmp/root</value>
</property>
<!--用于在远程文件系统中添加资源的临时本地目录-->
<property>
<name>hive.downloaded.resources.dir</name>
<value>/opt/installs/hive/iotmp/${hive.session.id}_resources</value>
</property>
修改 core-site.xml【hadoop】的
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
<property>
<name>hadoop.http.staticuser.user</name>
<value>root</value>
</property>
<!-- 不开启权限检查 -->
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
同步另外两台
myscp core-site.xml
stop-dfs.sh
start-dfs.sh
第四步:开始配置远程服务(两个)
配置hiveserver2服务
修改hive-site.xml
<property>
<name>hive.server2.thrift.bind.host</name>
<value>hadoop11</value>
</property>
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
启动测试
1. 该服务端口号默认是10000
2. 可以单独启动此服务进程,供远程客户端连接;此服务内置metastore服务。
3. 启动方式:
方法1:
直接调用hiveserver2。会进入监听状态不退出。
弊端是: ctrl + c 窗口关闭之后,服务就停止了
方法2:
hive --service hiveserver2 & # 进入后台启动 但是日志信息会弹出
方法3:
nohup hive --service hiveserver2 >/dev/null 2>&1 & #信息送入黑洞。看不了日志信息
metastore 服务
修改hive-site.xml
修改hive-site.xml的配置
注意:想要连接metastore服务的客户端必须配置如下属性和属性值
<property>
<name>hive.metastore.uris</name>
<value>thrift://hadoop11:9083</value>
</property>解析:thrift:是协议名称
ip为metastore服务所在的主机ip地址
9083是默认端口号
启动方式
方法1:
hive --service metastore & 后台启动
方法2:
nohup hive --service metastore 2>&1 >/dev/null & #信息送入黑洞。
解析:2>&1 >/dev/null 意思就是把错误输出2重定向到标准输出1,也就是屏幕,标准输出进了“黑洞”,也就是标准输出进了黑洞,错误输出打印到屏幕。
Linux系统预留可三个文件描述符:0、1和2,他们的意义如下所示:
0——标准输入(stdin)-- System.in
1——标准输出(stdout)--System.out
2——标准错误(stderr) --System.err
启动命令(编写脚本 hive-service-manager.sh)
#!/bin/bash
# 检查参数是否正确
if [ ! $op ]; then
help_info
elif [ $op != "start" -a $op != "stop" -a $op != "status" ]; then
help_info
fi
# 检查进程状态
metastore_pid=`ps aux | grep org.apache.hadoop.hive.metastore.HiveMetaStore | grep -v grep | awk '{print $2}'`
hiveserver2_pid=`ps aux | grep proc_hiveserver2 | grep -v grep | awk '{print $2}'`
# 检查日志文件夹的存在情况,如果不存在则创建这个文件夹
log_dir=/var/log/my_hive_log
if [ ! -e $log_dir ]; then
mkdir -p $log_dir
fi
# 开启服务
start_metastore() {
# 检查是否开启,如果未开启,则开启 metastore 服务
if [ $metastore_pid ]; then
echo "metastore 服务已经开启,进程号: $metastore_pid,已跳过"
else
nohup hive --service metastore >> $log_dir/metastore.log 2>&1 &
echo "metastore 服务已经开启,日志输出在 $log_dir/metastore.log"
fi
}
start_hiveserver2() {
# 检查是否开启,如果未开启,则开启 hiveserver2 服务
if [ $hiveserver2_pid ]; then
echo "hiveserver2 服务已经开启,进程号: $hiveserver2_pid,已跳过"
else
nohup hive --service hiveserver2 >> $log_dir/hiveserver2.log 2>&1 &
echo "hiveserver2 服务已经开启,日志输出在 $log_dir/hiveserver2.log"
fi
}
# 停止服务
stop_metastore() {
if [ $metastore_pid ]; then
kill -9 $metastore_pid
fi
echo "metastore 服务已停止"
}
stop_hiveserver2() {
if [ $hiveserver2_pid ]; then
kill -9 $hiveserver2_pid
fi
echo "hiveserver2 服务已停止"
}
# 查询服务
status_metastore() {
if [ $metastore_pid ]; then
echo "metastore 服务已开启,进程号: $metastore_pid"
else
echo "metastore 服务未开启"
fi
}
status_hiveserver2() {
if [ $hiveserver2_pid ]; then
echo "hiveserver2 服务已开启,进程号: $hiveserver2_pid"
else
echo "hiveserver2 服务未开启"
fi
}
# 控制操作
if [ ! $server ]; then
${op}_metastore
${op}_hiveserver2
elif [ $server == "metastore" ]; then
${op}_metastore
elif [ $server == "hiveserver2" ]; then
${op}_hiveserver2
else
echo "服务选择错误"
help_info
fi
更多推荐

所有评论(0)