一、Hive安装
- 官方下载地址:http://www.apache.org/dyn/closer.cgi/hive/,可在其中寻找镜像
- 下载安装命令:
wget http://mirror.bit.edu.cn/apache/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz
sudo tar -zxf apache-hive-1.2.1-bin.tar.gz -C /usr/local
cd /usr/local/
sudo mv apache-hive-1.2.1-bin/ hive
sudo chown -R hadoop:hadoop hive
sudo mkdir -p /usr/local/hive/warehouse
sudo chmod a+rwx /usr/local/hive/warehouse
- 将Hive命令配置到系统环境变量,使用命令
vim ~/.bashrc
编辑.bashrc文件。在文件中添加如下文本。
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
- 使配置生效
source ~/.bashrc
- 运行Hive,成功会出现如下消息
hadoop@ubuntu:/usr/local/hive$ hive
Logging initialized using configuration in jar:file:/usr/local/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive>
- 启动失败,可能会出现如下错误:
......
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
at jline.TerminalFactory.create(TerminalFactory.java:101)
at jline.TerminalFactory.get(TerminalFactory.java:158)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
at org.apache.hadoop.hive.cli.CliDriver.setupConsoleReader(CliDriver.java:787)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:721)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:681)
......
解决方法:
rm /usr/local/hadoop/share/hadoop/yarn/lib/jline-0.9.94.jar
hive
二、Hive配置
在$HIVE_HOME/conf目录下,创建hive-site.xml文件(conf目录下,有hive-default.xml.template这个文件,它包含了Hive提供的配置属性及默认属性),默认情况下,元数据存储在Derby数据库中,Derby是Java编写的数据库,可跨平台,但需在JVM中运行。因多用户和系统需并发访问元数据存储,所以Derby并不适用于生产环境。任何一个适用于JDBC进行连接的数据库都可用于元数据存储,一般将MySQL作为存储元数据的数据库。
2-1 使用Derby存储元数据
本地模式中,用户的“表”等元数据信息,都默认存储在file://user/hive/warehouse;其他模式默认存储路径是hdfs://namenode_server/user/hive/warehouse。
- 使用命令:
vim /usr/local/hive/conf/hive-site.xml
,配置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>/usr/local/hive/warehouse</value>
<description>location of default database for the datahouse</description>
</property>
<property>
<name>javax.jdo.o