Hive 入门

Submitted by Lizhe on Wed, 05/03/2017 - 23:19

下载

http://apache.fayea.com/hive/hive-1.2.2/apache-hive-1.2.2-bin.tar.gz

这里我解压到

/download/apache-hive-1.2.2-bin

以下操作均已上面路径为基础

先创建几个目录

[root@lzvm apache-hive-1.2.2-bin]# ls
bin  conf  examples  hcatalog  lib  LICENSE  NOTICE  README.txt  RELEASE_NOTES.txt  scripts
[root@lzvm apache-hive-1.2.2-bin]# mkdir log
[root@lzvm apache-hive-1.2.2-bin]# mkdir tmp

[root@lzvm apache-hive-1.2.2-bin]# mkdir tmp2

[root@lzvm apache-hive-1.2.2-bin]# mkdir tmp3
[root@lzvm apache-hive-1.2.2-bin]# /download/hadoop-2.6.5/bin/hadoop fs -mkdir /hive

从conf配置目录里重命名3个template文件

cp hive-default.xml.template hive-default.xml

cp hive-default.xml.template hive-site.xml

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

配置hive-env.sh

将export HADOOP_HEAPSIZE=1024前面的‘#’去掉

将export HADOOP_HOME前面的‘#’号去掉 指向hadoop home路径,我这里是 HADOOP_HOME=/download/hadoop-2.6.5

将export HIVE_CONF_DIR=/usr/local/hadoop/hive/conf前面的‘#’号去掉,并让它指向相应的目录 export HIVE_CONF_DIR=/download/apache-hive-1.2.2-bin/conf

将export HIVE_AUX_JARS_PATH=/usr/local/hadoop/hive/lib前面的‘#’号去掉,并让它指向相应的目录 export HIVE_AUX_JARS_PATH=/download/apache-hive-1.2.2-bin/lib

调用source命令让配置生效 source ./hive-env.sh

修改hive-site.xml

<property>
    <name>hive.metastore.warehouse.dir</name>
    <value>hdfs://lzvm:9000/hive</value>
    <description>location of default database for the warehouse</description>
  </property>
 

<property>
    <name>hive.exec.scratchdir</name>
    <value>/download/apache-hive-1.2.2-bin/tmp</value>
    <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/&lt;username&gt; is created, with ${hive.scratch.dir.permission}.</description>
  </property>
  <property>
    <name>hive.exec.local.scratchdir</name>
    <value>/download/apache-hive-1.2.2-bin/tmp2</value>
    <description>Local scratch space for Hive jobs</description>
  </property>
  <property>
    <name>hive.downloaded.resources.dir</name>
    <value>/download/apache-hive-1.2.2-bin/tmp3/${hive.session.id}_resources</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>
 

<property>
    <name>hive.querylog.location</name>
    <value>/download/apache-hive-1.2.2-bin/log</value>
    <description>Location of Hive run time structured log file</description>
  </property>
 

如果出现下面的错误是jar包版本的问题

Found class jline.Terminal, but interface was expected

cp /download/hadoop-2.6.5/share/hadoop/yarn/lib/jline-0.9.94.jar /download/hadoop-2.6.5/share/hadoop/yarn/lib/jline-0.9.94.jar.bak

rm -rf /download/hadoop-2.6.5/share/hadoop/yarn/lib/jline-0.9.94.jar

 cp /download/apache-hive-1.2.2-bin/lib/jline-2.12.jar /download/hadoop-2.6.5/share/hadoop/yarn/lib/

最后使用bin目录下./hive 来启动进入hive的shell

114

最后我们试试创建一个表插入一条数据

115