配置

geoWebcache自动配置为使用geoserver,使用最常见的选项,不需要设置。geoserver和geoWebcache之间的所有通信都是通过在JVM中传递消息来实现的。

默认情况下,geoWebcache将知道geoServer提供的所有层。查看 瓦片层 要测试配置的页。

备注

geoserver的2.2.0版引入了对集成geoWebcache配置的更改。

集成用户界面

geoWebcache具有完全集成的基于Web的配置。查看 geoWebCache设置 节中 Web管理界面 .

确定瓦片层

在2.2.0之前版本的geoServer中,geoWebCache集成的完成方式是强制每个geoServer层和层组具有关联的geoWebCache瓦片层。此外,每一个这样的贴片层都被强制发布在epsg:900913和epsg:4326网格集中,输出格式为png和jpeg。

可以有选择地为通过地理服务器提供服务的任何层打开或关闭缓存。此设置可以在 瓦片层 剖面图 Web管理界面 .

配置文件

可以通过 geoWebCache设置 节中 Web管理界面geoWebcache REST API .

geoWebCache在 <data_dir>/gwc-layers/ 目录。每个瓦片层有一个XML文件。这些文件包含不同于 <wmsLayer> 在独立版本中的语法 not 手工编辑的。相反,您可以在 瓦片层 翻页或翻页 geoWebcache REST API .

定义网格集的配置保存在 <data_dir>/gwc/geowebcache.xml `这样,集成的geoWebcache可以继续为来自geoserver外部的WMS服务的外部定义的瓦片层提供服务。

如果从2.2.0之前的版本升级,则将运行迁移过程,该过程将使用旧的默认值为geoserver中的所有可用图层和图层组创建瓦片图层配置。从那时起,您应该在 瓦片层 页。

更改缓存目录

geoWebCache将自动在 gwc 地理服务器数据目录中的目录。若要设置其他目录,请停止geoserver(如果它正在运行),并将以下代码添加到geoserver中 web.xml 文件(位于 WEB-INF 目录):

<context-param>
   <param-name>GEOWEBCACHE_CACHE_DIR</param-name>
   <param-value>C:\temp</param-value>
</context-param>

更改内部路径 <param-value> 到所需的缓存路径(例如 C:\temp/tmp )。完成后重新启动geoserver。

备注

确保geoserver在此目录中具有写入权限。

具有多个地理服务器实例的geoWebCache

出于稳定性原因,不建议将嵌入式geoWebcache与多个geoServer实例一起使用。如果要将geoWebcache配置为多个geoServer实例的前端,建议使用 standalone GeoWebCache .

地理服务器数据安全

GWC数据安全是一个选项,可以通过 缓存默认值 第页。默认情况下,它是关闭的。

打开后,嵌入式GWC将在调用geoWebcache之前进行数据安全检查,即验证用户是否确实有权访问层,如果不是这样,则拒绝请求。在WMS-C请求的情况下,对数据访问限制过滤器的支持也有限,仅限于地理边界(将忽略所有其他类型的数据访问限制)。嵌入式GWC将拒绝请求边界框(部分)不可访问的请求。只能在完全可访问的边界框内请求瓦片。这种行为不同于常规的WMS,后者将在提供数据之前对其进行过滤。但是,如果使用集成的WMS/WMS-C,请求将被转发回WMS并给出所需的结果。

使用默认的geoserver安全系统时,规则不能将数据安全与服务安全结合起来。但是,在使用安全子系统时,可能会进行这种特殊的组合。在这种情况下,WMS-C服务从常规WMS服务继承所有安全规则;而所有其他GWC服务将从与“GWC”服务本身关联的规则获取其安全性。

配置内存缓存

GWC内存缓存是一项新功能,它允许在内存中缓存GWC块,从而缩短了它们的访问时间。如果需要,用户还可以选择避免将文件存储在磁盘上。要启用/禁用这些功能,用户可以查看有关瓦片的相关部分。 缓存默认值 页。

实际上,只有两种缓存方法:

  • 番石榴缓存

  • Hazelcast缓存

番石榴缓存

Guava 缓存提供用于单个地理服务器实例的本地内存缓存。对于配置guava缓存,用户只能在 缓存默认值 页。

Hazelcast缓存

Hazelcast 是一个针对分布式结构(如集群)的开源API。GWC支持此API来创建分布式内存缓存。在撰写本文时,Hazelcast需要安装 gs-gwc-distributed 插件中的 WEB_INF/lib directory of your geoserver application. This plugin can be found at the following link

在GWC中配置分布式缓存有两种方法:

  • 使用名为 hazelcast.xml .此文件必须位于由jvm参数指示的目录中 hazelcast.config.dir

  • 直接,通过在geoserver应用程序上下文中配置bean

这两种配置都应定义以下参数:

  1. Hazelcast配置需要具有名称的映射对象 CacheProviderMap

  2. 映射逐出策略必须为 LRULFU

  3. 映射配置必须具有以MB为单位定义的固定大小

  4. 映射配置必须具有 USED_HEAP_SIZE 作为 MaxSizePolicy

警告

请注意,所有集群实例都具有相同的配置,因为不同的配置可能导致不正确的Hazelcast行为。

警告

为了避免丢失数据块,集群实例应该访问相同的数据。

配置 hazelcast.xml

以下是一个示例文件:

<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-2.3.xsd"
                   xmlns="http://www.hazelcast.com/schema/config"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <group>
        <name>cacheCluster</name>
        <password>geoserverCache</password>
  </group>

  <network>
        <!--
                Typical usage: multicast enabled with port auto-increment enabled
                or tcp-ip enabled with port auto-increment disabled. Note that you
                must choose between multicast and tcp-ip. Another option could be
                aws, but will not be described here.

        -->
        <port auto-increment="false">5701</port>
                <join>
                         <multicast enabled="false">
                                <multicast-group>224.2.2.3</multicast-group>
                                <multicast-port>54327</multicast-port>
                        </multicast>
                        <tcp-ip enabled="true">
                                <interface>192.168.1.32</interface>
                                <interface>192.168.1.110</interface>
                        </tcp-ip>
                </join>
  </network>

  <map name="CacheProviderMap">
                <eviction-policy>LRU</eviction-policy>
                <max-size policy="USED_HEAP_SIZE">16</max-size>
  </map>

</hazelcast>

使用ApplicationContext配置

要直接从geoserver应用程序上下文配置缓存,用户必须编辑该文件 geowebcache-distributed.xml 里面 gs-gwc JAR文件。有关将弹簧与榛壳一起使用的更多信息,请参见 Hazelcast related documentation .修改后的应用程序上下文如下:

<hz:hazelcast id="instance1">
        <hz:config>
                <hz:group name="dev" password="password" />
                <hz:network port="5701" port-auto-increment="true">
                        <hz:join>
                                <hz:multicast enabled="true" multicast-group="224.2.2.3"
                                        multicast-port="54327" />
                        <hz:tcp-ip enabled="false">
                          <hz:members>10.10.1.2, 10.10.1.3</hz:members>
                        </hz:tcp-ip>
                        </hz:join>
                </hz:network>
                <hz:map name="CacheProviderMap" max-size="16" eviction-policy="LRU"
                        max-size-policy="USED_HEAP_SIZE" />
        </hz:config>
</hz:hazelcast>

<bean id="HazelCastLoader1"
        class="org.geowebcache.storage.blobstore.memory.distributed.HazelcastLoader">
        <property name="instance" ref="instance1" />
</bean>

<bean id="HazelCastCacheProvider1"
        class="org.geowebcache.storage.blobstore.memory.distributed.HazelcastCacheProvider">
        <constructor-arg ref="HazelCastLoader1" />
</bean>

可选配置参数

在本节中描述了要配置的其他可用配置参数:

  • 缓存过期时间:

    <map name="CacheProviderMap">
    ...
    
            <time-to-live-seconds>0</time-to-live-seconds>
            <max-idle-seconds>0</max-idle-seconds>
    
    </map>
    

    哪里 time-to-live-seconds 指示条目可以在缓存中停留的秒数, max-idle-seconds 指示条目在被逐出之前可能未被访问的秒数。

  • 靠近缓存。

    <map name="CacheProviderMap">
    ...
    <near-cache>
      <!--
            Same configuration parameters of the Hazelcast Map. Note that size indicates the maximum number of
            entries in the near cache. A value of Integer.MAX_VALUE indicates no limit on the maximum
            size.
      -->
      <max-size>5000</max-size>
      <time-to-live-seconds>0</time-to-live-seconds>
      <max-idle-seconds>60</max-idle-seconds>
      <eviction-policy>LRU</eviction-policy>
    
      <!--
            Indicates if a cached entry can be evicted if the same value is modified in the Hazelcast Map. Default is true.
      -->
      <invalidate-on-change>true</invalidate-on-change>
    
      <!--
            Indicates if local entries must be cached. Default is false.
      -->
      <cache-local-entries>false</cache-local-entries>
    </near-cache>
    
    </map>
    

    近缓存是每个集群实例的本地缓存,用于缓存其他集群实例中的条目。此行为通过执行远程调用避免每次请求这些条目。此功能有助于提高Hazelcast缓存性能。

    备注

    一个值 max-size 不能使用大于或等于integer.max_值以避免缓存大小的不可控制增长。