Hive 环境配置 详解

来源:互联网 发布:旧版本ios软件 编辑:程序博客网 时间:2024/06/05 00:43
1、由于hive依赖于Hadoop框架,所以首先启动Hadoop相关守护进程
注 : 需要先安装Hadoop
-> namenode $ sbin/hadoop-daemon.sh start namenode
-> datanode $ sbin/hadoop-daemon.sh start datanode
-> Resourcemanager $ sbin/yarn-daemon.sh start resourcemanager
-> nodemanager $ sbin/yarn-daemon.sh start nodemanager
-> historyserver $ sbin/mr-jobhistory-daemon.sh start historyserver

2、上传hive安装包到系统,在解压安装包
$ tar -zxf apache-hive-0.13.1-bin.tar.gz -C /opt/modules/
$ cd /opt/modules/hive-0.13.1-bin// 此处的 Hive 文件已被重命名

3、在HDFS上创建对应的目录,并赋予权限
$ cd /opt/modules/hadoop-2.5.0
$ bin/hdfs dfs -mkdir /tmp
$ bin/hdfs dfs -mkdir -p /user/hive/warehouse
$ bin/hdfs dfs -chmod g+w /tmp
$ bin/hdfs dfs -chmod g+w /user/hive/warehouse
注: hadoop fs 在 Hadoop1.x 系列版本中使用的命令
metadata -> 元数据
表和数据的关联 -> 都需要存储
数据库和表
元数据默认存储在 -> Derby数据库
一般公司都存储在关系型数据库中: mysql oracle
/user/hive/warehouse -> 数据仓库目录 -> 保存 hive所有的数据

4、.template代表不启用,不生效的文件
$ cd /opt/modules/hive-0.13.1-bin
$ cd conf/
$ ls


5、hive-default.xml 包含了 hive所有的配置项,hive.metastore.warehouse.dir代表hive在HDFS上的默认目录路径
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>


6、修改 hive-env.sh.template,将template去掉

1> 指定 Hadoop 的工作目录路径
HADOOP_HOME=/opt/modules/hadoop-2.5.0

2> 指定用户自定义文件的所在目录路径:
export HIVE_CONF_DIR=/opt/modules/hive-0.13.1-bin/conf


7、启动hive
$ cd /opt/modules/hive-0.13.1-bin
$ bin/hive
hive提供了一个可以交互的shell命令行


8、创建一张表
create table student(
num int,
name string
) row format delimited fields terminated by'\t';
注: hive 的命令行中不允许出 Tab键


-> 需要指定分隔符,让数据文件与表的结构对应
->创建一个测试文件

-> 加载数据
load data local inpath '/opt/datas/student.txt' into table student;


0 0