Hive的安装和配置详解

来源:互联网 发布:中兴端口查询mac 编辑:程序博客网 时间:2024/05/29 10:34

Hive的安装和配置详解

转自:http://hi.baidu.com/loveq369/item/55a9aba1c3b1effe15329b85

一直使用别人装好的Hive,想自己安装个Hive,在网上找了很多配置文档,都写的太简单了,于是自己摸索了下,记录在这里。

1. 安装Hive之前必须先安装好Hadoop,单机的或者集群都可以。

  因为Hive是基于hadoop的,它是将用户编写的类SQL语句转化为可以在hadoop上执行的mapreduce程序,要先保证hadoop可以正常使用。

2. 到apache的网站下载Hive的压缩包,http://hive.apache.org/releases.html

 我下载的是 hive-0.7.0-bin.tar.gz , 解压:  

?

tar zxf hive-0.7.0-bin.tar.gz   

3. 在.bashrc文件中配置Hive和Hadoop的路径

?

cat ~/.bashrc

export HADOOP_HOME=/home/steven/hadoop

export HIVE_HOME=/home/steven/hive

export HIVE_CONF_DIR=$HIVE_HOME/conf

export HIVE_LIB=$HIVE_HOME/lib

export CLASSPATH=$CLASSPATH:$HIVE_LIB

export PATH=$HIVE_HOME/bin/:$PATH

4. 在$HIVE_HOME/conf目录下,新建一个hive-site.xml,配置Hive元数据的存储方式,默认是采用一个轻量级的内存数据库derby。

  采用derby数据库的hive-site.xml文件如下:

?

<configuration>

<property>

  <name>hive.metastore.local</name>

  <value>true</value>

  <description>controls whether to connect to remove metastore server or open a new metastore server in Hive Client JVM</description>

</property>

<property>

  <name>javax.jdo.option.ConnectionURL</name>

  <value>jdbc:derby://localhost:1527/metastore_db;create=true</value>

  <description>JDBC connect string for a JDBC metastore</description>

</property>

<property>

  <name>javax.jdo.option.ConnectionDriverName</name>

  <value>org.apache.derby.jdbc.ClientDriver</value>

  <description>Driver class name for a JDBC metastore</description>

</property>

</configuration>

  如果在Hive执行的时候,遇到“ERROR exec.DDLTask: FAILED: Error in metadata: java.lang.IllegalArgumentException: URI:  does not have a scheme”这种错误就可能是$HIVE_HOME,$HIVE_CONF_DIR,$HIVE_LIB配置不对,导致hive找不到元数据的配置文件或者找不到元数据的数据库导致的。

  现在我们执行$HIVE_HOME/bin/hive后showtables命令,会提示“java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused”。这是因为我们的derby数据库没有安装,服务没有启动,1527是derby的默认端口。

5. 安装derby数据库

  Hive默认是采用derby数据库来存放元数据信息,可以发现在$HIVE_HOME/lib下有derby.jar和derbyclient.jar。

    从 http://db.apache.org/derby/releases/release-10.7.1.1.html 下载 db-derby-10.7.1.1-bin.tar.gz 。

    解压后,在~/.bashrc中配置环境变量:

?

export DERBY_HOME=/home/steven/derby

  启动derby数据库服务:

?

cd $DERBY_HOME/bin

./startNetworkServer &

6. 现在可以运行hive了。

 我们可以创建一个表试试。

?

[steven@search001 ~]$cd $HIVE_HOME

[steven@search001 hive]$./bin/hive

Hive history file=/tmp/steven/hive_job_log_steven_201107151707_1593375167.txt

hive> show tables;

OK

Time taken: 2.236 seconds

hive> create table auction(nid INT, price INT)

    > row format delimited

    > fields terminated by ','

    > stored as textfile;

OK

Time taken: 0.508 seconds

hive> show tables;

OK

auction

Time taken: 0.118 seconds

hive> desc auction;

OK

nid     int   

price   int   

Time taken: 0.177 seconds

hive>

7. 在第4步除了采用derby数据库来存元数据外,还可以采用mysql数据库。如果采用mysql库,需要把相应的jar包,如mysql-connector-java-5.1.11-bin.jar拷贝到$HIVE_HOME/lib/下

    采用mysql库的hive-site.xml配置如下

?

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<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>datanucleus.fixedDatastore</name>

  <value>false</value>

</property>

</configuration>

   在mysql库中必须创建用户hive,密码也为hive。还要给hive用户赋予权限,否则会提示如下错误:

-bash-3.2$ ./hive

Hive history file=/home/admin/hive-log//hive_job_log_admin_201202211022_217216149.txt

hive> show tables;

FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Access denied for user 'hive'@'localhost' to database 'hive'

NestedThrowables:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'hive'@'localhost' to database 'hive'

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

hive>

     在mysql中创建hive用户,操作如下:

?

mysql> CREATE USER 'hive'@'localhost' IDENTIFIED BY 'hive';         

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'hive'@'localhost' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

  可以用hive用户登录试验添加成功了没

?

-bash-3.2$ mysql -uhive -phive

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 317586

Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

  ok了.

8.  btw, 学习Hive的参考资料:

     恨少的hive学习小结

     淘宝数据平台Hive

0 0
原创粉丝点击