Geoserver JMS Cluster modules 共享數(shù)據(jù)目錄的集群同步

主要參考文檔鏈接:https://geoserver.geo-solutions.it/edu/en/index.html

Geoserver使用多個節(jié)點集群時,使用共享目錄來存儲數(shù)據(jù)最為方便,而各個節(jié)點修改geoserver配置如數(shù)據(jù)存儲、圖層、樣式時,其他節(jié)點無法自動同步導致新的配置無法正常使用,舊的做法是在其他每個節(jié)點的服務器狀態(tài)里點擊配置和目錄的自動載入,很不方便,所以嘗試用JMS Cluster modules擴展來解決配置同步問題。

參考了http://www.itdecent.cn/p/c1630bcc1920,但按照步驟缺少了詳細配置,且無法適用于共享目錄,所以按geo-solutions上的教程并不斷嘗試最后才成功。

準備擴展

https://build.geoserver.org/geoserver/按geoserver的對應版本,在community下找到activeMQ-broker-plugin.zip和jms-cluster-plugin.zip

把jms-cluster-plugin.zip里的jar包全部復制到geoserver的WEB-lib目錄下,把activeMQ-broker-plugin.zip解壓得到的activemqBroker-x-SNAPSHOT.war包放到geoserver.war包同級目錄下

節(jié)點讀取不同配置目錄

集群各個節(jié)點同步需要每個節(jié)點配置不同的實例名等,配置文件需要多套,按文檔所說,在應用容器上添加JAVA_OPTS參數(shù)CLUSTER_CONFIG_DIR指定不同的配置文件夾,例如tomcat在/bin/catalina.sh(linux)和catalina.bat(windows)文件里找到JAVA_OPTS=“$JAVA_OPTS $JSSE_OPTS",在后面添加"JAVA_OPTS=%JAVA_OPTS% -DCLUSTER_CONFIG_DIR=geoserver共享數(shù)據(jù)文件目錄/data/cluster/clusterConfig1”,clusterConfig文件夾取不同名稱來存放各個節(jié)點配置。

詳細配置

重啟geoserver所在容器,啟動成功時會自動在該節(jié)點配置的CLUSTER_CONFIG_DIR目錄下創(chuàng)建cluster.properties和embedded-broker.properties兩個文件,而activemqBroker-x-SNAPSHOT.war里/WEB-INF/classes下有兩個配置文件standalone-broker.properties和applicationContext.xml,其中standalone-broker.properties和之前說的embedded-broker.properties很相似,我嘗試了多次更改這兩個文件來配置activemq一直未成功,并且按官網(wǎng)說的配置獨立activemq時需要更改此配置,而集群使用共享目錄和配置的方式應該不需要這個,并且不管如何配置一直啟動不成功,索性直接刪除這兩個文件,事實證明是可行的。
現(xiàn)在geoserver.war和activemqBroker-x-SNAPSHOT.war內(nèi)無需要更改的配置了,重點就是CLUSTER_CONFIG_DIR目錄下的cluster.properties和embedded-broker.properties,同時在此目錄下增加broker.xml,嘗試了多次,現(xiàn)在直接上成功的配置:

cluster.properties:

toggleSlave=true

topicName=VirtualTopic.geoserver

connection=enabled

brokerURL=tcp\://{本節(jié)點IP}\:61616

durable=false

xbeanURL=./broker.xml

toggleMaster=true

embeddedBroker=enabled

CLUSTER_CONFIG_DIR=/{共享數(shù)據(jù)目錄}/data/cluster/clusterConfig1{四個節(jié)點,可區(qū)分為1-4}

embeddedBrokerProperties=embedded-broker.properties

connection.retry=3

instanceName={隨機數(shù)或指定的不同實例名}

readOnly=disabled

group=geoserver-cluster

connection.maxwait=10000

embedded-broker.properties:

## JMX settings (can be overridden by env vars)
## For more information, see: http://activemq.apache.org/jmx.html
# enable/disable broker jmx
activemq.jmx.useJmx=true
# set the JMX connector port
activemq.jmx.port=1098
# set the JMX connector host
activemq.jmx.host=localhost
# enable the JMX connector
activemq.jmx.createConnector=true

## broker settings
# set the base path of the temporary broker dir
# this is also used as persistence base dir  
activemq.base=./

## configuring the embedded broker
# connects the server via native I/O socket to the local network broadcast using an automatic assigned port 
# maximumConnections and wireFormat.maxFrameSize are added to avoid ddos attacks
activemq.transportConnectors.server.uri=tcp:// {本節(jié)點IP}:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600&jms.useAsyncSend=true&transport.daemon=true&trace=false

## the broker performs discovery using the following protocol:
# multicast on default network
activemq.transportConnectors.server.discoveryURI=multicast://224.1.1.3:6255

## persistence settings and system usage
## The systemUsage controls the maximum amount of space the broker will 
## use before slowing down producers. 
## For more information, see: http://activemq.apache.org/producer-flow-control.html
# enable/disable persistence
activemq.broker.persistent=true
# heap memory usage
activemq.broker.systemUsage.memoryUsage=128 mb
# disk space memory usage
activemq.broker.systemUsage.storeUsage=1 gb
# temp disk space memory usage
activemq.broker.systemUsage.tempUsage=128 mb

broker.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--DOCTYPE beans PUBLIC "-//ACTIVEMQ//DTD//EN" "http://activemq.org/dtd/activemq.dtd" -->

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/jms
                           http://www.springframework.org/schema/jms/spring-jms.xsd
                           http://activemq.apache.org/schema/core
                           http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration 
        file -->
    <bean id="activemq.propertyPlaceholderConfigurer"
        class="org.geoserver.cluster.impl.utils.JMSPropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="searchSystemEnvironment" value="true" />
        <property name="ignoreUnresolvablePlaceholders" value="false" />
        <property name="ignoreResourceNotFound" value="true" />
        <constructor-arg index="0" type="Resource">
            <value>embedded-broker.properties</value>
        </constructor-arg>
        <constructor-arg index="1" type="JMSConfiguration"
            ref="JMSConfiguration" />

    </bean>

    <broker id="broker" persistent="${activemq.broker.persistent}"
        useJmx="${activemq.jmx.useJmx}" xmlns="http://activemq.apache.org/schema/core"
        dataDirectory="${activemq.base}" tmpDataDirectory="${activemq.base}/tmp"
        startAsync="false" start="false" brokerName="${instanceName}">

        <!-- The managementContext is used to configure how ActiveMQ is exposed 
            in JMX. By default, ActiveMQ uses the MBean server that is started by the 
            JVM. For more information, see: http://activemq.apache.org/jmx.html -->
        <managementContext>
            <managementContext createConnector="${activemq.jmx.createConnector}"
                connectorPort="${activemq.jmx.port}" connectorHost="${activemq.jmx.host}" />
        </managementContext>

        <!--destinationInterceptors>
            <virtualDestinationInterceptor>
                <virtualDestinations>
                    <virtualTopic name=">" prefix="Consumer.*.VirtualTopic."
                        selectorAware="false" />
                </virtualDestinations>
            </virtualDestinationInterceptor>
        </destinationInterceptors-->

        <!-- Configure message persistence for the broker. The default persistence 
            mechanism is the KahaDB store (identified by the kahaDB tag). For more information, 
            see: http://activemq.apache.org/persistence.html -->
        <amq:persistenceAdapter>

            <kahaDB directory="${activemq.base}/kahadb"
                lockKeepAlivePeriod="0" />

            <!-- <jdbcPersistenceAdapter dataDirectory="activemq-data" dataSource="#postgres-ds" 
                lockKeepAlivePeriod="0" /> -->
        </amq:persistenceAdapter>


        <!-- The systemUsage controls the maximum amount of space the broker will 
            use before slowing down producers. For more information, see: http://activemq.apache.org/producer-flow-control.html -->
        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="${activemq.broker.systemUsage.memoryUsage}" />
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="${activemq.broker.systemUsage.storeUsage}" />
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="${activemq.broker.systemUsage.tempUsage}" />
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <!-- The transport connectors expose ActiveMQ over a given protocol to 
            clients and other brokers. For more information, see: http://activemq.apache.org/configuring-transports.html -->
        <transportConnectors>
            <transportConnector name="openwire"
                uri="${activemq.transportConnectors.server.uri}" discoveryUri="${activemq.transportConnectors.server.discoveryURI}" />
        </transportConnectors>
        <networkConnectors xmlns="http://activemq.apache.org/schema/core">
            <networkConnector
                uri="${activemq.transportConnectors.server.discoveryURI}" />
        </networkConnectors>

        <!-- destroy the spring context on shutdown to stop jetty -->
        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

    </broker>

    <!-- This xbean configuration file supports all the standard spring xml 
        configuration options -->

    <!-- <bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource"> -->
    <!-- <property name="serverName" value="localhost" /> -->
    <!-- <property name="databaseName" value="activemq" /> -->
    <!-- <property name="portNumber" value="5432" /> -->
    <!-- <property name="user" value="postgres" /> -->
    <!-- <property name="password" value="postgres" /> -->
    <!-- <property name="dataSourceName" value="postgres" /> -->
    <!-- <property name="initialConnections" value="1" /> -->
    <!-- <property name="maxConnections" value="30" /> -->
    <!-- </bean> -->

    <!-- Oracle DataSource Sample Setup -->
    <!-- <bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource" 
        destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> 
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:AMQDB"/> <property 
        name="username" value="scott"/> <property name="password" value="tiger"/> 
        <property name="poolPreparedStatements" value="true"/> </bean> -->

</beans>

問題1:embedded-broker.properties的discoveryURI配置,在本機測試時直接使用multicast://default是可以建立連接的,但是在線上失效,后來采用組播地址段224.0.1.0~238.255.255.255(全網(wǎng)范圍內(nèi)有效):
問題2:embedded-broker.properties的activemq.transportConnectors.server.uri設置為127.0.0.1后建立連接失敗,設置為節(jié)點IP后成功。

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容