Contents
  1. 1. 1.安装Java
  2. 2. 2.安装Hadoop
  3. 3. 3.安装Hive
  4. 4. 启动hive报错

Hive依赖于Hadoop,而Hadoop依赖于Java。

1.安装Java

下载地址:

http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk7-downloads-1880260.html

直接rpm安装即可

[root@mysql mysql]# rpm -ivh jdk-7u79-linux-x64.rpm 
Preparing...                ########################################### [100%]
1:jdk                    ########################################### [100%]
Unpacking JAR files...
    rt.jar...
    jsse.jar...
    charsets.jar...
    tools.jar...
    localedata.jar...
    jfxrt.jar...
[mysql@mysql]$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

修改.bash_profile文件加入环境变量

[mysql@mysql ~]$ vi .bash_profile     
export JAVA_HOME=/usr/java
PATH=$PATH:$JAVA_HOME/bin

或用如下方法

[root@mysql]$ sudo echo "export JAVA_HOME=/usr/java/latest/">>/etc/profile.d/java.sh 
[root@mysql]$ sudo echo "PATH=$PATH:$JAVA_HOME/bin">>/etc/profile.d/java.sh
[root@mysql]$  . /etc/profile
[root@mysql]$ echo $JAVA_HOME
/usr/java/latest/
注:关于/etc/profile和/etc/profile.d/
  1. 两个文件都是设置环境变量文件的,/etc/profile是永久性的环境变量,是全局变量,/etc/>profile.d/设置所有用户生效
  1. /etc/profile.d/比/etc/profile好维护,不想要什么变量直接删除/etc/profile.d/下对应的>shell脚本即可,不用像/etc/profile需要改动此文件

2.安装Hadoop

下载地址:

http://hadoop.apache.org/releases.html

这里下载版本为2.5.2

[root@mysql mysql]$ tar -xvf hadoop-2.5.2.tar.gz 

修改.bash_profile文件加入环境变量
[root@mysql mysql]$ vi .bash_profile
HADOOP_HOME=/home/mysql/hadoop
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$HADOOP_HOME/bin
export PATH
export HADOOP_HOME

3.安装Hive

下载地址:

http://hive.apache.org/downloads.html

解压安装文件后重命名目录为hive

[mysql@mysql ~]$ tar -xvf apache-hive-1.2.1-bin.tar.gz 
[mysql@mysql ~]$ mv apache-hive-1.2.1-bin hive
[mysql@mysql ~]$ sudo mkdir /usr/hive/warehouse -p
[mysql@mysql ~]$ sudo chmod a+rwx /usr/hive/warehouse/ 

修改.bash_profile文件加入环境变量

[mysql@mysql ~]$ vi .bash_profile
JAVA_HOME=/usr/java/latest
HADOOP_HOME=/home/mysql/hadoop
HIVE_HOME=/home/mysql/hive
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HIVE_HOME/bin
export PATH
export JAVA_HOME
export HADOOP_HOME
export HIVE_HOME

使变量生效

[mysql@mysql ~]$ . .bash_profile

启动hive报错

[mysql@mysql ~]$ hive

Logging initialized using configuration in jar:file:/home/mysql/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties
[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)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:621)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

Exception in thread "main" java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:230)
    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)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:621)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

原因是hadoop目录下存在老版本jline:

[mysql@mysql lib]$ ll|grep jline
-rw-r--r--. 1 10021 10021   87325 Nov 15  2014 jline-0.9.94.jar

解决方法是:
将hive/lib/下的新版本jline的JAR包拷贝到hadoop/share/hadoop/yarn/lib/目录下:

[mysql@mysql ~]$ cp hive/lib/jline-2.12.jar hadoop/share/hadoop/yarn/lib/

重新启动hive成功

[mysql@mysql ~]$ hive

Logging initialized using configuration in jar:file:/home/mysql/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> 
Contents
  1. 1. 1.安装Java
  2. 2. 2.安装Hadoop
  3. 3. 3.安装Hive
  4. 4. 启动hive报错