- 下载二进制安装文件
- 安装到指定目录
- 配置环境变量
- 配置元数据存储位置
- 初始化hive
- 命令验证
(一) 下载二进制安装文件
到Hive官网找到指定版本的文件进行下载(https://mirrors.tuna.tsinghua.edu.cn/apache/hive/)
此处下载最新发布的安装包
#> wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-3.1.1/apache-hive-3.1.1-bin.tar.gz
(二)安装到指定目录
#> tar -zxvf apache-hive-3.1.1-bin.tar.gz -C /soft
#> ln -s apache-hive-3.1.1-bin hive
(三)配置环境变量
#> vim /etc/environment
HIVE_HOME=/soft/hive
PATH=追加"/soft/hive/bin"
(四)配置元数据存储位置
原始数据默认存储在derby,改为mysql
在hive安装目录的conf中创建hive-site.xml添加如下配置
#> vim hive-site.xml
|
(五)初始化hive
#> schematool -dbType mysql -initSchema
hive初始化有可能会出现找不到连接mysql数据库jar包的错误, 如下:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:mysql://127.0.0.1:3306/database?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.cj.jdbc.Driver
Metastore connection User: root
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
Underlying cause: java.lang.ClassNotFoundException : com.mysql.cj.jdbc.Driver
Use --verbose for detailed stacktrace.
*** schemaTool failed ***
解决办法:
到mysql(https://dev.mysql.com/downloads/connector/j/)网站找到属于服务器系统的版本,下载到服务器就行安装
找到mysql-connector-java-8.0.16.jar,复制到hive的lib目录下即可
如果系统是Ubuntu server 可用 dpkg -l | grep mysql 找到对应的安装包名称,然后用dpkg -L 安装包名称 找到安装路径
(六)命令验证
#> hive -e "show tables;"
成功显示如下:
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/soft/jdk/bin:/soft/hadoop/bin:/soft/hadoop/sbin:/soft/hive/bin) SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/soft/apache-hive-3.1.1-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/soft/hadoop-3.2.0/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Hive Session ID = 5535c2a2-05d2-44f9-9b09-80ce7e95c25a
Logging initialized using configuration in jar:file:/soft/apache-hive-3.1.1-bin/lib/hive-common-3.1.1.jar!/hive-log4j2.properties Async: true |