文章目录
1、下载和解压
我使用的版本是 :apache-hive-2.3.6-bin.tar.gz
使用 tar -zxvf
命令进行解压。
2、配置环境变量
在 /etc/profile
文件中追加:
#hive environment
export HIVE_HOME=/usr/hive/apache-hive-2.3.6-bin
export PATH=$PATH:$HIVE_HOME/bin
保存修改之后,使用 source /etc/profile
命令,使得配置信息生效。
3、修改hive-default.xml 文件
只改名:
[root@centos2020 apache-hive-2.3.6-bin]# cd conf/
[root@centos2020 conf]# mv hive-default.xml.template hive-default.xml
4、新建一个 hive-site.xml
[root@centos2020 conf]# vim hive-site.xml
增加内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://centos2020:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<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.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>
5、将mysql 驱动放在 lib 目录下
这里使用mysql 存储元数据。
驱动名为:
mysql-connector-java-5.1.48.jar
存放的位置是:
/usr/hive/apache-hive-2.3.6-bin/lib
6、进入mysql
创建 hive 数据库,用于存储hive的元数据信息。
[root@centos2020 lib]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database hive;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on *.* to root@localhost identified by 'root';
Query OK, 0 rows affected, 2 warnings (0.05 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
mysql> exit;
Bye
7、启动 hive
在安装目录:
[root@centos2020 apache-hive-2.3.6-bin]# bin/hive
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_161/bin:/usr/mysql/mysql5.7.26/bin:/usr/hadoop/hadoop-2.7.7/bin:/root/bin:/usr/java/jdk1.8.0_161/bin:/usr/mysql/mysql5.7.26/bin:/usr/hadoop/hadoop-2.7.7/bin:/usr/sqoop/sqoop-1.4.7.bin__hadoop-2.6.0/bin:/usr/java/jdk1.8.0_161/bin:/usr/mysql/mysql5.7.26/bin:/usr/hadoop/hadoop-2.7.7/bin:/usr/sqoop/sqoop-1.4.7.bin__hadoop-2.6.0/bin:/usr/hive/apache-hive-2.3.6-bin/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/hive/apache-hive-2.3.6-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hadoop/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
Logging initialized using configuration in jar:file:/usr/hive/apache-hive-2.3.6-bin/lib/hive-common-2.3.6.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive>
8、使用命令测试
hive> show databases;
Tue Feb 25 06:57:20 EST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决方案:
在hive-site.xml 中修改:增加了useSSL=false
<value>jdbc:mysql://centos2020:3306/hive?createDatabaseIfNotExist=true&useSSL=false</value>
再次测试:
hive> show databases;
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
解决方案:初始化一下
[root@centos2020 apache-hive-2.3.6-bin]# cd bin
[root@centos2020 bin]# ls
beeline ext hive hive-config.sh hiveserver2 hplsql metatool schematool
[root@centos2020 bin]# schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/hive/apache-hive-2.3.6-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hadoop/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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://centos2020:3306/hive?createDatabaseIfNotExist=true&useSSL=false
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed
再次测试:
hive> show databases;
OK
default
Time taken: 7.593 seconds, Fetched: 1 row(s)
成功了!!