Mac单机安装Apache Hive

本文记录一下 Mac 本机安装 Hive 的过程,免得每次都要去搜索一堆博客才能安装成功。

环境

Mac:10.15.7
Hadoop:2.7.4
JDK:1.8.0_151
Hive:2.2.0

下载并解压

从官网下载解压到某个目录下,并在 /etc/profile 设置环境变量:

1
2
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin:$HIVE_HOME/conf

使环境变量生效:

1
source /etc/profile

查看是否安装成功:

1
hive

修改 Hive 配置

修改 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
<!-- 数据库的用户名 -->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>

<!-- 数据库密码 -->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>

<!-- 数据库连接 url -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive_metadata?createDatabaseIfNotExsit=true&amp;characterEncoding=UTF-8&amp;verifyServerCertificate=false&amp;useSSL=false</value>
</property>

<!-- 数据库连接驱动 -->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>

<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>

<property>
<name>hive.exec.scratchdir</name>
<value>/tmp/hive</value>
</property>

<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>

修改 hive-env.sh 文件

1
2
3
export HADOOP_HOME=/usr/local/hadoop
export HIVE_CONF_DIR=/usr/local/hive/conf
export HIVE_AUX_JARS_PATH=/usr/local/hive/lib

初始化 Hive metastore 数据库表

  1. 复制 mysql 驱动包到 hive lib 目录

    1
    cp mysql-connector-java-5.1.43.jar  $HIVE_HOME/lib
  2. 创建 hive_metadata 数据库

    1
    mysql -uroot -p123456
1
create database hive_metadata;
  1. 初始化创建 Hive metastore 数据库表
    1
    $HIVE_HOME/bin/schematool -dbType mysql -initSchema
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
64
65
66
67
68
69
mysql> 
mysql> use hive_metadata;
Database changed
mysql>
mysql> show tables;
+---------------------------+
| Tables_in_hive_metadata |
+---------------------------+
| AUX_TABLE |
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_COMPACTIONS |
| COMPLETED_TXN_COMPONENTS |
| DATABASE_PARAMS |
| DBS |
| DB_PRIVS |
| DELEGATION_TOKENS |
| FUNCS |
| FUNC_RU |
| GLOBAL_PRIVS |
| HIVE_LOCKS |
| IDXS |
| INDEX_PARAMS |
| KEY_CONSTRAINTS |
| MASTER_KEYS |
| NEXT_COMPACTION_QUEUE_ID |
| NEXT_LOCK_ID |
| NEXT_TXN_ID |
| NOTIFICATION_LOG |
| NOTIFICATION_SEQUENCE |
| NUCLEUS_TABLES |
| PARTITIONS |
| PARTITION_EVENTS |
| PARTITION_KEYS |
| PARTITION_KEY_VALS |
| PARTITION_PARAMS |
| PART_COL_PRIVS |
| PART_COL_STATS |
| PART_PRIVS |
| ROLES |
| ROLE_MAP |
| SDS |
| SD_PARAMS |
| SEQUENCE_TABLE |
| SERDES |
| SERDE_PARAMS |
| SKEWED_COL_NAMES |
| SKEWED_COL_VALUE_LOC_MAP |
| SKEWED_STRING_LIST |
| SKEWED_STRING_LIST_VALUES |
| SKEWED_VALUES |
| SORT_COLS |
| TABLE_PARAMS |
| TAB_COL_STATS |
| TBLS |
| TBL_COL_PRIVS |
| TBL_PRIVS |
| TXNS |
| TXN_COMPONENTS |
| TYPES |
| TYPE_FIELDS |
| VERSION |
| WRITE_SET |
+---------------------------+
57 rows in set (0.00 sec)

mysql>

运行 Hive

启动命令

启动 metastore 服务:

1
$HIVE_HOME/bin/hive --service metastore &

启动 HiveServer2 :

1
$HIVE_HOME/bin/hive --service metastore &

查看相关进程

显示为两个 RunJar 进程:

1
2
3
4
5
jps

4929 org.apache.hadoop.util.RunJar /usr/local/hive/lib/hive-service-2.2.0.jar org.apache.hive.service.server.HiveServer2 --hiveconf hive.aux.jars.path=file:///usr/local/hive/lib/HikariCP-2.5.1.jar,file:///usr/local/hive/lib/RoaringBitmap-0.5.18.jar,file:///usr/local/hive/lib/ST4-4.0.4.jar,file:///usr/local/hive/lib/accumulo-core-1.6.0.jar,file:///usr/local/hive/lib/accumulo-fate-1.6.0.jar,file:///usr/local/hive/lib/accumulo-start-1.6.0.jar,file:///usr/local/hive/lib/accumulo-trace-1.6.0.jar,file:///usr/local/hive/lib/activation-1.1.jar,file:///usr/local/hive/lib/aether-api-0.9.0.M2.jar,file:///usr/local/hive/lib/aether-connector-file-0.9.0.M2.jar,file:///usr/local/hive/lib/aether-connector-okhttp-0.0.9.jar,file:///usr/local/hive/lib/aether-impl-0.9.0.M2.jar,file:///usr/local/hive/lib/aether-spi-0.9.0.M2.jar,file:///usr/local/hive/lib/aether-util-0.9.0.M2.jar,file:///usr/local/hive/lib/airline-0.7.jar,file:///usr/local/hive/lib/ant-1.6.5.jar,file:///usr/local/hive/lib/ant-1.9.1.jar,file:///usr/local/hive/lib/ant-la

4870 org.apache.hadoop.util.RunJar /usr/local/hive/lib/hive-metastore-2.2.0.jar org.apache.hadoop.hive.metastore.HiveMetaStore