Hive安装配置详解

来源:互联网 发布:217淘宝站外平台哪个好 编辑:程序博客网 时间:2024/06/05 22:34

本文主要是在Hadoop单机模式中演示Hive默认(嵌入式derby 模式)安装配置过程,目录结构如下:

  • 基础环境
  • Hive安装配置
  • 启动及演示

[一]、基础环境

  • Mac OSX 10.9.1
  • Java 1.6+ 
  • Hadoop 2.2.0 (单机模式安装配置详见:http://www.micmiu.com/opensource/hadoop/hadoop2x-single-node-setup/ )
  • Hive 0.12.0 (截止2014-02-09最新的发布版本)

[二]、Hive安装配置

1、下载发布包

到官方下载最近发布包以 0.12.0为例:

1tar -zxf hive-0.12.0-bin.tar.gz -C /usr/local/share
2cd /usr/local/share
3ln -s hive-0.12.0-bin hive

本文中 HIVE_HOME = “/usr/local/share/”

2、设置环境变量

执行 vi ~/.profile ,添加如下内容:

1#Hive @micmiu.com
2export HIVE_HOME="/usr/local/share/hive"
3export PATH=$HIVE_HOME/bin:$PATH

3、配置文件

在目录 <HIVE_HOME>/conf 目录下有4个模板文件:

1hive-default.xml.template
2hive-env.sh.template
3hive-exec-log4j.properties.template
4hive-log4j.properties.template

copy 生成四个配置文件然后既可自定义相关属性:

1cd  /usr/local/share/hive/conf
2$ copy hive-default.xml.template hive-site.xml
3$ copy hive-env.sh.template hive-env.sh
4$ copy hive-exec-log4j.properties.template hive-exec-log4j.properties
5$ copy hive-log4j.properties.template hive-log4j.properties

ps:注意文件名称: hive-site.xml ,本文以嵌入式derby 模式做演示,故以默认配置即可无效修改相关参数。

不过官方0.12.0的发布版本中的 hive-default.xml.template 中有 bug,在 2000行:

<value>auth</auth>  修改为:<value>auth</value>

有关 hive.metastore.schema.verification 版本检查的问题,有两个解决办法

方法一:修改配置文件

第一次运行前先将 hive.metastore.schema.verification 设为false

1......
2<!-- 设为false 不做验证-->
3<name>hive.metastore.schema.verification</name>
4<value>false</value>
5......

方法二:不改配置,先初始化好数据

执行初始化命令:schematool -dbType derby -initSchema

1micmiu-mbp:~ micmiu$ schematool -dbType derby -initSchema
2Metastore connection URL:    jdbc:derby:;databaseName=metastore_db;create=true
3Metastore Connection Driver :    org.apache.derby.jdbc.EmbeddedDriver
4Metastore connection User:   APP
5Starting metastore schema initialization to 0.12.0
6Initialization script hive-schema-0.12.0.derby.sql
7Initialization script completed
8schemaTool completeted

查看初始化后的信息: schematool -dbType derby -info

1micmiu-mbp:~ micmiu$ schematool -dbType derby -info
2Metastore connection URL:    jdbc:derby:;databaseName=metastore_db;create=true
3Metastore Connection Driver :    org.apache.derby.jdbc.EmbeddedDriver
4Metastore connection User:   APP
5Hive distribution version:   0.12.0
6Metastore schema version:    0.12.0
7schemaTool completeted

详见:https://cwiki.apache.org/confluence/display/Hive/Hive+Schema+Tool

以上方法都可以,否则第一次运行时会类似如下的报错信息:

1ERROR exec.DDLTask (DDLTask.java:execute(435)) - org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
2        at org.apache.hadoop.hive.ql.metadata.Hive.getDatabase(Hive.java:1143)
3        ......
4Caused by: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
5        at org.apache.hadoop.hive.metastore.MetaStoreUtils.newInstance(MetaStoreUtils.java:1212)
6        ......
7Caused by: java.lang.reflect.InvocationTargetException
8        ......
9Caused by: MetaException(message:Version information not found in metastore. )
10        at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:5638)
11        at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:5622)
12        ......

4、配置dfs中得目录和权限

1$ hdfs dfs -mkdir       /tmp
2$ hdfs dfs -mkdir       /user/hive/warehouse
3$ hdfs dfs -chmod g+w   /tmp
4$ hdfs dfs -chmod g+w   /user/hive/warehouse

[三]、运行和测试

确保HADOOP_HOME 在环境变量中配置好,然后以CLI(command line interface)方式下运行,直接执行命令  hive 即可,然后执行一些测试命令如下:

1hive> show databases;
2OK
3default
4Time taken: 4.966 seconds, Fetched: 1 row(s)
5hive> show tables;
6OK
7Time taken: 0.186 seconds
8hive> CREATE TABLE micmiu_blog (id INT, siteurl STRING);
9OK
10Time taken: 0.359 seconds
11hive> SHOW TABLES;
12OK
13micmiu_blog
14Time taken: 0.023 seconds, Fetched: 1 row(s)
15hive>

到此嵌入式derby 模式下的Hive安装配置已经成功。

参考:

  • https://cwiki.apache.org/confluence/display/Hive/Home
  • https://cwiki.apache.org/confluence/display/Hive/GettingStarted
  • https://cwiki.apache.org/confluence/display/Hive/Hive+Schema+Tool
  • https://cwiki.apache.org/confluence/display/Hive/AdminManual+MetastoreAdmin

—————–  EOF @Michael Sun —————–

0 0
原创粉丝点击