Hive(四) Metastore详解

  1. 相关概念
    Hive Metastore有三种配置方式,分别是:

Embedded Metastore Database (Derby) 内嵌模式
Local Metastore Server 本地元存储
Remote Metastore Server 远程元存储
1.1 Metadata、Metastore作用
metadata即元数据。元数据包含用Hive创建的database、tabel等的元信息。
元数据存储在关系型数据库中。如Derby、MySQL等。

Metastore的作用是:客户端连接metastore服务,metastore再去连接MySQL数据库来存取元数据。有了metastore服务,就可以有多个客户端同时连接,而且这些客户端不需要知道MySQL数据库的用户名和密码,只需要连接metastore 服务即可。

1.2三种配置方式区别
内嵌模式使用的是内嵌的Derby数据库来存储元数据,也不需要额外起Metastore服务。这个是默认的,配置简单,但是一次只能一个客户端连接,适用于用来实验,不适用于生产环境。

本地元存储和远程元存储都采用外部数据库来存储元数据,目前支持的数据库有:MySQL、Postgres、Oracle、MS SQL Server.在这里我们使用MySQL。

本地元存储和远程元存储的区别是:本地元存储不需要单独起metastore服务,用的是跟hive在同一个进程里的metastore服务。远程元存储需要单独起metastore服务,然后每个客户端都在配置文件里配置连接到该metastore服务。远程元存储的metastore服务和hive运行在不同的进程里。

在生产环境中,建议用远程元存储来配置Hive Metastore。

  1. 集群规划
    本教程Hadoop相关软件全部基于CDH5.5.1,用yum安装,系统环境如下:

操作系统:CentOS 7.2
Hadoop 2.6.0
Hive1.1.0
Spark1.5.0
MySQL 5.6
JDK 1.8
Maven 3.3.3
Scala 2.10
各节点规划如下:

192.168.117.51 Goblin01 nn1 jn1 rm1 worker master hive metastore mysql
192.168.117.52 Goblin02 zk2 nn2 jn2 rm2 worker hive metastore
192.168.117.53 Goblin03 zk3 dn1 jn3 worker hive
192.168.117.54 Goblin04 zk4 dn2 worker hive
说明:Goblin01~04是每台机器的hostname,zk代表zookeeper,nn代表hadoop的namenode,dn代表datanode,jn代表journalnode,rm代表resourcemanager,worker代表Spark的slaves,master代表Spark的master

如果不需要Hive on Spark,只需要Hive on MR,则不需要安装Spark、Maven和Scala。

我们把metastore服务和MySQL都装在51上(装在哪一台都可以),51-54都安装Hive,这样多个客户端可以同时执行Hive命令。

在执行以下步骤之前,请确保已经安装了Hadoop集群

  1. 安装MySQL
    下载mysql的repo源

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
安装mysql-community-release-el7-5.noarch.rpm包

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

安装mysql

$ sudo yum install mysql-server
4. 配置MySQL和metastore
Step 1: Install and start MySQL if you have not
already done so

$ sudo yum install mysql-server
$ sudo service mysqld start
Step 2: Configure the MySQL Service and Connector

因为使用MySQL作为存储元数据的数据库,所以需要把连接MySQL的jar包放入或链接到$HIVE_HOME/lib目录下。

$ sudo yum install mysql-connector-java
$ ln -s /usr/share/java/mysql-connector-java.jar /usr/lib/hive/lib/mysql-connector-java.jar
To set the MySQL root password:

$ sudo /usr/bin/mysql_secure_installation
[…]
Enter current password for root (enter for none):
OK, successfully used password, moving on…
[…]
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[…]
Disallow root login remotely? [Y/n] N
[…]
Remove test database and access to it [Y/n] Y
[…]
Reload privilege tables now? [Y/n] Y
All done!
To make sure the MySQL server starts at boot:

$ sudo /sbin/chkconfig mysqld on
$ sudo /sbin/chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Step 3. Create the Database and User

$ mysql -u root -p
Enter password:
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-0.12.0.mysql.sql;

mysql> CREATE USER ‘hive’@‘metastorehost’ IDENTIFIED BY ‘mypassword’;

mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM ‘hive’@‘metastorehost’;
mysql> GRANT ALL ON metastore.* TO ‘hive’@‘metastorehost’ IDENTIFIED BY ‘hive’;
mysql> GRANT ALL ON metastore.* TO ‘hive’@’%’ IDENTIFIED BY ‘hive’;
mysql> FLUSH PRIVILEGES;
mysql> ALTER DATABASE metastore CHARACTER SET latin1;
mysql> quit;
Step 4. Format the Database

$ cd /usr/lib/hive/bin
$ ./schematool --dbType mysql --initSchema
5. Hive配置
5.1 HDFS存储位置配置
Hive配置文件里要用到HDFS的一些路径,需要先手动创建。

hdfs dfs -mkdir -p /usr/hive/warehouse
hdfs dfs -mkdir -p /usr/hive/tmp
hdfs dfs -mkdir -p /usr/hive/log
hdfs dfs -chmod g+w /usr/hive/warehouse
hdfs dfs -chmod g+w /usr/hive/tmp
hdfs dfs -chmod g+w /usr/hive/log
上述语句涉及hive-site.xml hive.metastore.warehouse.dir等,表示数据在hdfs中的存储位置

5.2 hive-env.sh (所有节点)

export HADOOP_HOME=/usr/lib/hadoop
export HIVE_CONF_DIR=/usr/lib/hive/conf
5.3 hive-log4j.properties(所有节点)
首先创建log存放的文件夹

mkdir /usr/lib/hive/logs
然后配置hive-log4j.properties

hive.log.dir=/usr/lib/hive/logs
5.4 服务端hive-site.xml
服务端指的是Metastore服务所在的机器,即安装metastore的机器,这里是51和52。

javax.jdo.option.ConnectionURL jdbc:mysql://Goblin01:3306/metastore?createDatabaseIfNotExist=true the URL of the MySQL database javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver Driver class name for a JDBC metastore javax.jdo.option.ConnectionUserName hive javax.jdo.option.ConnectionPassword hive hive.metastore.warehouse.dir /usr/hive/warehouse hive.exec.scratchdir /usr/hive/tmp hive.querylog.location /usr/hive/log 5.5 客户端hive-site.xml 这里指的是53和54。 hive.metastore.uris thrift://Goblin01:9083,Goblin02:9083 IP address (or fully-qualified domain name) and port of the metastore host hive.metastore.warehouse.dir /usr/hive/warehouse hive.exec.scratchdir /usr/hive/tmp hive.querylog.location /usr/hive/log 6. 启动Hive 启动MySQL

$ service mysqld start
启动metastore服务

$ service hive-metastore start
启动Hive CLI
因为在4台机器上都安装了hive,并且作了相关的配置,所有四台机器均可以启动Hive CLI(Hive交互式shell)

$ hive

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值