MYSQL安装

详细看mysql安装的章节

添加hive用户

1
2
3
4
5
CREATE DATABASE hive;
CREATE USER 'hiveuser'@'localhost' IDENTIFIED BY 'hivepassword';
GRANT ALL PRIVILEGES ON hive.* TO 'hiveuser'@'localhost';
FLUSH PRIVILEGES;

Hive安装

安装包下载

1
wget --user-agent="Mozilla" https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-4.0.1/apache-hive-4.0.1-bin.tar.gz

解压

1
tar -xzvf apache-hive-4.0.1-bin.tar.gz

到hive的conf文件夹下面

1
vim hive-site.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- jdbc连接的URL -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?useSSL=false</value>
</property>

<!-- jdbc连接的Driver-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>

<!-- jdbc连接的username-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>

<!-- jdbc连接的password -->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>

<!-- Hive默认在HDFS的工作目录 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>

<!-- Hive元数据存储的验证 -->
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>

<!-- 元数据存储授权 -->
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>
<!-- 指定存储元数据要连接的地址 -->
<property>
<name>hive.metastore.uris</name>
<value>thrift://localhost:9083</value>
</property>
<!-- 指定hiveserver2连接的host -->
<property>
<name>hive.server2.thrift.bind.host</name>
<value>localhost</value>
</property>

<!-- 指定hiveserver2连接的端口号 -->
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>

</configuration>

下载mysql jdbc包把它复制到hive/lib目录下

配置环境变量

1
2
3
vi /etc/profile
export HIVE_HOME=/opt/apps/hive-3.1.2
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$FLINK_HOME/bin:$HIVE_HOME/bin

配置文件生效

1
source /etc/profile

HIVE初始化元数据

1
schematool -initSchema -dbType mysql -verbos

HIVE启动

启动hive的服务: metastore

前台启动

1
hive --service metastore

后台启动

1
nohup hive --service metastore &

启动hive的服务: hiveserver2服务

前台启动

1
hive --service hiveserver2

后台启动

1
nohup hive --service hiveserver2 &

本地连接

1
hive

开防火墙

1
firewall-cmd --zone=public --add-port=9083/tcp --permanent