hadoop 3.3大数据集群搭建系列3-安装Hive

一. 下载hive

cd /home/software
wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz --no-check-certificate

二. 解压

将下载下来的安装包解压到/home目录

tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /home

三. 添加Hive核心配置,选择远程MySQL模式

cd /home/apache-hive-3.1.2-bin/conf/
vim hive-site.xml

添加如下内容:





    
    
        javax.jdo.option.ConnectionURL
        jdbc:mysql://hp8:3306/hivedb?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false
        JDBC connect String for a JDBC metastore
    

    
    
        javax.jdo.option.ConnectionDriverName
        com.mysql.cj.jdbc.Driver
        Driver class name for a JDBC metastore
    

    
    
        javax.jdo.option.ConnectionUserName
        root
        username to use against metastore database
    

    
    
        javax.jdo.option.ConnectionPassword
        abc123
        password to use against metastore database
    

四. 下载连接MySQL的驱动包到hive的lib目录下

我连接的远程mysql是 5.7版本的,所以此处选在的是mysql-connector-java-5.1.9.jar,而非8版本的。

cd /home/apache-hive-3.1.2-bin/lib
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/6.0.6/mysql-connector-java-6.0.6.jar

五. MySQL下创建hive数据库

登陆远程数据库,创建hivedb;

create database hivedb;

六. 执行Hive的初始化工作

初始化Hive

cd /home/apache-hive-3.1.2-bin/bin
./schematool -initSchema -dbType mysql

七. 验证初始化是否成功

初始化完成后,在MySQL的hivedb数据库中查看是否初始化成功:


image.png

八. 使用hive

启动hive:

# 启动hive
cd /home/apache-hive-3.1.2-bin/bin
./hive

报错:

Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
image.png

网上找了下,需要使用JDK 8版本,而我使用的是openjdk 11

cd /home/hadoop-3.3.2/etc/hadoop/
vi hadoop-env.sh
export JAVA_HOME=/usr/java/jdk1.8.0_181

将hadoop的配置文件下的hadoop-env.sh 修改为 JDK8版本的,而全局的/etc/profile里面依旧使用OpenJDK11,测试无问题。

image.png

配置hive环境变量:

vi /etc/profile
export HIVE_HOME=/home/apache-hive-3.1.2-bin

source /etc/profile

参考:

  1. https://blog.csdn.net/tyh1579152915/article/details/109405407
  2. https://blog.csdn.net/u011109589/article/details/124870879
  3. https://blog.csdn.net/keyboard_/article/details/114054013
  4. https://stackoverflow.com/questions/54037773/hive-exception-class-jdk-internal-loader-classloadersappclassloader-cannot

你可能感兴趣的:(hadoop 3.3大数据集群搭建系列3-安装Hive)