1 Hive
安装地址
1
)
Hive
官网地址
http://hive.apache.org/
2
)文档查看地址
https://cwiki.apache.org/confluence/display/Hive/GettingStarted
3
)下载地址
http://archive.apache.org/dist/hive/
4
)
github
地址
https://github.com/apache/hive
2Hive
安装部署
2.1
安装
Hive
1
)把
apache-hive-3.1.2-bin.tar.gz
上传到
linux
的
/opt/software
目录下
2
)解压
apache-hive-3.1.2-bin.tar.gz
到
/opt/module/
目录下面
[atguigu@hadoop102 software]$ tar -zxvf /opt/software/apache-hive-3.1.2-
bin.tar.gz -C /opt/module/
3
)修改
apache-hive-3.1.2-bin.tar.gz
的名称为
hive
[atguigu@hadoop102 software]$ mv /opt/module/apache-hive-3.1.2-bin/
/opt/module/hive
4
)修改
/etc/profile.d/my_env.sh
,添加环境变量
[atguigu@hadoop102 software]$ sudo vim /etc/profile.d/my_env.sh
5
)添加内容
#HIVE_HOME
export HIVE_HOME=/opt/module/hive
export PATH=$PATH:$HIVE_HOME/bin
6
)解决日志
Jar
包冲突
[atguigu@hadoop102 software]$ mv $HIVE_HOME/lib/log4j-slf4j-impl-
2.10.0.jar $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.bak
7
)初始化元数据库
[atguigu@hadoop102 hive]$ bin/schematool -dbType derby -initSchema
2.2
启动并使用
Hive
1
)启动
Hive
[atguigu@hadoop102 hive]$ bin/hive
2
)使用
Hive
hive> show databases;
hive> show tables;
hive> create table test(id int);
hive> insert into test values(1);
hive> select * from test;
3
)在
CRT
窗口中开启另一个窗口开启
Hive
,在
/tmp/atguigu
目录下监控
hive.log
文件
原因在于
Hive
默认使用的元数据库为
derby
,开启
Hive
之后就会占用元数据库,且不与
其他客户端共享数据,所以我们需要将
Hive
的元数据地址改为
MySQL
2.3MySQL
安装
4)在安装目录下执行 rpm 安装
5)删除/etc/my.cnf 文件中 datadir 指向的目录下的所有内容,如果有内容的情况下:
6)初始化数据库
[atguigu @hadoop102 opt]$ sudo mysqld --initialize --user=mysql
7
)查看临时生成的
root
用户的密码
2.4 Hive 元数据配置到 MySQL
2.4.1
拷贝驱动
将
MySQL
的
JDBC
驱动拷贝到
Hive
的
lib
目录下
[atguigu@hadoop102 software]$ cp /opt/software/mysql-connector-java-
5.1.37.jar $HIVE_HOME/lib
2.4.2
配置
metastore
到
MySQL
1
)在
$HIVE_HOME/conf
目录下新建
hive-site.xml
文件
[atguigu@hadoop102 software]$ vim $HIVE_HOME/conf/hive-site.xml
添加如下内容
2
)登陆
MySQL
[atguigu@hadoop102 software]$ mysql -uroot -p000000
3
)新建
Hive
元数据库
mysql> create database metastore;
mysql> quit;
4
) 初始化
Hive
元数据库
[atguigu@hadoop102 software]$ schematool -initSchema -dbType mysql -
verbose
2.4.3
再次启动
Hive
1
)启动
Hive
[atguigu@hadoop102 hive]$ bin/hive
2
)使用
Hive
hive> show databases;
hive> show tables;
hive> create table test (id int);
hive> insert into test values(1);
hive> select * from test;
3
)在
CRT
窗口中开启另一个窗口开启
Hive
hive> show databases;
hive> show tables;
hive> select * from aa;
2.5
使用元数据服务的方式访问
Hive
1
)在
hive-site.xml
文件中添加如下配置信息
hive.metastore.uris
thrift://hadoop102:9083
2
)启动
metastore
[atguigu@hadoop202 hive]$ hive --service metastore
2020-04-24 16:58:08: Starting Hive metastore Server
注意
:
启动后窗口不能再操作,需打开一个新的
shell
窗口做别的操作
3
)启动
hive
[atguigu@hadoop202 hive]$ bin/hive