Hive中metastore(元数据存储)的三种方式

  • 内嵌Derby方式
  • Local方式
  • Remote方式

[一]、内嵌Derby方式

这个是Hive默认的启动模式,一般用于单元测试,这种存储方式有一个缺点:在同一时间只能有一个进程连接使用数据库。

hive-site.xml 中jdbc URL、驱动、用户名、密码等的配置信息如下:

 
 
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
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<!-- micmiu.com -->

执行初始化命令:schematool -dbType derby -initSchema

查看初始化后的信息: schematool -dbType derby -info

配置完成后就可在shell中以CLI的方式访问hive 进行操作验证。

[二]、Local方式

以本地Mysql数据库为例:创建好用户:hive;database:hive。

配置文件 hive-site.xml 中jdbc URL、驱动、用户名、密码等属性值配置如下:

 
 
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
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
<!-- base hdfs path -->
</value>
</description>
</property>
<!-- micmiu.com -->

ps:需要把mysql的驱动包copy到目录 <HIVE_HOME>/lib 中

如果是第一次需要执行初始化命令:schematool -dbType mysql -initSchema

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
initSchema
recursive
maxsize
minsize
rack
node
reduces
speculative
//localhost/hive?createDatabaseIfNotExist=true
Driver
hive
0.12.0
0.12.0.mysql.sql
completed
completeted

查看初始化后信息 schematool -dbType mysql -info

初始化后查看mysql中表情况:show tables;

 
 
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
;
+
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
)

配置完成后就可在shell中以CLI的方式访问hive 进行操作验证。

[三]、Remote方式

以Mysql数据库(192.168.6.77)为例:创建好用户:hive;database:hive_meta。Remote方式需要分别配置服务端和客户端的配置文件:

服务端的 hive-site.xml 中jdbc URL、驱动、用户名、密码等属性值配置如下:

 
 
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
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
</value>
</description>
</property>
 
<property>
</name>
<!-- base hdfs path -->
</value>
</description>
</property>
<!-- micmiu.com -->

ps:需要把mysql的驱动包copy到目录 <HIVE_HOME>/lib 中

如果是第一次需要执行初始化命令:schematool -dbType mysql -initSchema

客户端中配置内容修改如下:

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- thrift://<host_name>:<port> 默认端口是9083 -->
<property>
</name>
</value>
</description>
</property>
 
<!--  hive表的默认存储路径 -->
<property>
</name>
</value>
</description>
</property>

hive metastore 服务端启动命令:
hive --service metastore -p <port_num>
如果不加端口默认启动:hive --service metastore,则默认监听端口是:9083 ,注意客户端中的端口配置需要和启动监听的端口一致。服务端启动正常后,客户端就可以执行hive操作了。

参考:

https://cwiki.apache.org/confluence/display/Hive/AdminManual+MetastoreAdmin

相关文章: