博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hive学习(三)安装配置
阅读量:3907 次
发布时间:2019-05-23

本文共 5211 字,大约阅读时间需要 17 分钟。

目录


官网地址:

下载地址:

官方wiki文档:

安装部署

由于Hive是运行在Hadoop之上的,所以在安装Hive之前,需安装Hadoop环境。

1. 把 apache-hive-1.2.1-bin.tar.gz 上传到 linux 的/opt/software 目录下

2. 解压 apache-hive-1.2.1-bin.tar.gz 到/opt/module/目录下面

tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/module/

3. 修改 apache-hive-1.2.1-bin.tar.gz 的名称为 hive mv apache-hive-1.2.1-bin/ hive

4. 修改/opt/module/hive/conf 目录下的 hive-env.sh.template 名称为 hive-env.sh mv hive-env.sh.template hive-env.sh

5. 配置 hive-env.sh 文件

  • 配置 HADOOP_HOME 路径
export HADOOP_HOME=/opt/module/hadoop-2.7.2
  • 配置 HIVE_CONF_DIR 路径

export HIVE_CONF_DIR=/opt/module/hive/conf

Hive基本操作

启动Hive,进入Hive安装目录,执行bin/hive

[root@izuf6i3w0v8mmmqlv77eanz apache-hive-1.2.1-bin]# bin/hive​Logging initialized using configuration in jar:file:/opt/module/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.propertieshive>
-- 查看数据库show databases;-- 打开默认库use default;-- 显示default数据库中的表show tables;-- 创建一张表create table student(id int,name string);-- 查看表的结构desc student;-- 向表中插入数据insert into student values(1, 'iceinl=k');-- 查询表中数据select * from student;-- 退出hivequit;

将本地文件导入hive

需求:将本地 /opt/module/datas/student.txt 这个目录下的数据导入到 hive 的 student(id int, name string)表中。

student.txt表数据

1   iceink2   icydate3   baka

操作步骤:

-- 删除已经创建的student表hive> drop table student;-- 创建student表,并声明文件分隔符'\t'hive> create table student (id int,name string) row format delimited fields terminated by '\t'; -- 加载数据到student表中hive> load data local inpath '/opt/module/datas/student.txt' into table student;Loading data to table default.student-- 查询结果hive> select * from student;OK1   iceink2   icydate3   bakaTime taken: 0.29 seconds, Fetched: 4 row(s)

遇到的问题

在打开一个客户端窗口启动Hive,会产生 java.sql.SQLException 异常。

[root@izuf6i3w0v8mmmqlv77eanz apache-hive-1.2.1-bin]# bin/hive​Logging initialized using configuration in jar:file:/opt/module/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.propertiesException in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient    at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:522)    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:677)    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:621)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)Caused by: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient    at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1523)    at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.
(RetryingMetaStoreClient.java:86) at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:132) at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:104) at org.apache.hadoop.hive.ql.metadata.Hive.createMetaStoreClient(Hive.java:3005) at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:3024) at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:503) ... 8 more

原因:Metastore 默认存储在自带的 derby 数据库中,推荐使用 MySQL 存储 Metastore

查看在hive中输入的所有历史命令

  1. 进入到当前用户的根目录:cd ~

  2. 查看. hivehistory 文件:[root@izuf6i3w0v8mmmqlv77eanz ~]# more .hivehistory

Hive常见属性配置

数据仓库位置配置

  1. default 数据仓库的最原始位置是在 hdfs 上的:/user/hive/warehouse 路径下

  2. 在仓库目录下,没有对默认的数据库 default 创建文件夹。如果某张表属于 default数据库,直接在数据仓库目录下创建一个文件夹。

    如:

          

修改 default 数据仓库原始位置(将 hive-default.xml.template 如下配置信息拷贝到hive-site.xml 文件中)。

   
hive.metastore.warehouse.dir
   
/user/hive/warehouse
   
location of default database for the   warehouse

查询后信息显示配置

在 hive-site.xml 文件中添加如下配置信息,就可以实现显示当前数据库,以及查询表的头信息配置?

   
hive.cli.print.header
   
true
   
hive.cli.print.current.db
   
true

运行日志信息配置

1. Hive 的 log 默认存放在 /tmp/root/hive.log 目录下(当前用户名下)

2. 修改 hive 的 log 存放日志到/opt/module/hive/logs

  • 修改 /opt/module/hive/conf/hive-log4j.properties.template 文件名称为 hive-log4j.properties

  • 在 hive-log4j.properties 文件中修改 log 存放位置 hive.log.dir=/opt/module/hive/logs

配置参数方式

查看当前所有的配置信息:hive> set

参数配置的三种方式:

  • 配置文件方式

  • 命令行参数方式

  • 声明式参数方式

 

下面详细解释一下参数配置的三种方式:

1. 配置文件方式

默认配置文件:hive-default.xml

用户自定义配置文件:hive-site.xml

注意:用户自定义配置会覆盖默认配置。另外,Hive 也会读入 Hadoop 的配置,因为 Hive 是作为 Hadoop 的客户端启动的,Hive 的配置会覆盖 Hadoop 的配置。配置文件的设定对本机启动的所有 Hive 进程都有效。

2. 命令行参数方式

启动 Hive 时,可以在命令行添加-hiveconf param=value 来设定参数。

例如:

[root@izuf6i3w0v8mmmqlv77eanz apache-hive-1.2.1-bin]# bin/hive -hiveconf mapred.reduce.tasks=10;

注意:仅对本次Hive启动有效

查看参数设置:

hive> set mapred.reduce.tasks;mapred.reduce.tasks=10

3. 参数声明方式

可以在 HQL 中使用 SET 关键字设定参数

例如:

hive> set mapred.reduce.tasks=100;​hive> set mapred.reduce.tasks;mapred.reduce.tasks=100

注意:仅对本次Hive启动有效

总结:

上述三种设定方式的优先级依次递增。即配置文件<命令行参数<参数声明。注意某些系统级的参数,例如 log4j 相关的设定,必须用前两种方式设定,因为那些参数的读取在会话建立以前已经完成了。

转载地址:http://liqen.baihongyu.com/

你可能感兴趣的文章
Lowest Common Ancestor
查看>>
EM Intro
查看>>
Online Learning
查看>>
Delete Last Element
查看>>
Python list reverse
查看>>
Level Order Tree Traversal
查看>>
REST and SOAP
查看>>
Web Browse Process
查看>>
Hash
查看>>
Hash in Python
查看>>
取模运算和求余运算的区别
查看>>
Modulo and Reminder
查看>>
Round robin
查看>>
consistent hashing
查看>>
Crawler
查看>>
Bloom Filter
查看>>
Dynamic Programming
查看>>
Python hashmap
查看>>
python 切片
查看>>
interview sum
查看>>