公司建立数仓, hive 是必不可少的, hive 是建立在 hadoop 基础上的数据库, 前面已经搭建起了 hadoop 高可用, 要学习 hive, 先从搭建开始, 下面梳理一下 hive 搭建过程
1. 下载 hive 安装包 , 下载地址: https://hive.apache.org/downloads.html
找到自己 hadoop 对应的版本下载安装, 我这里下载的是 apache-hive-2.3.6-bin.tar.gz
2. 安装 hive, 将安装包解压到 / opt/soft 下, 并建立软链接
- tar -zxvf apache-hive-2.3.6-bin.tar.gz -C /opt/soft/
- cd /opt/soft
- mv apache-hive-2.3.6-bin hive-2.3.6
- ln -s hive-2.3.6 hive
3. 配置环境变量 / etc/profile
- VIM /etc/profile
- #hive
- export HIVE_HOME=/opt/soft/hive
- export PATH=$PATH:$HIVE_HOME/bin
保存后别忘记编译一下
source /etc/profile
4. 配置 hive 配置文件, hive 元数据默认存储到 derby 数据库中, 我们这里使用 MySQL 来存储, hive-site.xml 配置信息较多建议下载到 Windows 下修改, 然后再传上去
首先复制默认的配置文件模板, 里面已经包含 hive 所有的默认配置信息
cp hive-default.xml.template hive-site.xml
修改 hive-site.xml 配置文件, 将元数据存放数据库改为 MySQL, 在 hive-site.xml 中找到下列属性, 修改为:
- <property>
- <name>javax.jdo.option.ConnectionDriverName</name>
- <value>com.MySQL.jdbc.Driver</value>
- <description>Driver class name for a JDBC metastore</description>
- </property>
- <property>
- <name>javax.jdo.option.ConnectionURL</name>
- <value>jdbc:MySQL://192.168.118.1:3306/hive2</value>
- <description>
- JDBC connect string for a JDBC metastore.
- To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
- For example, jdbc:PostgreSQL://myhost/db?ssl=true for postgres database.
- </description>
- </property>
- <property>
- <name>javax.jdo.option.ConnectionUserName</name>
- <value>root</value>
- <description>Username to use against metastore database</description>
- </property>
- <property>
- <name>javax.jdo.option.ConnectionPassword</name>
- <value>111111</value>
- <description>password to use against metastore database</description>
- </property>
数据库驱动为 MySQL 驱动 com.MySQL.jdbc.Driver,URL 改为 MySQL 的 hive2(自定义)数据库, 用户名密码为自己数据库对应的用户名密码
修改 hive 配置的一些目录, 指定到自己选择的目录, 搜索以 ${system 开头的 value 替换为自己的目录, 我这里替换为:/home/hdfs/hive 下相关目录
- <property>
- <name>hive.exec.local.scratchdir</name>
- <value>/home/hdfs/hive</value>
- <description>Local scratch space for Hive jobs</description>
- </property>
- <property>
- <name>hive.downloaded.resources.dir</name>
- <value>/home/hdfs/hive/downloads</value>
- <description>Temporary local directory for added resources in the remote file system.</description>
- </property>
- <property>
- <name>hive.querylog.location</name>
- <value>/home/hdfs/hive/querylog</value>
- <description>Location of Hive run time structured log file</description>
- </property>
- <property>
- <name>hive.server2.logging.operation.log.location</name>
- <value>/home/hdfs/hive/server2_logs</value>
- <description>Top level directory where operation logs are stored if logging functionality is enabled</description>
- </property>
修改权限验证为 false
- <property>
- <name>hive.server2.enable.doAs</name>
- <value>false</value>
- <description>
- Setting this property to true will have HiveServer2 execute
- Hive operations as the user making the calls to it.
- </description>
- </property>
5. 既然修改元数据存放在 MySQL 库里, 就需要将 MySQL 驱动包放入到 hive/lib 中, 注意 MySQL 版本和驱动包一致
mv MySQL-connector-java-8.0.18.jar /opt/soft/hive/lib/
6. 在 MySQL 数据库中创建 hive2 库
7. 初始化 hive 的元数据 (表结构) 到 MySQL 中.
- cd /opt/soft/hive/bin
- schematool -dbType MySQL -initSchema
出现如下信息, 代表成功
也可以查看 MySQL 中 hive2 库, 所有表初始化完成
8. 启动 hadoop, 如果没有安装可以参考: centos7 搭建 hadoop2.10 高可用(HA)
start-all.sh
9. 启动 hive
hive
查看目前只有 default 数据库
创建数据库:
create database myhivedb2;
查看创建的 mysqhivedb2 已经出来了
我们查一下 hdfs 中是否创建了对应的目录
hdfs dfs -ls -R /user/hive/
也可以查看 MySQL 中 hive2 库的 dbs 表:
至此 hive 环境搭建完成
来源: https://www.cnblogs.com/qixing/p/12275185.html