Linux--安装hive

分为三种:内嵌模式、本地模式、远程模式

1、内嵌模式

1、上传 压缩包至  /opt/modules

2、解压至  /opt/installs

tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /opt/installs/

3、重命名

mv apache-hive-3.1.2-bin/ hive

4、配置环境变量 vi /etc/profile

  export HIVE_HOME=/opt/installs/hive
  export PATH=$HIVE_HOME/bin:$PATH

5、刷新环境变量

source /etc/profile

6、配置hive-env.sh

6.1 进入这个文件夹下:/opt/installs/hive/conf
cd /opt/installs/hive/conf
cp hive-env.sh.template hive-env.sh
6.2 修改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

7、进入到conf 文件夹下,修改这个文件hive-site.xml

cp hive-default.xml.template hive-site.xml

接着开始修改:
把Hive-site.xml 中所有包含${system:java.io.tmpdir}替换成/opt/installs/hive/tmp。如果系统默认没有指定系统用户名,那么要把配置${system:user.name}替换成当前用户名root。

使用nodepad++,打开该文件,进行替换: 

一个替换了4处

 一个替换了3处

8、启动集群:

start-all.sh

9、给hdfs创建文件夹:

[root@yunhe01 conf] # hdfs dfs -mkdir -p /user/hive/warehouse 
[root@yunhe01 conf] # hdfs dfs -mkdir -p /tmp/hive/ 
[root@yunhe01 conf] # hdfs dfs -chmod 750 /user/hive/warehouse 
[root@yunhe01 conf] # hdfs dfs -chmod 777 /tmp/hive

10、初始化元数据,因为是内嵌模式,所以使用的数据库是derby

schematool --initSchema -dbType derby

在hive-site.xml中,3215行,96列的地方有一个非法字符

 将这个非法字符,删除,保存即可。

需要再次进行元数据的初始化操作:

schematool --initSchema -dbType derby

提示初始化成功!

初始化操作要在hive的家目录执行,执行完毕之后,会出现一个文件夹:

11、测试是否成功:

-- 进入后可以执行下面命令进行操作:
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,另一个窗口能进入,但是会报错!

 2、本地模式--最常使用的模式

使用本地模式的最大特点是:将元数据从derby数据库,变为mysql数据库,并且支持多窗口同时使用。

1、第一步:检查你的mysql是否正常

systemctl status mysqld

2、第二步:删除以前的derby数据

进入到hive中,删除 
rm -rf metastore_db/ derby.log

3、第三步:修改配置文件 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>

4、将mysql的驱动包,上传至 hive 的lib 文件夹下

 初始化元数据(本质就是在mysql中创建数据库,并且添加元数据)

schematool --initSchema -dbType mysql

5、测试:同时打开两个窗口都可以使用, 支持多个会话。

create database mydb01;
use mydb01;

create table stu (id int,name string);

insert 语句 走MR任务
insert into stu values(1,'wangcai');
select * from stu;
select * from stu limit 10; 
不走MR任务。
创建表的时候,varchar类型需要指定字符长度,否则报错!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值