CentOS下安装Hive2.1.0详解

CentOS下安装Hive2.1.0详解

本文所需环境如下:
操作系统:CentOS 6.5 64位
Hive版本:2.1.0
JDK版本:1.7.0_79
Hadoop版本:2.5.2

0.官网地址

hive官网地址

1.三种模式

  • 内嵌模式:元数据保持在内嵌的derby模式,只允许一个会话链接
  • 本地独立模式:在本地安装Mysql,把元数据存放到MySQL内
  • 远程模式:元数据存放在远程的MySQL数据库

2.安装过程

2.1下载、解压hive安装包
  • 我将hive等工具都安装到了/iwisdom目录下
    wget http://www-eu.apache.org/dist/hive/hive-2.1.0/apache-hive-2.1.0-bin.tar.gz
    tar -xzvf apache-hive-2.1.0-bin.tar.gz -C /iwisdom
2.2配置环境变量(可选)

将apache-hive-2.1.0-bin/bin添加到path,以方便访问

    vi /etc/profile

在文档的最后添加

    export HIVE_HOME=/iwisdom/apache-hive-2.1.0-bin
    export PATH=$PATH:$HIVE_HOME/bin

3.三种模式分别介绍

三种模式的不同之处就是体现在hive-site.xml里元数据的使用方式

3.1内嵌模式(元数据在derby数据库中)

3.1.1修改配置文件

也可以用hive-default.xml.template去改,不过这个文件中的配置项太多了

    cd /iwisdom/apache-hive-2.1.0-bin/conf
    vi hive-site.xml

输入以下内容后保存:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
    <configuration>
        <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/iwisdom/apache-hive-2.1.0-bin/warehouse</value>
        <description>location of default database for the warehouse</description>
        </property>
        <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:derby:/iwisdom/apache-hive-2.1.0-bin/metastore_db;create=true</value>
        <description>JDBC connect string for a JDBC metastore</description>
        </property>
    </configuration>
3.1.2初始化数据库

hive2.0以后的版本必须要依据hive-site.xml中配置的元数据存储方式来初始化数据库。

    schematool -initSchema -dbType derby

出现以下几行说明初始化成功:

    Starting metastore schema initialization to 2.1.0
    Initialization script hive-schema-2.1.0.derby.sql
    Initialization script completed
    schemaTool completed
3.1.3启动程序
    mkdir -p /iwisdom/apache-hive-2.1.0-bin//warehouse       // 创建元数据存储文件夹
    chmod a+rwx /iwisdom/apache-hive-2.1.0-bin//warehouse    // 修改文件权限
    hive                                                     //启动hive

如果出现hive>提示符则说明启动成功

3.1.4常见错误
运行hive时出现
    Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)

错误原因: 数据库没有初始化,请参照3.1.2

使用schematool初始化数据库时出现
    Initialization script hive-schema-2.1.0.derby.sql
    Error: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)
    org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
    *** schemaTool failed ***

错误原因:数据库文件夹中已经存在一些文件,解决方法就是清空数据库文件夹(也就是前面配置的/iwisdom/apache-hive-2.1.0-bin/metastore_db文件夹)

3.2远程模式(元数据在远程MySQL数据库)

3.2.1修改配置文件

将以下两个文件重命名,日志配置文件

    cd /iwisdom/apache-hive-2.1.0-bin/conf
    mv hive-log4j.properties.template hive-log4j.properties
    mv hive-exec-log4j.properties.template hive-exec-log4j.properties

也可以用hive-default.xml.template去改,不过这个文件中的配置项太多了

    cd /iwisdom/apache-hive-2.1.0-bin/conf
    vi hive-site.xml

输入以下内容后保存:
注意下面配置的是:数据库连接串、驱动、用户和密码
···

3.2.2拷贝MySQL驱动

将mysql-connector-java-5.1.30-bin.jar 放入 $HIVE_HOME/lib下

3.2.3初始化Hive
    schematool -initSchema -dbType mysql
3.2.4启动、测试hive
    hive

出现以下是正常:

    Metastore connection URL:        jdbc:mysql://192.168.0.100:3306/wfbhive?createDatabaseIfNotExist=true
    Metastore Connection Driver :    com.mysql.jdbc.Driver
    Metastore connection User:       root
    Starting metastore schema initialization to 2.1.0
    Initialization script hive-schema-2.1.0.mysql.sql
    Initialization script completed
    schemaTool completed

查看hdfs上是否有hive的目录

    hdfs dfs -ls /usr/hive

    Found 1 items
    drwxr-xr-x   - root supergroup          0 2016-08-16 21:44 /user/hive/warehouse

创建数据、创建表、查询数据库中的表。

    create database test;
    use test;

    create table test_table(id int,name string)
    row format delimited fields terminated by '\t';

    show tables;

    OK
    test_table
    Time taken: 0.717 seconds, Fetched: 1 row(s)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值