Hive安装配置详解

  本文主要是在Hadoop单机模式中演示Hive默认(嵌入式Derby模式)安装配置过程。

1、下载安装包

到官方网站下载最新的安装包,这里以Hive-0.12.0为例:

$ tar -zxf hive-0.12.0-bin.tar.gz -C /home/ubuntu/hive-0.12.0

在这里,HIVE_HOME=” /home/ubuntu/hive-0.12.0”。

2、设置环境变量

gedit /etc/profile,添加如下内容:

export HIVE_HOME=/home/ubuntu/hive-0.12.0export PATH=$HIVE_HOME/bin:$PATH

3、定义配置文件

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

hive-default.xml.template

hive-env.sh.template

hive-exec-log4j.properties.template

hive-log4j.properties.template

以它们为模板,定义对应的配置文件,其中最重要的是hive-site.xmlhive-env.sh

$ cd  /home/ubuntu/hive-0.12.0/conf$ cp hive-default.xml.template hive-site.xml$ cp hive-env.sh.template hive-env.sh$ cp hive-exec-log4j.properties.template hive-exec-log4j.properties$ cp hive-log4j.properties.template hive-log4j.properties

    本文以嵌入式Derby模式做演示,故hive-site.xml以默认配置即可无需修改相关参数。但是需要根据自己具体的安装情况来更新  hive-env.sh中的配置信息:

# Set HADOOP_HOME to point to a specific hadoop install directoryexport HADOOP_HOME=/home/ubuntu/hadoop-1.2.1# Hive Configuration Directory can be controlled by:export HIVE_CONF_DIR=/home/ubuntu/hive-0.12.0/confexport HIVE_HOME=/home/ubuntu/hive-0.12.0export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64# Folder containing extra ibraries required for hive compilation/execution can be controlled by:# export HIVE_AUX_JARS_PATH=

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

  4、配置HDFS中的目录和权限

$ hadoop dfs -mkdir       /tmp$ hadoop dfs -mkdir       /user/hive/warehouse$ hadoop dfs -chmod g+w   /tmp$ hadoop dfs -chmod g+w   /user/hive/warehouse

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

方法一:运行前先将hive.metastore.schema.verification 设为false

......
hive.metastore.schema.verification
false
......

方法二:不改配置,先初始化好数据,执行初始化命令:schematool -dbType derby -initSchema

$ schematool -dbType derby -initSchemaMetastore connection URL:    jdbc:derby:;databaseName=metastore_db;create=trueMetastore Connection Driver :    org.apache.derby.jdbc.EmbeddedDriverMetastore connection User:   APPStarting metastore schema initialization to 0.12.0Initialization script hive-schema-0.12.0.derby.sqlInitialization script completedschemaTool completeted

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

$ schematool -dbType derby -infoMetastore connection URL:    jdbc:derby:;databaseName=metastore_db;create=trueMetastore Connection Driver :    org.apache.derby.jdbc.EmbeddedDriverMetastore connection User:   APPHive distribution version:   0.12.0Metastore schema version:    0.12.0schemaTool completeted

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

ERROR 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        at org.apache.hadoop.hive.ql.metadata.Hive.getDatabase(Hive.java:1143)

6、运行和测试

启动HADOOP的所有进程,然后在命令行方式下执行命令hive即可,然后就可以执行以下测试命令

hive> show databases;OKdefaultTime taken: 4.966 seconds, Fetched: 1 row(s)hive> show tables;OKTime taken: 0.186 secondshive> CREATE TABLE micmiu_blog (id INT, siteurl STRING);OKTime taken: 0.359 secondshive> SHOW TABLES;OKmicmiu_blogTime taken: 0.023 seconds, Fetched: 1 row(s)hive>

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