Hive2.x环境搭建

5 篇文章 0 订阅
1 篇文章 0 订阅
与 Hadoop 类似,Hive 也有 3 种运行模式:
    1. 内嵌模式
    将元数据保存在本地内嵌的 Derby 数据库中,这是使用 Hive 最简单的方式。但是这种方式缺点也比较明显,
因为一个内嵌的 Derby 数据库每次只能访问一个数据文件,这也就意味着它不支持多会话连接。

    2. 本地模式
    这种模式是将元数据保存在本地独立的数据库中(一般是 MySQL),这用就可以支持多会话和多用户连接了。

    3. 远程模式
    此模式应用于 Hive 客户端较多的情况。把 MySQL 数据库独立出来,将元数据保存在远端独立的 MySQL 服务中,
避免了在每个客户端都安装 MySQL 服务从而造成冗余浪费的情况。


1,从官网下载安装包http://mirrors.shu.edu.cn/apache/hive/

这里选择apache-hive-2.3.2-bin.tar.gz

2,新建hive目录

[hadoop@master hive]$ mkdir -p /opt/hive
[hadoop@master hive]$ sudo chown hadoop:hadoopGroup /opt/hive

将安装包解压到上述目录

3,修改环境变量

vi .bash_profile,增加如下配置

export HIVE_HOME=/opt/hive/apache-hive-2.3.2-bin
export PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$HIVE_HOME/bin
4,配置hive配置文件

4.1,$HIVE_HOME/conf 对应的是 Hive 的配置文件路径, 该路径下的 hive-site.xml 是 Hive 工程的配置文件。

默认情况下,该文件并不存在,我们需要拷贝它的模版来实现:

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

新建目录,iotmp,

修改${system:java.io.tmpdir}为相应的/opt/hive/apache-hive-2.3.2-bin/iotmp

进入vi模式,先按Esc键  再同时按shift+: 把以下替换命令粘贴按回车即可全局替换

%s#${system:java.io.tmpdir}#/opt/hive/apache-hive-2.3.2-bin/iotmp#g 

修改${system:user.name}改为你的用户名,如hive

(网上教程大多数没有提示修改,导致hive启动后运行中会报错: Relative path in absolute URI: ${system:user.name%7D)

其中有两处默认配置

  <property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/user/hive/warehouse</value>
    <description>location of default database for the warehouse</description>
  </property>
....
   <property>
    <name>hive.exec.scratchdir</name>
    <value>/tmp/hive</value>
    <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/&lt;username&gt; is created, with ${hive.scratch.dir.permission}.</description>
  </property>

需要在hdfs上创建相应的文件路径

hdfs dfs -mkdir /user/hive/warehouse
hdfs dfs -mkdir /tmp/hive
hdfs dfs -chmod 777 /user/hive/warehouse
hdfs dfs -chmod 777 /tmp/hive

4.2,同理,修改$HIVE_HOME/conf/hive-env.sh 文件,该文件默认也不存在,同样是拷贝它的模版来实现:

cp hive-env.sh.template  hive-env.sh

并修改相应的变量:

# Set HADOOP_HOME to point to a specific hadoop install directory
 HADOOP_HOME=/opt/hadoop/hadoop-2.7.5

# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/opt/hive/apache-hive-2.3.2-bin/conf

# Folder containing extra libraries required for hive compilation/execution can be controlled by:
export HIVE_AUX_JARS_PATH=/opt/hive/apache-hive-2.3.2-bin/lib

5,启动hive

hive2.x版本需要先进行初始化,这里先使用hive自带数据库

schematool -initSchema -dbType derby

[hadoop@master iotmp]$ schematool -initSchema -dbType derby
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/apache-hive-2.3.2-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL:	 jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver :	 org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:	 APP
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.derby.sql
Initialization script completed
schemaTool completed

6,测试hive

新建文件,table键分隔

[hadoop@master ~]$ more students.txt 
111	andy
222	lucy
333	yueyue
    > create database hive_test;
OK
Time taken: 0.68 seconds
hive> use hive_test;
OK
Time taken: 0.027 seconds
hive> create table student(id int,name string) row format delimited fields terminated by '\t';
OK
    > load data local inpath'/home/hadoop/students.txt' into table hive_test.student;
Loading data to table hive_test.student
OK
Time taken: 0.8 seconds
hive> 
    > 
    > select * from students;
FAILED: SemanticException [Error 10001]: Line 1:14 Table not found 'students'
hive> select * from student;
OK
111    andy
222    lucy
333    yueyue
Time taken: 1.165 seconds, Fetched: 3 row(s)

查看文件系统


告一段落,参考https://www.cnblogs.com/hmy-blog/p/6506417.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值