hive的安装
准备条件
安装好hdfs集群
安装MySQL数据库,并且在MySQL中创建"hive"数据库(数据库名必须为"hive",默认情况下hive会将元数据存储在"hive"数据库中)
安装hive
[[email protected] usr]# mkdir hive
[[email protected] hive]# apache-hive-2.3.3-bin.tar
[[email protected] hive]# tar -zxvf apache-hive-2.3.3-bin.tar
配置环境变量
[[email protected] hive]# vi /etc/profile
[[email protected] hive]# source /etc/profile
配置hive-site.xml
[[email protected] hive]# cd /usr/hive/apache-hive-2.3.3-bin/conf/
[[email protected] conf]# touch hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--指定连接路径-->
<property>
</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>root</value>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<!--显示当前hive使用的数据库-->
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<!--显示表的字段名-->
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<!--指定hive2的端口号,不添加如下内容,无法使用java代码操作hive2-->
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
<!--指定hive操作的机器的ip(即安装hive的虚拟机)-->
<property>
<name>hive.server2.thrift.bind.host</name>
<value>192.168.215.154</value>
</property>
</configuration>
添加MySQL驱动架包
将mysql的驱动架包放入"/usr/hive/apache-hive-2.3.3-bin/lib"
注:如果没有MySQL驱动架包,hive初始化时会出现如下错误
在MySQL中创建名为"hive"的数据库
create database hive
如果没有创建"hive"数据库,会出现如下错误
hive初始化
[[email protected] hive]# cd /usr/hive/apache-hive-2.3.3-bin/bin
[[email protected] bin]# schematool -initSchema -dbType mysql
进入hive
[[email protected] bin]# hive
退出hive
hive (default)> exit;
hive (default)> quit;
使用java代码操作hive(可以使用java操作hive2)
打开"core-site.xml"文件,追加如下内容
[[email protected] usr]# cd /usr/hadoop/hadoop-2.7.3/etc/hadoop/
[[email protected] hadoop]# vi core-site.xml
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.zhaoshb.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.zhaoshb.groups</name>
<value>*</value>
</property>
在关闭所有进程,重新启动。
开启hive服务
[[email protected] hive]# hiveserver2
注:此命令会占用当前窗口,重新复制一个窗口,只能强制退出
开启hive服务客户端
[[email protected] ~]# beeline
beeline> !connect jdbc:hive2://localhost:10000(会让你输入一个身份(启动HDFS的那个用户,也随便写个不存在的用户,但是该用户不能创建新表)
Enter username for jdbc:hive2://localhost:10000:(root)
Enter password for jdbc:hive2://localhost:10000:(提示你确定密码,可以不写)
注:“localhost”为开启hive服务的机器的映射,此处只能写映射,不能写ip,“10000”就是“hive-site.xml”文件中的hive2的端口
退出hive服务客户端
0: jdbc:hive2://localhost:10000> !quit;