Hive的安装
前提:
安装hive所需要的虚拟机环境为虚拟机安装有Hadoop并且集群成功,同时Hadoop需要在启动状态下,同时需要安装有mysql。不需要有zookeeper和HA,由于HA中含有大量进程,启动会占用很多资源,建议不要有HA
安装步骤:
上传
将hive-3.1.2上传到虚拟机中的/usr/local/soft目录下
解压hive-3.1.2
输入命令:
tar -zxvf apache-hive-3.1.2-bin.tar.gz
解压文件:
重命名:
mv apache-hive-3.1.2-bin hive-3.1.2
配置环境变量
vim /etc/profile 进入到环境变量中:添加以下内容:
保存退出,输入source /etc/profile使环境变量生效
配置HIVE文件
配置hive-env.sh
cd $HIVE_HOME/conf 进入到conf目录中
复制创建hive.env.sh
cp hive-env.sh.template hive-env.sh
输入命令:
vim hive-env.sh 进入到hive-env.sh中增加如下内容:
配置hive-site.xml
上传hive-site.xml到conf目录:
hive-site.xml文件内容:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<!-- 查询数据时 显示出列的名字 -->
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<!-- 在命令行中显示当前所使用的数据库 -->
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<property>
<!-- 默认数据仓库存储的位置,该位置为HDFS上的路径 -->
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<!-- 8.x -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=GMT</value>
</property>
<!-- 8.x -->
<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>123456</value>
</property>
<!-- hiveserver2服务的端口号以及绑定的主机名 -->
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>master</value>
</property>
</configuration>
配置日志
创建日志目录:
在hive根目录hive-3.1.2下创建log日志目录:
mkdir log
设置日志配置
复制创建hive-log4j2.properties,输入命令:
cd conf
cp hive-log4j2.properties.template hive-log4j2.properties
进入到hive-log4j2.properties中:
vim hive-log4j2.properties
修改以下内容:
property.hive.log.dir = /usr/local/soft/hive-3.1.2/log
修改默认配置文件
复制创建hive-default.xml:
cp hive-default.xml.template hive-default.xml
上传MySQL连接jar包
上传 mysql-connector-java-5.1.37.jar 至 /usr/local/app/hive/lib目录中
修改MySQL编码
1、修改mysql编码为UTF-8
1.1 编辑配置文件
vim /etc/my.cnf
1.2 加入以下内容:
1.3 重启mysql
systemctl restart mysqld
初始化HIVE
输入命令:
schematool -dbType mysql -initSchema
结果:成功截图
进入Hive
输入命令:hive
后续配置
修改mysql元数据库hive,让其hive支持utf-8编码以支持中文
登录mysql:
mysql -u root -p123456
切换到hive数据库:
use hive;
1).修改字段注释字符集
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
2).修改表注释字符集
alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
3).修改分区表参数,以支持分区键能够用中文表示
alter table PARTITION_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
alter table PARTITION_KEYS modify column PKEY_COMMENT varchar(4000) character set utf8;
4).修改索引注解(可选)
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
5).修改库注释字符集
alter table DBS modify column DESC varchar(4000) character set utf8;
测试hive
1、启动hive
2、在hive中创建test1数据库
create database test1;
3、切换test1数据库:
use test1;
4、创建students表:
create table students(
id bigint comment '学生id',
name string comment '学生姓名',
age int comment '学生年龄',
gender string comment '学生性别',
clazz string comment '学生班级'
) comment '学生信息表'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
5、创建score表:
create table score(
id bigint comment '学生id',
score_id bigint comment '科目id',
score int comment '学生成绩'
) comment '学生成绩表'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
6、查看表信息:
desc students;
desc score;
配置JDBC连接
Hadoop 中的core-site.xml添加如下:
<property> <name>hadoop.proxyuser.root.hosts</name> <value>*</value> </property> <property> <name>hadoop.proxyuser.root.groups</name> <value>*</value> </property>
启动hiveserver2
hive --service hiveserver2