目录

实验环境:

实验步骤(均在root模式下进行):

一、解压

二、配置环境变量

三、修改配置文件

1.修改/usr/local/hive/conf下的hive-site.xml

2.配置hive-env.sh

3.配置hive-config.sh,位于bin目录:

4.查看版本:

 四、配置mysql和jdbc

1.安装MySQL:

2.配置jdbc驱动:

3.启动并登陆mysql shell

4.新建hive数据库

5.配置mysql允许root接入:

6.初始化元数据库hive

7.启动hive

实验环境:

操作系统:Ubuntu 18.04

Hadoop版本:3.1.3

Hive版本:3.1.2

JDK版本:1.8

Mysql版本:5.7.4

实验步骤(均在root模式下进行):

一、解压

tar -zxvf ./apache-hive-3.1.2-bin.tar.gz -C /usr/local

二、配置环境变量

vim /etc/profile

 添加:

export HIVE_HOME=/usr/local/hive

export PATH=$PATH: $HIVE_HOME/bin

刷新环境变量 

source /etc/profie

三、修改配置文件

1.修改/usr/local/hive/conf下的hive-site.xml

cd /usr/local/hive/conf

将hive-default.xml.template重命名为hive-default.xml;

mv hive-default.xml.tenplate hive-default.xml

使用vim编辑器新建一个配置文件hive-site.xml, 

vim hive-site.xml

在hive-site.xml中添加如下配置信息(注意下方有个密码,用于连接元数据库,与连接mysql密码相同):

 

    javax.jdo.option.ConnectionURL

    jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true

    JDBC connect string for a JDBC metastore

 

 

    javax.jdo.option.ConnectionDriverName

    com.mysql.jdbc.Driver

    Driver class name for a JDBC metastore

 

 

    javax.jdo.option.ConnectionUserName

    root

    username to use against metastore database

 

 

    javax.jdo.option.ConnectionPassword

    这里输入你的密码

    password to use against metastore database

 

    datanucleus.schema.autoCreateAll

    true

    Auto creates necessary schema on a startup if one doesn't exist. Set this to false, after creating it once.To enable auto create also set hive.metastore.schema.verification=false. Auto creation is not recommended for production use cases, run schematool command instead.

 

    hive.metastore.schema.verification

    false

   

      Enforce metastore schema version consistency.

      True: Verify that version information stored in is compatible with one from Hive jars.  Also disable automatic

            schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures

            proper metastore schema migration. (Default)

      False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.

   

 

2.配置hive-env.sh

cp hive-env.sh.template hive-env.sh

vim hive-env.sh

插入java和hadoop环境变量

export JAVA_HOME=/usr/local/jdk

export HADOOP_HOME=/usr/local/Hadoop

3.配置hive-config.sh,位于bin目录:

cd /usr/local/hive/bin

添加:

export JAVA HOME=/usr/local/jdk

export HADOOP_HOME=/usr/local/hadoop

export HIVE_HOME=/usr/local/hive

4.查看版本:

hive --version

 四、配置mysql和jdbc

1.安装MySQL:

#更新软件源

apt-get update

#安装mysql

apt-get install mysql-server

 为mysql设置密码,与hive-site.xml配置文件的一样: 

update user set authentication_string=PASSWORD('输入你的密码') where user='root';

启动mysql服务器:

service mysql start

确认是否启动成功,mysql节点处于LISTEN状态表示启动成功:

netstat -tap | grep mysql

进入mysql shell界面:

mysql -u root -p

关闭服务:

service mysql stop

2.配置jdbc驱动:

tar -zxvf mysql-connector-java-5.1.40.tar.gz

将mysql驱动文件复制到hive目录下的lib目录中

3.启动并登陆mysql shell

#启动mysql服务

service mysql start

 #登陆shell界面

mysql -u root -p

4.新建hive数据库

#这个hive数据库与hive-site.xml中localhost:3306/hive的hive对应,用来保存hive元数据

create database hive;

5.配置mysql允许root接入:

#将所有数据库的所有表的所有权限赋给hive用户,后面的hive是配置hive-site.xml中配置的连接密码

grant all on *.* to root@localhost identified by '跟你上方一样的密码';

 #刷新mysql系统权限关系表

flush privileges;

6.初始化元数据库hive

cd /usr/local/hive

./bin/schematool -dbType mysql -initSchema

7.启动hive

启动hive之前,先启动hadoop集群。

#启动Hadoop的HDFS

start-dfs.sh

 #启动hive

hive

注意,我们这里已经配置了PATH,所以,不需要把start-all.sh和hive命令的路径加上。如果没有配置PATH,请加上路径才能运行命令,比如,本教程Hadoop安装目录是“/usr/local/hadoop”,Hive的安装目录是“/usr/local/hive”,因此,启动hadoop和hive,也可以使用下面带路径的方式:

cd /usr/local/hadoop

./sbin/start-dfs.sh

cd /usr/local/hive

./bin/hive

好文推荐

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: