Hadoop2.9.1 安装 Hive2.3.3 on ubuntu 16.04

前言

http://hive.apache.org/downloads.html 上有说明,hadoop3.x版本需要hive3.0.0,而hadoop2.x需要hive2.3.3。因为我的hadoop是2.9,所以选择下载hive2.3.3。Hive是hadoop的工具,所以只需要安装在NameNode上,不需要安装在DataNode上。

Hadoop 安装请移步

https://blog.51cto.com/ljohn/2307655

安装 Hive2.3.3

1、下载 Hive

# 下载地址:
wget http://mirrors.shu.edu.cn/apache/hive/stable-2/apache-hive-2.3.3-bin.tar.gz

# 解压Hive2.3.3
tar xvf apache-hive-2.3.3-bin.tar.gz -C /usr/local/
chown -R hadoop.hadoop  /usr/local/apache-hive-2.3.3-bin/

2、配置 Hive2.3.3 环境变量

cat << EOF >> ~/.bashrc
HIVE_HOME=/usr/local/apache-hive-2.3.3-bin
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_HOME/bin:$HIVE_HOME/bin:$HIVE_HOME/conf
export JAVA_HOME JRE_HOME CLASS_PATH PATH HADOOP_HOME HIVE_HOME
EOF
source /etc/profile

3、配置 hive-env.sh

cat < EOF > /usr/local/apache-hive-2.3.3-bin/hive-env.sh

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_HOME=/usr/local/hadoop
export HIVE_HOME=/usr/local/apache-hive-2.3.3-bin

# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=$HIVE_HOME/conf

# Folder containing extra libraries required for hive compilation/execution can be controlled by:
export HIVE_AUX_JARS_PATH=$HIVE_HOME/lib/*
EOF 

4、配置 hive-site.xml

Hive环境模式有3中,本例中采用了内嵌模式
cp hive-default.xml.template hive-site.xml

hive-site.xml 文件内容不需要修改,主要配置


    hive.metastore.warehouse.dir
    /user/hive/warehouse
    location of default database for the warehouse

..

    hive.exec.scratchdir
    /tmp/hive
    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}/<username> is created, with ${hive.scratch.dir.permission}.

注:

  • hive.metastore.warehouse.dir

    该参数指定了Hive的数据存储目录,默认位置在HDFS上面的 /user/hive/warehouse路径下

  • hive.exec.scratchdir

    该参数指定了Hive的数据临时文件目录,默认位置为HDFS上面的 /tmp/hive路径下

5、创建HDFS目录

hive-site.xml 文件中有两个重要的HDFS路径/user/hive/warehouse和/tmp/hive,需要在HDFS中创建,并修改权限

hadoop fs -mkdir /user
hadoop fs -mkdir /user/hive
hadoop fs -mkdir /user/hive/warehouse
hadoop fs -mkdir /tmp/hive
hadoop fs -chmod  777 /user/hive/warehouse
hadoop fs -chmod  777 /tmp/hive

6、初始化数据库

内嵌模式用的是本地数据库derby

./schematool -initSchema -dbType derby 
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL:        jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver :    org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:       APP
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.derby.sql
Initialization script completed
schemaTool completed

7、启动hive

进入$HIVE_HOME/bin目录

cd $HIVE_HOME/bin
./hive

# 测试
hive> show tables;
OK
Time taken: 7.101 seconds

FAQ

Q1: 启动 Hive 报错

Logging initialized using configuration in jar:file:/usr/local/apache-hive-2.3.3-bin/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
        at org.apache.hadoop.fs.Path.initialize(Path.java:254)
        at org.apache.hadoop.fs.Path.(Path.java:212)
        at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:659)
        at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:582)
        at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:549)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:750)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:686)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:239)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
        at java.net.URI.checkPath(URI.java:1823)
        at java.net.URI.(URI.java:745)
        at org.apache.hadoop.fs.Path.initialize(Path.java:251)
        ... 12 more

A1:

在hive-site.xml文件最前面增加如下配置,重启hive

创建一个缓存目录:mkdir -p /usr/local/apache-hive-2.3.3-bin/tmpdir


     system:java.io.tmpdir
     /usr/local/apache-hive-2.3.3-bin/tmpdir
  
  
     system:user.name
     hive