本篇主要介绍配置Hue来使用Hive,通过Hue的Web UI来使用Hive的查询功能。配置分为两部分,一个是针对Hive本身的配置,一个是针对Hue的配置。
Hive数据存储在HDFS上,默认路径是【/user/hive/warehouse】(或者是在hive-site.xml中配置的hive.metastore.warehouse.dir),要确保这个路径存在,并且你创建数据表的用户对这个路径具有写权限。
修改【HUE_HOME/desktop/conf】目录下的hue.ini关于beeswax的配置来集成Hive,这些配置位于[beeswax]
# Host where HiveServer2 is running.
# If Kerberos security is enabled, use fully-qualified domain name (FQDN).
hive_server_host=hadoop-main.dimensoft.com.cn
# Port where HiveServer2 Thrift server runs on.
hive_server_port=10000
# Hive configuration directory, where hive-site.xml is located
hive_conf_dir=/usr/local/cdh-5.2.0/hive-0.13.1/conf
在hive中准备若干数据,测试是否能够从hue的Web UI查询出这些数据。
在【/usr/local/cdh-5.2.0/hive-0.13.1】目录下创建department.txt,内容如下:
boss 4
test 15
investigative 50
dev 40
高能预警:不同字段之间的分隔符一定要和创建表的时候声明的分隔符一致!在这里是\t,即一个制表符,如果是使用空格的话则会导入数据与预期数据不一致!
这里需要同时启动hive的metastore和hiveserve2。进入【HIVE_HOME】目录下来启动服务
$ bin/hive --service metastore
高能预警:matestore服务是Hive连接Mysql的metastore数据库用的。
$ bin/hive --service hiveserver2
高能预警:hiveserver2服务是通过JDBC访问Hive用的,默认端口是:10000。
在【HIVE_HOME】目录下进入hive的CLI界面
$ bin/hive
创建数据库
> create database my_test;
> use my_test;
创建数据表
> create table department(name string, count int) row format delimited fields terminated by '\t';
高能预警:这里的 terminated by ‘\t’ 是与创建表时所声明的字段分隔符一致的。
导入数据
> load data local inpath '/usr/local/cdh-5.2.0/hive-0.13.1/department.txt' into table department;
查询
> select * from department;
进入【HUE_HOME】目录下启动Hue。
$ build/env/bin/supervisor
在浏览器访问:http://192.168.187.128:8888打开Hue的Web 界面并登陆
高能预警:如果左侧导航栏无法刷新出数据库信息的话可能是hive-site.xml关于hiveserver2的参数值没有配置好,比如hive.server2.thrift.bind.host配置的是localhost而不是主机名。
执行sql语句查询department表数据结果报错:Invalid time unit l
最后修改了hive-site.xml中hive.server2.long.polling.timeout的值为5000(默认为5000L)后重启hive,一切正常了。
配置成功。