ubuntu14.04配置Hive1.2.1

1、添加环境变量:vi ~/.bashrc

#HIVE VARIABLES START
export HIVE_HOME=/usr/local/hive-1.2.1
export PATH=$PATH:$HIVE_HOME/bin
export PATH=$PATH:$HIVE_HOME/hcatalog/bin:$HIVE_HOME/hcatalog/sbin
export CLASSPATH=$CLASSPATH:$HIVE_HOME/lib //可以不配
export HIVE_CONF_DIR=$HIVE_HOME/conf //可以不配
#HIVE VARIABLES END

2、替换Hadoop下的lib

cp /usr/local/hive-1.2.1/lib/jline-2.12.jar  /usr/local/hadoop-2.6.0/share/hadoop/yarn/lib/
rm -rf jline-0.9.94.jar

3、修改配置文件

cp hive-default.xml.template hive-default.xml
cp hive-default.xml.template hive-site.xml
//一下三项可以不配
cp hive-exec-log4j.properties.template hive-exec-log4j.properties
cp hive-log4j.properties.template hive-log4j.properties
cp beeline-log4j.properties.template beeline-log4j.properties

把几个带.template后缀的模板文件,复制一份变成不带.template的配置文件,注意hive-default.xml.template这个要复制二份,一个是hive-default.xml,另一个是hive-site.xml,其中hive-site.xml为用户自定义配置,hive-default.xml为全局配置,hive启动时,-site.xml自定义配置会覆盖-default.xml全局配置的相同配置项。

hive-site.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configuration>
    <property> //该项可以不配
        <name>hive.metastore.local</name>
        <value>true</value>
</property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.jdbc.Driver</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>hive</value>
    </property>
    <property>
        <name>hive.exec.scratchdir</name>
        <value>/tmp/hive</value>
    </property>
    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive/warehouse</value>
    </property>
</configuration>

4、ubuntu下mysql安装

 sudo apt-get install mysql-server
 sudo apt-get install mysql-client
 sudo apt-get install libmysqlclient-dev

5、添加mysql-connector
下载mysql-connector-java-3.1.12-bin.jar文件,并放到$HIVE_HOME/lib目录下
6、mysql权限设置

mac启动mysql服务

mysql.server start
mysql -uroot -p

ubuntu启动mysql服务

service mysql start

建立数据库hive,并设定为latin1编码

create database hive default character set latin1;

创建用户hive

create user 'hive'@'%' identified by 'hive';
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' WITH GRANT OPTION;
grant all on *.* to hive@'localhost'  identified by 'hive';
flush privileges;  

图形界面搭建:
http://blog.csdn.net/ggz631047367/article/details/49979109
Hive使用:
http://my.oschina.net/leejun2005/blog/120463

出错记录:

问题1:

Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
    at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:522)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:677)
    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:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
……
NestedThrowables:
java.sql.SQLException: Unable to open a test connection to the given database. JDBC url = jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true, username = hive. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------
java.sql.SQLException: Access denied for user 'hive'@'localhost' (using password: YES)
……
Caused by: java.sql.SQLException: Access denied for user 'hive'@'localhost' (using password: YES)

解决:

mysql -uroot -p
grant all on hive.* to hive@’localhost’  identified by ’hive’; 
flush privileges;  

问题2:

Logging initialized using configuration in jar:file:/hive/apache-hive-1.1.0-bin/lib/hive-common-1.1.0.jar!/hive-log4j.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/hadoop-2.5.2/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/hive/apache-hive-1.1.0-bin/lib/hive-jdbc-1.1.0-standalone.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.slf4j.impl.Log4jLoggerFactory]
[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.getConsoleReader(CliDriver.java:773)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:715)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:615)
        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)

解决方法是:
将hive下的新版本jline的JAR包拷贝到hadoop下:

cp /usr/local/hive-1.2.1/lib/jline-2.12.jar  /usr/local/hadoop-2.6.0/share/hadoop/yarn/lib/
rm -rf jline-0.9.94.jar

问题3:

Logging initialized using configuration in file:/usr/local/hive-1.2.1/conf/hive-log4j.properties
Exception in thread "main" java.lang.RuntimeException: java.net.ConnectException: Call From master/192.168.2.214 to master:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
    at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:522)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:677)
    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:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.ConnectException: Call From master/192.168.2.214 to master:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

检查hdfs是否启动

原文地址:https://www.cnblogs.com/ggzone/p/10121234.html