美文网首页开源
Geoserver JMS Cluster modules 共享

Geoserver JMS Cluster modules 共享

作者: 军曹_5868 | 来源:发表于2019-04-25 16:57 被阅读9次

    主要参考文档链接:https://geoserver.geo-solutions.it/edu/en/index.html

    Geoserver使用多个节点集群时,使用共享目录来存储数据最为方便,而各个节点修改geoserver配置如数据存储、图层、样式时,其他节点无法自动同步导致新的配置无法正常使用,旧的做法是在其他每个节点的服务器状态里点击配置和目录的自动载入,很不方便,所以尝试用JMS Cluster modules扩展来解决配置同步问题。

    参考了https://www.jianshu.com/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包同级目录下

    节点读取不同配置目录

    集群各个节点同步需要每个节点配置不同的实例名等,配置文件需要多套,按文档所说,在应用容器上添加JAVA_OPTS参数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共享数据文件目录/data/cluster/clusterConfig1”,clusterConfig文件夹取不同名称来存放各个节点配置。

    详细配置

    重启geoserver所在容器,启动成功时会自动在该节点配置的CLUSTER_CONFIG_DIR目录下创建cluster.properties和embedded-broker.properties两个文件,而activemqBroker-x-SNAPSHOT.war里/WEB-INF/classes下有两个配置文件standalone-broker.properties和applicationContext.xml,其中standalone-broker.properties和之前说的embedded-broker.properties很相似,我尝试了多次更改这两个文件来配置activemq一直未成功,并且按官网说的配置独立activemq时需要更改此配置,而集群使用共享目录和配置的方式应该不需要这个,并且不管如何配置一直启动不成功,索性直接删除这两个文件,事实证明是可行的。
    现在geoserver.war和activemqBroker-x-SNAPSHOT.war内无需要更改的配置了,重点就是CLUSTER_CONFIG_DIR目录下的cluster.properties和embedded-broker.properties,同时在此目录下增加broker.xml,尝试了多次,现在直接上成功的配置:

    cluster.properties:

    toggleSlave=true
    
    topicName=VirtualTopic.geoserver
    
    connection=enabled
    
    brokerURL=tcp\://{本节点IP}\:61616
    
    durable=false
    
    xbeanURL=./broker.xml
    
    toggleMaster=true
    
    embeddedBroker=enabled
    
    CLUSTER_CONFIG_DIR=/{共享数据目录}/data/cluster/clusterConfig1{四个节点,可区分为1-4}
    
    embeddedBrokerProperties=embedded-broker.properties
    
    connection.retry=3
    
    instanceName={随机数或指定的不同实例名}
    
    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:// {本节点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(全网范围内有效):
    问题2:embedded-broker.properties的activemq.transportConnectors.server.uri设置为127.0.0.1后建立连接失败,设置为节点IP后成功。

    相关文章

      网友评论

        本文标题:Geoserver JMS Cluster modules 共享

        本文链接:https://www.haomeiwen.com/subject/kyyzgqtx.html