设为首页 加入收藏

TOP

GeoMesa-HBase部署实践
2019-02-12 01:46:28 】 浏览:1062
Tags:GeoMesa-HBase 部署 实践

关于HBase实验环境的搭建请参阅我的另一篇文章:

https://blog.csdn.net/xiaof22a/article/details/80213064


1. GeoMesa源代码编译

由于考虑到日后需要基于GeoMesa进行二次开发,所以本文采用的是编译GeoMesa源代码的方式,如果读者仅仅为了学习应用GeoMesa进行空间数据管理,可以直接从官方下载已经编译好的GeoMesa HBase工具包,最新版本为2.0: GitHub

下载最新版本(VERSION为你想使用的版本):

 git checkout tags/geomesa-$VERSION -b geomesa-$VERSION

定位到根目录,使用maven进行编译:

 mvn clean install -DskipTests

在编译过程中经常会出错或者无响应的情况,多重复几次就能成功。

编译成功后,GeoMesa for HBase的完整安装包位于geomesa-hbase\geomesa-hbase-dist\target目录下


2. 部署GeoMesa for HBase

默认情况下,GeoMesa启动过程中会读取所有HBase与Hadoop相关的环境变量来构建自己的CLASSPATH, 有GeoMesa相关的所有配置都可以在geomesa-hbase_2.11-$VERSION/conf/geomesa-env.sh中进行,或者你也可以在系统用户根目录下的.bashrc文件中进行配置,详细的配置信息读者可参阅官方文档:

http://www.geomesa.org/documentation/user/hbase/install.html

这里我们采用配置.bashrc文件的方式:

注意:官方文档中这一部分有个小错误,就是将GEOMESA_HBASE_HOME写成了GEOMESA_HOME!!!


然后进入到${GEOMESA_HBASE_HOME},运行:

$ bin/install-jai.sh
$ bin/install-jline.sh

GeoMesa使用HBase的自定义过滤器来执行CQL查询,为了允许GeoMesa使用过滤器,需要将${GEOMESA_HBASE_HOME}/dist/hbase/geomesa-hbase-distributed-runtime_2.11-2.0.0.jar拷贝到${HBase_HOME}/lib目录下。

注册Coprocessors:

Geomesa使用HBase提供的coprocessor工具将处理过程移动到服务器端运行来提高查询效率,最简单的注册方式就是直接修改hbase-site.xml,增加以下内容:

  <property>
    <name>hbase.coprocessor.user.region.classes</name>
    <value>org.locationtech.geomesa.hbase.coprocessor.GeoMesaCoprocessor</value>
  </property>
最后运行bin/geomesa-hbase configure初始化Geomesa

3. 测试

测试代码使用官方提供的示例程序:

$git clonehttps://github.com/geomesa/geomesa-tutorials.git

下载完成后进行编译:

$cd geomesa-tutorials
$ mvn clean install -pl geomesa-quickstart-hbase
编译成功后运行:
$ java -cp geomesa-tutorials-hbase-quickstart-2.1.0-SNAPSHOT.jar org.geomesa.example.hbase.HBaseQuickStart 
    --hbase.zookeepers master 
    --hbase.catalog geomesa_hbase

如果看到下面的输出证明运行成功:

这里有必要提一下GeoMesa的内置时空索引方法,通过查阅官方文档,可以看到GeoMesa提供了两类四种索引方法:

空间索引(Spatial Index, Z2/XZ2)

If the SimpleFeatureType has a Geometry-type attribute (Point, LineString, Polygon, etc), GeoMesa will create a spatial index on that attribute. If there is more than one Geometry-type attribute, the default one will be used. The default geometry is generally specified with a * prefix in the SimpleFeatureType string, and is the one returned by SimpleFeatureType.getGeometryDescriptor.

时空索引(Spatio-temporal Index, Z3/XZ3)

If the SimpleFeatureType has both a Geometry-type attribute and a Date attribute, GeoMesa will create a spatio-temporal index on those attributes. The Geometry-type attribute used is the same as for the spatial index, above. The Date attribute selected will be the first one declared, or can be set explicitly. See Setting the Indexed Date Attribute for details on setting the indexed date.

可见Z2/XZ2与Z3/XZ3最大区别在于在于是否将时间属性包含在索引中。

在HBase Shell中输入list查看运行结果,可以看到geomesa新建了5个表格,这里Z2/Z3指示了Geomesa的索引方式。

接着我们使用全日本地区的OSM数据集的建筑物图层(gis.osm_buildings_a_free_1)进行测试 (使用root用户

使用 geomesa-hbase ingest 命令导入shp数据:

geomesa-hbase ingest --catalog gis_osm_buildings_a_free_1 
	--feature-name gis_osm_buildings_a_free_1 
	--input-format shp 
	"/home/xiaofei/Downloads/Japan/gis.osm_buildings_a_free_1.shp"

运行结果如下,我们发现4,906,174条记录被插入到数据库中,耗时5分钟44秒,可见Geomesa数据导入功能的效率还是比较优秀的。


接着我们还是在HBase Shell中查看Schema,注意由于gis.osm_buildings_a_free_1没有时间属性,所以系统默认的构建xz2索引,也就是只使用经纬度构建GeoHash索引:


4. 整合GeoServer

将$GEOMESA_HBASE_HOME/dist/gs-plugins/geomesa-hbase-gs-plugin_2.11-$VERSION-install.tar.gz解压到WBE-INF/lib路径下;

由于geomesa-hbase-gs-plugin并不包含有Hadoop、HBase有关的依赖jar文件,所以需要手动将下图中的jar文件复制到WBE-INF/lib路径下;

启动Tomcat,然后访问http://master:8080/geoserver

在Stores页面中可以发现新增了HBase(Geomesa)数据源


将前面我面新导入的gis.osm_buildings_a_free_1(Catalog名称)发布为新图层:


然后就可以通过OpenLayers查看图层了:


上述就是GeoMesa for HBase的整个部署流程,在部署过程中会遇到各种各样的问题,希望读者朋友保持耐心,多参考网上相关资源,尤其是GeoMesa官方参考手册,一定可以成功搭建GeoMesa的开发环境。后面我会详细介绍GeoMesa的整体架构以及空间索引方法,也希望有兴趣的朋友可以多提意见,一起学习。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hbase连接异常,JAR包冲突解决攻略 下一篇hbase 修改表名 Java api(shell)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目