共计 5028 个字符,预计需要花费 13 分钟才能阅读完成。
一、实验环境
1. 软件版本:apache-hive-2.3.0-bin.tar.gz、mysql-community-server-5.7.19
2.mysql JDBC 驱动包:mysql-connector-java-5.1.44.tar.gz
3.mysql 已经安装在 Hadoop5 上
4.. 主机规划
hadoop3 | Remote:client |
hadoop5 | Remote:server;mysql |
二、基础配置
1. 解压并移动 hive
[root@hadoop5 ~]
# tar -zxf apache-hive-2.3.0-bin.tar.gz
[root@hadoop5 ~]
# cp -r apache-hive-2.3.0-bin /usr/local/hive
2. 修改环境变量
[root@hadoop5 ~]
# vim /etc/profile
export
HIVE_HOME=
/usr/local/hive
export
PATH=$HIVE_HOME
/bin
:$PATH
[root@hadoop5 ~]
# source /etc/profile
3. 复制初始文件
[root@hadoop5 ~]
# cd /usr/local/hive/conf/
[root@hadoop5 conf]
# cp hive-env.sh.template hive-env.sh
[root@hadoop5 conf]
# cp hive-default.xml.template hive-site.xml
[root@hadoop5 conf]
# cp hive-log4j2.properties.template hive-log4j2.properties
[root@hadoop5 conf]
# cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
4. 修改 hive-env.sh 文件
[root@hadoop5 conf]
# vim hive-env.sh #在最后添加
export
JAVA_HOME=
/usr/local/jdk
export
HADOOP_HOME=
/usr/local/hadoop
export
HIVE_HOME=
/usr/local/hive
export
HIVE_CONF_DIR=
/usr/local/hive/conf
5. 拷贝 mysql 的 JDBC 驱动包
[root@hadoop5 ~]
# tar -zxf mysql-connector-java-5.1.44.tar.gz
[root@hadoop5 ~]
# cp mysql-connector-java-5.1.44/mysql-connector-java-5.1.44-bin.jar /usr/local/hive/lib/
6. 在 hdfs 中创建一下目录,并授权,用于存储文件
hdfs dfs -
mkdir
-p
/user/hive/warehouse
hdfs dfs -
mkdir
-p
/user/hive/tmp
hdfs dfs -
mkdir
-p
/user/hive/log
hdfs dfs -
chmod
-R 777
/user/hive/warehouse
hdfs dfs -
chmod
-R 777
/user/hive/tmp
hdfs dfs -
chmod
-R 777
/user/hive/log
7. 在 mysql 中创建相关用户和库
mysql> create database metastore;
Query OK, 1 row affected (0.03 sec)
mysql>
set
global validate_password_policy=0;
Query OK, 0 rows affected (0.26 sec)
mysql> grant all on metastore.* to hive@
'%'
identified by
'hive123456'
;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
7. 使用 scp 将 hive 拷贝到 hadoop3 上
[root@hadoop5 ~]
# scp -r /usr/local/hive root@hadoop3:/usr/local/
三、修改配置文件
1. 服务端 hive-site.xml 的配置
<configuration>
<property>
<name>hive.
exec
.scratchdir<
/name
>
<value>
/user/hive/tmp
<
/value
>
<
/property
>
<property>
<name>hive.metastore.warehouse.
dir
<
/name
>
<value>
/user/hive/warehouse
<
/value
>
<
/property
>
<property>
<name>hive.querylog.location<
/name
>
<value>
/user/hive/log
<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionURL<
/name
>
<value>jdbc:mysql:
//hadoop5
:3306
/metastore
?createDatabaseIfNotExist=
true
&characterEncoding=UTF-8&useSSL=
false
<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionDriverName<
/name
>
<value>com.mysql.jdbc.Driver<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionUserName<
/name
>
<value>hive<
/value
>
<
/property
>
<property>
<name>javax.jdo.option.ConnectionPassword<
/name
>
<value>hive123456<
/value
>
<
/property
>
<
/configuration
>
2. 客户端 hive-site.xml 的配置
<configuration>
<property>
<name>hive.metastore.uris<
/name
>
<value>thrift:
//hadoop5
:9083<
/value
>
<
/property
>
<property>
<name>hive.
exec
.scratchdir<
/name
>
<value>
/user/hive/tmp
<
/value
>
<
/property
>
<property>
<name>hive.metastore.warehouse.
dir
<
/name
>
<value>
/user/hive/warehouse
<
/value
>
<
/property
>
<property>
<name>hive.querylog.location<
/name
>
<value>
/user/hive/log
<
/value
>
<
/property
>
<property>
<name>hive.metastore.
local
<
/name
>
<value>
false
<
/value
>
<
/property
>
<
/configuration
>
四、启动 hive(两种方式)
首先格式化数据库
schematool --dbType mysql --initSchema
1. 直接启动
service:
[root@hadoop5 ~]
# hive --service metastore
client:
[root@hadoop3 ~]
# hive
hive> show databases;
OK
default
Time taken: 1.599 seconds, Fetched: 1 row(s)
hive> quit;
2.beeline 方式
需要先在 hadoop 的 core-site.xml 中添加配置
<property>
<name>hadoop.proxyuser.root.
groups
<
/name
>
<value>*<
/value
>
<
/property
>
<property>
<name>hadoop.proxyuser.root.hosts<
/name
>
<value>*<
/value
>
<
/property
>
service:
[root@hadoop5 ~]
# nohup hiveserver2 &
[root@hadoop5 ~]
# netstat -nptl | grep 10000
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 3464
/java
client:
[root@hadoop3 ~]
# beeline
Beeline version 1.2.1.spark2 by Apache Hive
beeline>
beeline> !connect jdbc:hive2:
//hadoop5
:10000 hive hive123456
Connecting to jdbc:hive2:
//hadoop5
:10000
17
/09/21
09:47:31 INFO jdbc.Utils: Supplied authorities: hadoop5:10000
17
/09/21
09:47:31 INFO jdbc.Utils: Resolved authority: hadoop5:10000
17
/09/21
09:47:31 INFO jdbc.HiveConnection: Will try to
open
client transport with JDBC Uri: jdbc:hive2:
//hadoop5
:10000
Connected to: Apache Hive (version 2.3.0)
Driver: Hive JDBC (version 1.2.1.spark2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2:
//hadoop5
:10000> show databases;
+----------------+--+
| database_name |
+----------------+--+
| default |
+----------------+--+
1 row selected (2.258 seconds)
Hive 编程指南 PDF 中文高清版 http://www.linuxidc.com/Linux/2015-01/111837.htm
基于 Hadoop 集群的 Hive 安装 http://www.linuxidc.com/Linux/2013-07/87952.htm
Hive 集成 sentry 的 sql 使用语法 http://www.linuxidc.com/Linux/2017-09/146878.htm
Hive 安装及与 HBase 的整合 http://www.linuxidc.com/Linux/2016-12/138721.htm
Hive 2.1.1 安装配置详解 http://www.linuxidc.com/Linux/2017-04/143053.htm
基于 Ubuntu Hadoop 的群集搭建 Hive http://www.linuxidc.com/Linux/2016-12/138699.htm
Hive 的详细介绍 :请点这里
Hive 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-10/147638.htm