本次介绍的时HIVE的本地模式安装及远程模式配置,HIVE是一个框架,可以通过编写sql的方式,自动的编译为MR任务的一个工具。其底层依赖Hadoop,所以每一次都需要启动Hadoop(hdfs以及yarn)。
一、本地模式安装
Hive官网地址:Apache Hivehttp://hive.apache.org/
首先下载好压缩包,将压缩包上传解压,然后配置环境变量,配置完后记得刷新环境变量:
配置环境变量:vi /etc/profile.d/custom_env.sh
<!-- 追加如下内容 -->
export HIVE_HOME=/opt/installs/hive
export PATH=$HIVE_HOME/bin:$PATH
<!-- 保存并刷新环境变量 -->
source /etc/profile
然后进入我们解压存放的../hive/conf的文件夹下对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/jdk
export HADOOP_HOME=/opt/installs/hadoop
export HIVE_AUX_JARS_PATH=/opt/installs/hive/lib
export HADOOP_HEAPSIZE=2048
然后我们启动Hadoop集群,(可选)给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,并对其进行修改配置文件
<?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>
<!--配置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中创建数据库,并且添加元数据):schematool --initSchema -dbType mysql 。搭配好后可以进行测试看是否配置成功
输入hive 进入后,可以编写sql
hive> show databases;
OK
default
-- 进入后可以执行下面命令进行操作:
hive>show databases; -- 查看数据库
hive>show tables; -- 查看表
-- 创建表
hive> create table dog(id int,name string);
hive> select * from dog;
hive> insert into dog values(1,'wangcai');
hive> desc dog; -- 查看表结构
hive> quit; -- 退出
二、Hive的远程模式
搭配好本地后就可以尝试搭配远程模式了,我们进到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>
开始配置远程服务,先配置hiveserver2服务,修改hive-site.xml文件
<property>
<name>hive.server2.thrift.bind.host</name>
<value>bigdata01</value>
</property>
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
启动方式:
方法1:
直接调用hiveserver2。会进入监听状态不退出。
弊端是: ctrl + c 窗口关闭之后,服务就停止了
方法2:
hive --service hiveserver2 & # 进入后台启动
方法3:
nohup hive --service hiveserver2 >/dev/null 2>&1 & #信息送入黑洞。
然后我们配置metastore服务,意义是:为别人连接MySQL元数据提供服务的。注意配置metastore以后,必须启动metastore,否则报错。继续打开hive-site.xml 文件进行配置
修改hive-site.xml的配置
注意:想要连接metastore服务的客户端必须配置如下属性和属性值
<property>
<name>hive.metastore.uris</name>
<value>thrift://bigdata01: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,也就是屏幕,标准输出进了“黑洞”,也就是标准输出进了黑洞,错误输出打印到屏幕。
到此我们的远程模式也配置完成,我们可以测试看是否配置成功,远程模式配置后我们可以使用客户端连接工具连接hive,常见的Hive连接工具有:IDEA、DBeaver、DataGrap、Beeline。
感谢阅读,我们下次再见~