config.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. .. _gwc_config:
  2. Configuration
  3. =============
  4. GeoWebCache is automatically configured for use with GeoServer using the most common options, with no setup required. All communication between GeoServer and GeoWebCache happens by passing messages inside the JVM.
  5. By default, all layers served by GeoServer will be known to GeoWebCache. See the :ref:`gwc_webadmin_layers` page to test the configuration.
  6. .. note:: Version 2.2.0 of GeoServer introduced changes to the configuration of the integrated GeoWebCache.
  7. Integrated user interface
  8. -------------------------
  9. GeoWebCache has a full integrated web-based configuration. See the :ref:`gwc_webadmin` section in the :ref:`web_admin`.
  10. Determining tiled layers
  11. ------------------------
  12. In versions of GeoServer prior to 2.2.0, the GeoWebCache integration was done in a such way that every GeoServer layer and layer group was forced to have an associated GeoWebCache tile layer. In addition, every such tile layer was forcedly published in the EPSG:900913 and EPSG:4326 gridsets with PNG and JPEG output formats.
  13. It is possible to selectively turn caching on or off for any layer served through GeoServer. This setting can be configured in the :ref:`gwc_webadmin_layers` section of the :ref:`web_admin`.
  14. Configuration files
  15. -------------------
  16. It is possible to configure most aspects of cached layers through the :ref:`gwc_webadmin` section in the :ref:`web_admin` or the :ref:`gwc_rest`.
  17. GeoWebCache keeps the configuration for each GeoServer tiled layer separately, inside the :file:`<data_dir>/gwc-layers/` directory. There is one XML file for each tile layer. These files contain a different syntax from the ``<wmsLayer>`` syntax in the standalone version and are *not* meant to be edited by hand. Instead you can configure tile layers on the :ref:`gwc_webadmin_layers` page or through the :ref:`gwc_rest`.
  18. Configuration for the defined gridsets is saved in :file:`<data_dir>/gwc/geowebcache.xml`` so that the integrated GeoWebCache can continue to serve externally-defined tile layers from WMS services outside GeoServer.
  19. If upgrading from a version prior to 2.2.0, a migration process is run which creates a tile layer configuration for all the available layers and layer groups in GeoServer with the old defaults. From that point on, you should configure the tile layers on the :ref:`gwc_webadmin_layers` page.
  20. Changing the cache directory
  21. ----------------------------
  22. GeoWebCache will automatically store cached tiles in a ``gwc`` directory inside your GeoServer data directory. To set a different directory, stop GeoServer (if it is running) and add the following code to your GeoServer :file:`web.xml` file (located in the :file:`WEB-INF` directory):
  23. .. code-block:: xml
  24. <context-param>
  25. <param-name>GEOWEBCACHE_CACHE_DIR</param-name>
  26. <param-value>C:\temp</param-value>
  27. </context-param>
  28. Change the path inside ``<param-value>`` to the desired cache path (such as :file:`C:\\temp` or :file:`/tmp`). Restart GeoServer when done.
  29. .. note:: Make sure GeoServer has write access in this directory.
  30. GeoWebCache with multiple GeoServer instances
  31. ---------------------------------------------
  32. For stability reasons, it is not recommended to use the embedded GeoWebCache with multiple GeoServer instances. If you want to configure GeoWebCache as a front-end for multiple instances of GeoServer, we recommend using the `standalone GeoWebCache <http://geowebcache.org>`_.
  33. .. _gwc_data_security:
  34. GeoServer Data Security
  35. -----------------------
  36. GWC Data Security is an option that can be turned on and turned off through the :ref:`gwc_webadmin_defaults` page. By default it is turned off.
  37. When turned on, the embedded GWC will do a data security check before calling GeoWebCache, i.e. verify whether the user actually has access to the layer, and reject the request if this is not the case.
  38. In the case of WMS-C requests, there is also limited support for data access limit filters, only with respect to geographic boundaries (all other types of data access limits will be ignored).
  39. The embedded GWC will reject requests for which the requested bounding box is (partly) inaccessible. It is only possible to request a tile within a bounding box that is fully accessible.
  40. This behaviour is different from the regular WMS, which will filter the data before serving it.
  41. However, if the integrated WMS/WMS-C is used, the request will be forwarded back to WMS and give the desired result.
  42. When using the default GeoServer security system, rules cannot combine data security with service security. However, when using a security subsystem it may be possible
  43. to make such particular combinations. In this case the WMS-C service inherits all security rules from the regular WMS service; while all other GWC services will get their security
  44. from rules associated with the 'GWC' service itself.
  45. Configuring In Memory Caching
  46. ------------------------------
  47. GWC In Memory Caching is a new feature which allows to cache GWC tiles in memory reducing their access time. User can also choose to avoid to store the files on the disk if needed.
  48. For enabling/disabling these features the user may see the related section on the TileCaching :ref:`gwc_webadmin_defaults` page.
  49. Actually there are only two Caching methods:
  50. * Guava Caching
  51. * Hazelcast Caching
  52. Guava Cache
  53. +++++++++++
  54. `Guava <https://code.google.com/p/guava-libraries/wiki/CachesExplained>`_ Cache provides a local in-memory cache to use for a single GeoServer instance. For configuring Guava Caching the user must only edit the configuration parameters in the *Caching Defaults* page.
  55. Hazelcast Cache
  56. +++++++++++++++
  57. `Hazelcast <https://docs.hazelcast.com/hazelcast/5.3/configuration/configuring-declaratively>`_ is an open-source API for distributed structures like clusters. GWC supports this API for creating a distributed in memory cache.
  58. At the time of writing, Hazelcast requires the installation of the *gs-gwc-distributed* plugin in the `WEB_INF/lib` directory of your geoserver application. This plugin can be found at the following `link <https://build.geoserver.org/geoserver/main/community-latest/>`_.
  59. There are 2 ways for configuring distributed caching in GWC:
  60. * Using an XML file called *hazelcast.xml*. This file must be located in a directory indicated by the JVM parameter **hazelcast.config.dir**
  61. * Directly, by configuring a bean inside the GeoServer application context
  62. Both the 2 configurations should define the following parameters:
  63. #. The Hazelcast configuration requires a Map object with name *CacheProviderMap*
  64. #. Map eviction policy must be *LRU* or *LFU*
  65. #. Map configuration must have a fixed size defined in Mb
  66. #. Map configuration must have **USED_HEAP_SIZE** as *MaxSizePolicy*
  67. .. warning:: Be careful that all the cluster instances have the same configuration, because different configurations may result in incorrect Hazelcast behaviour.
  68. .. warning:: In order to avoid missing tiles, the cluster instances should access the same data.
  69. Configuration with *hazelcast.xml*
  70. ``````````````````````````````````
  71. Here can be found an example file:
  72. .. code-block:: xml
  73. <hazelcast xmlns="http://www.hazelcast.com/schema/config"
  74. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  75. xsi:schemaLocation="http://www.hazelcast.com/schema/config
  76. https://hazelcast.com/schema/config/hazelcast-config-5.3.xsd">
  77. <cluster-name>gsCacheCluster</cluster-name>
  78. <network>
  79. <!--
  80. Typical usage: multicast enabled with port auto-increment enabled
  81. or tcp-ip enabled with port auto-increment disabled. Note that you
  82. must choose between multicast and tcp-ip. Another option could be
  83. aws, but will not be described here.
  84. -->
  85. <port auto-increment="false">5701</port>
  86. <join>
  87. <multicast enabled="false">
  88. <multicast-group>224.2.2.3</multicast-group>
  89. <multicast-port>54327</multicast-port>
  90. </multicast>
  91. <tcp-ip enabled="true">
  92. <interface>192.168.1.32</interface>
  93. <interface>192.168.1.110</interface>
  94. </tcp-ip>
  95. </join>
  96. </network>
  97. <map name="CacheProviderMap">
  98. <eviction eviction-policy="LRU" max-size-policy="USED_HEAP_SIZE" size="16" />
  99. </map>
  100. </hazelcast>
  101. Configuration with ApplicationContext
  102. `````````````````````````````````````
  103. For configuring caching directly from the GeoServer application context, the user must edit the file *geowebcache-distributed.xml* inside the *gs-gwc* jar file. More informations about using
  104. Spring with Hazelcast can be found in the `Hazelcast related documentation <http://docs.hazelcast.org/docs/3.3/manual/html/springintegration.html>`_. The modified application context is presented
  105. below:
  106. .. code-block:: xml
  107. <hz:hazelcast id="instance1">
  108. <hz:config>
  109. <hz:group name="dev" password="password" />
  110. <hz:network port="5701" port-auto-increment="true">
  111. <hz:join>
  112. <hz:multicast enabled="true" multicast-group="224.2.2.3"
  113. multicast-port="54327" />
  114. <hz:tcp-ip enabled="false">
  115. <hz:members>10.10.1.2, 10.10.1.3</hz:members>
  116. </hz:tcp-ip>
  117. </hz:join>
  118. </hz:network>
  119. <hz:map name="CacheProviderMap" max-size="16" eviction-policy="LRU"
  120. max-size-policy="USED_HEAP_SIZE" />
  121. </hz:config>
  122. </hz:hazelcast>
  123. <bean id="HazelCastLoader1"
  124. class="org.geowebcache.storage.blobstore.memory.distributed.HazelcastLoader">
  125. <property name="instance" ref="instance1" />
  126. </bean>
  127. <bean id="HazelCastCacheProvider1"
  128. class="org.geowebcache.storage.blobstore.memory.distributed.HazelcastCacheProvider">
  129. <constructor-arg ref="HazelCastLoader1" />
  130. </bean>
  131. Optional configuration parameters
  132. ``````````````````````````````````
  133. In this section are described other available configuration parameters to configure:
  134. * Cache expiration time:
  135. .. code-block:: xml
  136. <map name="CacheProviderMap">
  137. ...
  138. <time-to-live-seconds>0</time-to-live-seconds>
  139. <max-idle-seconds>0</max-idle-seconds>
  140. </map>
  141. Where *time-to-live-seconds* indicates how many seconds an entry can stay in cache and *max-idle-seconds* indicates how many seconds an entry may be not accessed before being evicted.
  142. * Near Cache.
  143. .. code-block:: xml
  144. <map name="CacheProviderMap">
  145. ...
  146. <near-cache>
  147. <!--
  148. Same configuration parameters of the Hazelcast Map. Note that size indicates the maximum number of
  149. entries in the near cache. A value of Integer.MAX_VALUE indicates no limit on the maximum
  150. size.
  151. -->
  152. <time-to-live-seconds>0</time-to-live-seconds>
  153. <max-idle-seconds>60</max-idle-seconds>
  154. <eviction eviction-policy="LRU" size="5000" />
  155. <!--
  156. Indicates if a cached entry can be evicted if the same value is modified in the Hazelcast Map. Default is true.
  157. -->
  158. <invalidate-on-change>true</invalidate-on-change>
  159. <!--
  160. Indicates if local entries must be cached. Default is false.
  161. -->
  162. <cache-local-entries>false</cache-local-entries>
  163. </near-cache>
  164. </map>
  165. Near Cache is a local cache for each cluster instance which is used for caching entries in the other cluster instances. This behaviour avoids requesting those entries each time by executing a remote call. This feature could be helpful in order to improve Hazelcast Cache performance.
  166. .. note:: A value of *max-size* bigger or equal to Integer.MAX_VALUE cannot be used in order to avoid an uncontrollable growth of the cache size.