geoserver集群部署
- 环境准备
- 系统准备
- 挂载nfs
- 软件准备
- 插件准备
- 配置jdk
- 安装tomcat
- 部署geoserver
- 配置geoserver数据存储目录
- geoserver配置jms
- 安装mq插件
- 修改tomcat 启动文件
- geoserver配置jms
- 新建broker.xml放入cluster文件内容如下(三个节点均要新建,内容相同)
- 集群配置
- 测试数据同步
- 配置tomcat 允许跨域
- 配置nginx代理
环境准备
系统准备
操作系统 | IP | jdk | 服务版本 | 角色 |
CentOS7 | 10.139.164.112 | jdk1.8 | nfs | |
CentOS7 | 10.139.164.102 | jdk1.8 | geoser2.20 | slave |
CentOS7 | 10.139.164.101 | jdk1.8 | geoser2.20 | master |
挂载nfs
安装nfs客户端
两个机器都挂载
[root@geo2 ~]# yum -y install nfs-utils
上次元数据过期检查:0:19:28 前,执行于 2023年08月10日 星期四 09时11分02秒。
软件包 nfs-utils-1:2.5.1-5.ky10.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
挂载到相同目录
创建挂载目录
[root@geo1 ~]# mkdir /opt/nfs_data
将NFS挂载到此目录
[root@geo1 ~]# mount -o rw,nosuid,fg,hard,intr 10.139.164.112:/opt/basedata/nfs_data /opt/nfs_data
将挂载添加到配置文件
[root@geo1 ~]# vim /etc/fstab
10.139.164.112:/opt/basedata/nfs_data /opt/nfs_data nfs defaults 0 0
软件准备
- jdk1.8
- geoserver 2.20
插件准备
插件下载地址:https://build.geoserver.org/geoserver/2.20.x/community-2022-09-01/ 根据版本选择下载
- geoserver-2.20-SNAPSHOT-activeMQ-broker-plugin.zip
- geoserver-2.20-SNAPSHOT-jms-cluster-plugin.zip
配置jdk
[root@localhost local]# tar -zxvf jdk-8u151-linux-x64.tar.gz
[root@localhost local]#mv jdk1.8.0_151 jdk
[root@localhost local]#cat >>/etc/profile<< EOF
JAVA_HOME=/usr/local/jdk
export PATH=\$JAVA_HOME/bin:\$PATH
EOF
[root@localhost local]#source /etc/profile
安装tomcat
tar -zxvf apache-tomcat-9.0.56.tar.gz
mv apache-tomcat-9.0.56 tomcat
部署geoserver
上传geoserver的war包到tomcat的webapps目录。然后启动tomcat.war包会自动解压
配置geoserver数据存储目录
- 在每个geoserver的WEB-INF/web.xml中添加这段:
<context-param>
<param-name>GEOSERVER_DATA_DIR</param-name>
<param-value>/opt/nfs_data/geoserver_data/data</param-value>
</context-param>
<context-param>
<param-name>GEOWEBCACHE_CACHE_DIR</param-name>
<param-value>/opt/nfs_data/geoserver_data/geowebcache</param-value>
</context-param>
- 创建数据目录及缓存目录
mkdir -p /opt/nfs_data/geoserver_data/data
mkdir -p /opt/nfs_data/geoserver_data/geowebcache
geoserver配置jms
解压jms的zip包
将解压后的所有.jar包复制到tomcat中webapps/geoserver/WEB-INF/lib目录下
重启tomcat,等待geoserver启动成功
访问ip:8080/geoserver
默认的账号密码为 admin geoserver
各节点都需要完成上述操作
安装mq插件
将geoserver-2.18-SNAPSHOT-activeMQ-broker-plugin.zip解压
将其中的war包上传到主节点的tomcat中
启动tomcat后自动解压,将/usr/local/tomcat/apache-tomcat-9.0.37/webapps/activemqBroker-2.18-SNAPSHOT/WEB-INF/classes目录下的 standalone-broker.properties和applicationContext.xml删除
重启tomcat
以上操作在一个tomcat中完成即可
修改tomcat 启动文件
修改tomcat bin目录下启动文件catalina.sh,指定数据文件位置,所有geoserve节点都要执行
找到下面的这段代码
JAVA_OPTS=“$JAVA_OPTS $JSSE_OPTS"
修改为:
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -DCLUSTER_CONFIG_DIR=/opt/nfs_data/geoserver_data/cluster/clusterConfig1"
其中的/clusterConfig1文件需要进行区分,如我这里master为/clusterConfig1另外一个节点就是/clusterConfig2
geoserver配置jms
解压jms的zip包
将解压后的所有.jar包复制到tomcat中webapps/geoserver/WEB-INF/lib目录下
重启tomcat,等待geoserver启动成功
启动成功后会在上述脚本设置的目录中生产对应的集群配置文件
在/opt/nfs_data/geoserver_data/cluster/clusterConfig1目录下生成cluster目录
其中包含以两个文件cluster.properties、embedded-broker.properties
新建broker.xml放入cluster文件内容如下(三个节点均要新建,内容相同)
在/opt/nfs_data/geoserver_data/cluster/clusterConfig1(此目录为上面脚本中指定的目录)目录下新建broker.xml文件内容如下(三个节点均要新建,内容相同)
vim 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>
集群配置
集群中只有一个节点是主节点,在这个节点新增数据,别的节点会根据activeMQ进行同步
修改各节点以下文件(文件路径为geoserver 数据目录下cluster目录中)
- cluster.properties
- embedded-broker.properties
修改embedded-broker.properties 修改下面行
activemq.jmx.host= #本机ip
activemq.transportConnectors.server.uri=ip:端口
修改cluster.properties配置文件 只改brokerURL,其他参数默认
#Thu Aug 10 10:53:05 CST 2023
toggleSlave=true
topicName=VirtualTopic.geoserver
connection=disabled
brokerURL=tcp\://10.139.164.101\:61616
durable=true
xbeanURL=./broker.xml
toggleMaster=true
embeddedBroker=enabled
CLUSTER_CONFIG_DIR=/opt/nfs_data/geoserver_data/cluster/clusterConfig2
embeddedBrokerProperties=embedded-broker.properties
connection.retry=10
instanceName=1a8bf8ee-f364-4e38-8812-4c8a9665449f
readOnly=disabled
group=geoserver-cluster
connection.maxwait=500
所有节点都要配置上述配置文件,配置文件基本相同。
重新启动各节点tomcat
访问geoserver 登录后可以看到cluster信息
此时有个问题,由于geoserver的配置是放在内存中的,所以修改配置信息时,无法进行同步
需要手动在从节点操作重读配置
测试数据同步
- 主节点创建工作空间
从节点查看数据是否同步成功
同步成功,如果遇到数据未能同步的,需要在服务器状态页面手动重新加载配置文件
配置tomcat 允许跨域
在tomcat安装目录里 找到conf文件夹。编辑web.xml,在大约4729行添加下面内容
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
配置nginx代理
upstream backend {
ip_hash;
server ip:8080;
server ip:8080;
}
server {
listen 9090;
server_name localhost;
#charset koi8-r;
client_max_body_size 1024m;
#access_log logs/host.access.log main;
location ^~ /geoserver/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
# 解决504错误,单位:秒
proxy_send_timeout 900s;
proxy_read_timeout 900s;
send_timeout 900s;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http:// $scheme://;
proxy_pass http://backend/geoserver/;
index index.html index.htm index.jsp;
}
}