Hive是基于Hadoop构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在hadoop 分布式文件系统中的数据。其在Hadoop的架构体系中承担了一个SQL解析的过程,它提供了对外的入口来获取用户的指令然后对指令进行分析,解析出一个MapReduce程序组成可执行计划,并按照该计划生成对应的MapReduce任务提交给Hadoop集群处理,获取最终的结果。元数据——如表模式——存储在名为metastore的数据库中。
系统环境ip地址1 hadoop-master
ip地址2 hadoop-slave
MySQL安装在master机器上,hive服务器也安装在master上
下载源码包,最新版本可自行去官网下载
[hadoop@hadoop-master ~]$ wget hive的下载地址[hadoop@hadoop-master ~]$ tar -zxf apache-hive-121-bintargz
[hadoop@hadoop-master ~]$ ls
apache-hive-121-bin apache-hive-121-bintargz dfs hadoop-271 Hsource tmp12341234配置环境变量[root@hadoop-master hadoop]# vi /etc/profile
HIVE_HOME=/home/hadoop/apache-hive-121-bin
PATH=$PATH:$HIVE_HOME/bin
export HIVE_NAME PATHMetastore
metastore是hive元数据集中存放地。它包括两部分:服务和后台数据存储。有三种方式配置metastore:内嵌metastore、本地metastore以及远程metastore。
本次搭建中采用MySQL作为远程仓库,部署在hadoop-master节点上,hive服务端也安装在hive-master上,hive客户端即hadoop-slave访问hive服务器。
mysql>GRANT ALL PRIVILEGES ON TO 'hive'@'hadoop-master' WITH GRANT OPTION;
mysql>flush privileges;123123Hive用户登录[hadoop@hadoop-master ~]mysql -h hadoop-master -uhive
mysql>set password = password('hive');1212创建Hive数据库mysql>create database hive;配置Hive
修改配置文件
进入到hive的配置文件目录下,找到hive-defaultxmltemplate,cp份为hive-defaultxml
另创建hive-sitexml并添加参数
/home/hadoop/apache-hive-121-bin/conf
[hadoop@hadoop-master conf]$ vi hive-sitexml
<configuration>
<property>
<name>javaxjdooptionConnectionURL</name>
<value>jdbc:mysql://hadoop-master:3306/hivecreateDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javaxjdooptionConnectionDriverName</name>
<value>commysqljdbcDriver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javaxjdooptionConnectionUserName</name>
<value>hive<value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javaxjdooptionConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
</configuration>Hive客户端配置[hadoop@hadoop-master ~]$ scp -r apache-hive-121-bin/ hadoop@hadoop-slave:/home/hadoop
[hadoop@hadoop-slave conf]$ vi hive-sitexml
<configuration>
<property>
<name>hivemetastoreuris</name>
<value>thrift://hadoop-master:9083</value>
</property>
</configuration>Hive启动
要启动metastore服务
[hadoop@hadoop-master ~]$ hive --service metastore &[hadoop@hadoop-master ~]$ jps
10288 RunJar #多了一个进程
9365 NameNode
9670 SecondaryNameNode
11096 Jps
9944 NodeManager
9838 ResourceManager
9471 DataNodeHive服务器端访问[hadoop@hadoop-master ~]$ hive
Logging initialized using configuration in jar:file:/home/hadoop/apache-hive-121-bin/lib/hive-common-121jar!/hive-log4jproperties
hive> show databases;
OK
default
src
Time taken: 1332 seconds, Fetched: 2 row(s)
hive> use src;
OK
Time taken: 0037 seconds
hive> create table test1(id int);
OK
Time taken: 0572 seconds
hive> show tables;
OK
abc
test
test1
Time taken: 0057 seconds, Fetched: 3 row(s)
hive>Hive客户端访问[hadoop@hadoop-slave conf]$ hive
Logging initialized using configuration in jar:file:/home/hadoop/apache-hive-121-bin/lib/hive-common-121jar!/hive-log4jproperties
hive> show databases;
OK
default
src
Time taken: 1022 seconds, Fetched: 2 row(s)
hive> use src;
OK
Time taken: 0057 seconds
hive> show tables;
OK
abc
test
test1
Time taken: 0218 seconds, Fetched: 3 row(s)
hive> create table test2(id int ,name string);
OK
Time taken: 5518 seconds
hive> show tables;
OK
abc
test
test1
test2
Time taken: 0102 seconds, Fetched: 4 row(s)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)