ubuntu下搭建hive(包括hive的web接口)记录

Hive版本 0.12.0(独立模式)

Hadoop版本 1.12.1

Ubuntu 版本 12.10

今天试着搭建了hive,差点迷失在了网上各种资料中,现在把我的经验分享给大家,亲手实践过,但未必每一步都是必须的,正确的,大家可以参考一下。

第一步:安装和测试mysql(已装好的可跳过)

见我总结的http://blog.csdn.net/unflynaomi/article/details/37811229

 

第二步.开始正式安装hive

1.hdfs上建目录:

 

$ hadoop fs -mkdir /tmp

$ hadoop fs -mkdir /user/hive/warehouse

 

2.添加权限:

$ hadoop fs -chmod g+w   /tmp

$ hadoop fs -chmod g+w   /user/hive/warehouse

 

3.下载解压hive
$ wget   http://mirrors.hust.edu.cn/apache/hive/hive-0.12.0.tar.gz .

下载官网地址 http://mirrors.hust.edu.cn/apache/hive/

然后 mv hive-0.12.0.tar.gz /usr/local/hive-0.12.0

将压缩包移动到/usr/local/hive-0.12.0

$ tar -zxvf hive-0.12.0.tar.gz

hive的官网观察兼容性

15 October, 2013: release 0.12.0 available

This release works with Hadoop 0.20.x, 0.23.x.y, 1.x.y, 2.x.y

可见hive-0.12.0版本与hadoop 1.2.1兼容

 

4.设置HADOOP_HOMEHIVE_HOME,并将其添加到~/.bashrc(你的hadoophive路径)配置环境变量,etc/profile文件末尾添加以下内容:

export HADOOP_HOME=/usr/local/hadoop

export HIVE_HOME=/usr/local/hive-0.12.0

export PATH=$HIVE_HOME/bin:$PATH
执行source /etc/profile更新环境变量

 

5. 创建用户hive,并授权:

root用户登录mysql创建hive用户并授权,执行命令:
use mysql;
insert into user(Host,User,Password) values("localhost","hive",password("hive"));
密码也是
hive
FLUSH PRIVILEGES;

 

6.授予用户hive足够大的权限

GRANT ALL PRIVILEGES ON *.*  TO 'hive'@'localhost' IDENTIFIED BY 'hive';
FLUSH PRIVILEGES;

可以用hive用户登录观察是否创建用户成功

hadoop@ubuntu:/usr/local$ mysql -h localhost -u hive -p

显示:

Enter password:

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

Your MySQL connection id is 78

Server version: 5.5.37-0ubuntu0.12.10.1 (Ubuntu)

 

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

成功登录

 

7.修改hive的配置文件

hive的配置文件放在HIVE_HOME/conf目录下,我们需要修改hive-env.shhive-site.xml这两个文件。ls之后发现并没有这两个文件,但是有hive-env.sh.template,hive-default.xml.template,我们须复制这两个文件,并分别命名为hive-env.sh,hive-site.xml。一般还有一个hive-default.xml文件,同样由hive-default.xml.template复制而来。hive-default.xml是默认配置,hive-site.xml是个性化配置,将会覆盖hive-default.xml配置。切换到hadoop用户下,并复制两个文件:

leefon@ubuntu:/usr/local/hadoop/hive/conf$su hadoop
输入hadoop用户的密码:
hadoop@ubuntu:/usr/local/hadoop/hive/conf$cp hive-default.xml.template hive-default.xml
hadoop@ubuntu:/usr/local/hadoop/hive/conf$cp hive-default.xml.template hive-site.xml
hadoop@ubuntu:/usr/local/hadoop/hive/conf$cp hive-env.sh.template hive-env.sh

其实这个设计很贴心,给你弄个模板,改坏了再,可以复制

配置hive-env.sh

vim打开

export HADOOP_HEAPSIZE=1024前面的‘#’去掉,当然可以根据自己的环境对这个默认的1024进行优化;

#去掉使得改动生效

export HADOOP_HOME前面的‘#’号去掉,并让它指向您所安装hadoop的目录,我的/usr/local/hadoop;

export HIVE_CONF_DIR=/usr/local/hadoop/hive/conf,并且把‘#’号去掉;

export HIVE_AUX_JARS_PATH=/usr/local/hadoop/hive/lib,并且把‘#’号去掉。

esc() :wq

source ./hive-env.sh(生效文件)

 

配置hive-site.xml

首先创建相应的目录,以便与配置文件的路径相对应:

hadoop@ubuntu:/usr/local/hadoop/hive$mkdir /usr/local/hadoop/hive/warehouse

hadoop@ubuntu:/usr/local/hadoop/hive$mkdir /usr/local/hadoop/hive/log

 

在修改时可以用查找功能:/要查找的字符串比如 :/metastore.warehouse.dir

<span style="font-size:18px;"><property>

  <name>hive.metastore.warehouse.dir</name>

  <value>/user/hive/warehouse</value>//你的路径

  <description>location of default database for the warehouse</description>

</property>

#临时文件目录,这个没有可以添加进去

<property>

<name>hive.exec.scratdir</name>

<value>/usr/local/hadoop/hive/tmp</value>

</property>

#存放hive相关日志的目录

<property>

  <name>hive.querylog.location</name>

  <value>/usr/local/hadoop/hive/log</value>//你的路径

  <description>

    Location of Hive run time structured log file

  </description>

</property>

</span>


 

接着修改hive-site.xml这一步将mysqlhive连接

<span style="font-size:18px;"><span style="font-size:18px;"><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>

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

</property>

 

<property>

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

  <value>com.mysql.jdbc.Driver</value>

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

</property>

 

<property>

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

  <value>hive</value>//与mysql中创建hive用户的密码有关

  <description>username to use against metastore database</description>

</property>

 

<property>

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

  <value>hive</value>

  <description>password to use against metastore database</description>

</property>
</span></span>


 

8. 添加jdbc的jar包

mysql的官网上下载jdbc,我使用的版本是5.1.31

下载时需要

Oracle Web 帐户

账户 oracle11r2@163.com

密码 ORA11cle

解压,拷贝到HIVE _HOME/lib目录下

leefon@ubuntu:~/Download$ tar -xvzf mysql-connector-java-5.1.31.tar.gz 

leefon@ubuntu:~/Download$ cp mysql-connector-java-5.1.25/*.jar /usr/local/hadoop/hive/lib 

 

9.启动hive

hadoop@ubuntu:/usr/local/hadoop/hive$ bin/hive 

出现

差不多装好了,别忘了加;一定要试下面的show table

hadoop@ubuntu:/usr/local/hadoop/hive$ hive> show tables; 

报错

FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

我是这么解决的

hive.site.xml文件中的

<property>
  <name>hive.metastore.schema.verification</name>
  <value><strong><span style="color:#ff0000;">true</span></strong></value>
   <description>
   </description>
</property>

true改为false



 

<pre>
改后效果:

<property>
  <name>hive.metastore.schema.verification</name>
  <value><strong><span style="color:#ff0000;">false</span></strong></value>
   <description>
   Enforce metastore schema version consistency.
   True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic
         schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures
         proper metastore schema migration. (Default)
   False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
   </description>
</property>


 

 

10.再次启动hive

hadoop@ubuntu:/usr/local/hadoop/hive$ bin/hive 

出现,进入hive shell

hadoop@ubuntu:/usr/local/hadoop/hive$ hive> show tables;

第一次启动时间比较长,耐心等待

试着插入一个表格

create table table1 (a int, b int);

显示

安装成功

观察传说中的mysql hive数据库是否存在

hive用户登录mysql

hadoop@ubuntu:/usr/local$ mysql -h localhost -u hive -p

Enter password:

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

Your MySQL connection id is 78

Server version: 5.5.37-0ubuntu0.12.10.1 (Ubuntu)

 

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

 

mysql> show tables;

ERROR 1046 (3D000): No database selected

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| hive               |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.14 sec)

 

mysql> use hive;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_hive            |

+---------------------------+

| BUCKETING_COLS            |

| CDS                       |

| COLUMNS_V2                |

| DATABASE_PARAMS           |

| DBS                       |

| PARTITION_KEYS            |

| SDS                       |

| SD_PARAMS                 |

| SEQUENCE_TABLE            |

| SERDES                    |

| SERDE_PARAMS              |

| SKEWED_COL_NAMES          |

| SKEWED_COL_VALUE_LOC_MAP  |

| SKEWED_STRING_LIST        |

| SKEWED_STRING_LIST_VALUES |

| SKEWED_VALUES             |

| SORT_COLS                 |

| TABLE_PARAMS              |

| TBLS                      |

| VERSION                   |

+---------------------------+

20 rows in set (0.00 sec)

 

mysql>

可见成功了。


 

11.安装hive网络接口

退出hive shell,回到命令行

输入

hadoop@ubuntu:/usr/local/hive-0.12.0$ bin/hive --service metastore &

&表示后台

显示

[1] 7710

hadoop@ubuntu:/usr/local/hive-0.12.0$ Starting Hive Metastore Server

不用苦等他结束,直接输入

bin/hive --service metastore &

bin/hive --service hwi &

显示

开始了服务

可以在hive.site.xml查看一下hive的端口

<span style="font-size:18px;"><property>

  <name>hive.hwi.listen.host</name>

  <value>0.0.0.0</value>

  <description>This is the host address the Hive Web Interface will listen on</description>

</property>

 

<property>

  <name>hive.hwi.listen.port</name>

  <value>9999</value>

  <description>This is the port the Hive Web Interface will listen on</description>

</property>

</span>


发现是9999

 

12.登录网络接口

需要本机ip地址

命令为

ifconfig -a |grep inet

然后打开浏览器输入地址

http://你的机器ip:9999/hwi

比如

http://100.138.6.123:9999/hwi

显示

这时如果再次尝试

bin/hive --service metastore &

就会抛出许多异常,因为端口已被占用

org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address 0.0.0.0/0.0.0.0:9083.

         at org.apache.thrift.transport.TServerSocket.<init>(TServerSocket.java:93)

         at org.apache.thrift.transport.TServerSocket.<init>(TServerSocket.java:75)

主要参考

http://www.cnblogs.com/bjtu-leefon/p/3170044.html

http://blog.csdn.net/yfkiss/article/details/7721329#

http://www.linuxidc.com/Linux/2013-06/86104.htm

http://blog.csdn.net/yonghutwo/article/details/23700749

http://blog.163.com/songyalong1117@126/blog/static/1713918972014124481752/


大功告成!!!!

原文地址:https://www.cnblogs.com/unflynaomi/p/4476871.html