启动命令
[root@node1 conf]# nohup hive --service metastore & nohup是放入后台
Hive的产生
非java编程者对hdfs的数据做mapreduce操作
Hive简介
Hive : 数据仓库。
Hive:解释器,编译器,优化器等。
Hive 运行时,元数据存储在关系型数据库(mysql)里面
- 用户接口主要有三个:CLI(命令行),Client 和 WUI。其中最常用的是CLI,Cli启动的时候,会同时启动一个Hive副本。Client是Hive的客户端,用户连接至Hive Server。在启动 Client模式的时候,需要指出Hive Server所在节点,并且在该节点启动Hive Server。 WUI是通过浏览器访问Hive。
- Hive将元数据存储在数据库中,如mysql、derby。Hive中的元数据包括表的名字,表的列和分区及其属性,表的属性(是否为外部表等),表的数据所在目录等。
- 解释器、编译器、优化器完成HQL查询语句从词法分析、语法分析、编译、优化以及查询计划的生成。生成的查询计划存储在HDFS中,并在随后有MapReduce调用执行。
- Hive的数据存储在HDFS中,大部分的查询、计算由MapReduce完成。
Metastore:Mysq
Driver:Hive
Compiler:解释器
Hadoop:Hadoop 数据来源
Hive搭建
Hive的搭建模式
local模式。
此模式连接到一个In-memory 的数据库Derby,一般用于Unit Test。
Mysql模式:
单用户模式:
多用户模式:
通过网络连接到一个数据库中,是最经常使用到的模式:
远程服务器模式/多用户模式。
用于非Java客户端访问元数据库,在服务器端启动MetaStoreServer,客户端利用Thrift协议通过MetaStoreServer访问元数据库
[root@node1 ~]# yum -y install mysql-server
[root@node1 ~]# service mysqld start
[root@node1 ~]# chkconfig mysqld on(开机自启动)
进入mysql
[root@node1 ~]# mysql
mysql> show databases;库
mysql> use mysql进入库
mysql> show tables;展示表
mysql> select host,password from user;
只能本机进入mysql 我们想让node2 node3也能访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
*.*让所有root用户所有ip地址都可以访问mysql密码是123
mysql> delete from user where host!="%";
Hive单用户模式安装
[root@node1 conf]# pwd
/root/apache-hive-1.2.1-bin/conf
[root@node1 conf]# vi 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>
<!--hdfs路径 默认路径-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive_01/warehouse</value>
</property>
<!--连接数据库如果不存在创建 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://node1/hive_01?createDatabaseIfNotExist=true</value>
</property>
<!--驱动-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123</value>
</property>
</configuration>
上传驱动
[root@node1 ~]# mv mysql-connector-java-5.1.32-bin.jar apache-hive-1.2.1-bin/lib/
[root@node1 lib]# pwd
/root/apache-hive-1.2.1-bin/lib
[root@node1 lib]# cp jline-2.12.jar /root/hadoop-2.6.5/share/hadoop/yarn/lib/
[root@node1 lib]# pwd
/root/hadoop-2.6.5/share/hadoop/yarn/lib
[root@node1 lib]# rm -rf jline-0.9.94.jar
[root@node1 ~]# vi .bash_profile
#hive
export HIVE_HOME=/root/apache-hive-1.2.1-bin
export PATH=$PATH:$HIVE_HOME/bin
[root@node1 ~]# source .bash_profile
[root@node1 ~]# hive 可以进去
多用户配置
[root@node1 conf]# pwd
/root/apache-hive-1.2.1-bin/