安装tomcat
下载apache-tomcat-8.5.34.tar.gz
并解压,tar -zxvf apache-tomcat-8.5.34.tar.gz
复制解压后的tomcat到安装目录,cp -r apache-tomcat-8.5.34 /opt/tomcat/tomcat8-geo3
/etc/systemd/system/
下新建service文件,tomcat8-geo3.service文件来管理Tomcat 进程
内容如下:
[Unit]
Description=Tomcat8-geo3
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/java/jdk1.8.0_181" "JRE_HOME=/usr/java/jdk1.8.0_181/jre"
PIDFile=/home/arcgis/tomcat/tomcat8-geo3/tomcat.pid
Environment=CATALINA_PID=/home/arcgis/tomcat/tomcat8-geo3/tomcat.pid
Environment=CATALINA_HOME=/home/arcgis/tomcat/tomcat8-geo3
Environment=CATALINA_BASE=/home/arcgis/tomcat/tomcat8-geo3
ExecStart=/home/arcgis/tomcat/tomcat8-geo3/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- [Unit] 表示这是基础信息
- Description 是描述
- After 是在那个服务后面启动,一般是网络服务启动后启动
- [Service] 表示这里是服务信息
- Type 是服务类型
- PIDFile 是服务的pid文件路径, 开启后,必须在tomcat的bin/catalina.sh中加入CATALINA_PID参数
- ExecStart 是启动服务的命令
- ExecReload 是重启服务的命令
- ExecStop 是停止服务的指令
- [Install] 表示这是是安装相关信息
- WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。
保存文件,刷新配置,让systemctl能识别
sudo systemctl daemon-reload
修改端口号
lsof -i:8085
查看端口是否被占用
开启端口
ufw allow 8085
启动tomcat,并查看tomcat状态:
systemctl start tomcat8-geo3
systemctl status tomcat8-geo3
允许开机自动启动:
sudo systemctl enable tomcat8-geo3
部署节点
配置tomcat
- 在tomcat/bin目录下,新建文件setenv.sh,内容如下,cluster的配置文件生成目录
JAVA_OPTS="-server -XX:PermSize=512M -XX:MaxPermSize=1024m -Xms1024M -Xmx1024M -XX:MaxNewSize=256m"
JAVA_OPTS="$JAVA_OPTS -DCLUSTER_CONFIG_DIR=/DataDisk/iserver/iserver_data_dir/cluster/clusterConfig3"
Geoserver版本及依赖
geoserver-2.16.0
geoserver-2.16-SNAPSHOT-jms-cluster-plugin
geoserver-2.16-SNAPSHOT-activeMQ-broker-plugin
部署
- 复制geoserver.war到tomcat的webapps下
- 复制activeMQ-broker-plugin.zip的war(双击zip文件时有时看不到war文件,但是war文件存在,直接解压即可)到geoserver.war同目录下,启动容器
- jms-cluster-plugin.zip解压,复制里面全部的jar包到geoserver的WEB-lib目录下,然后重启geoserver服务
- 删除activemqBroker-2.16-SNAPSHOT/WEB-INF/classes下的ApplicationContext.xml和standalone-broker.properties
- 在cluster目录下,修改cluster.properties,内容如下:
#
#Wed Mar 25 15:13:04 CST 2020
toggleSlave=true
topicName=VirtualTopic.geoserver
connection=enabled
brokerURL=tcp\://127.0.0.1\:61616
durable=true
xbeanURL=./broker.xml
toggleMaster=true
embeddedBroker=enabled
CLUSTER_CONFIG_DIR=/DataDisk/iserver/iserver_data_dir/cluster/clusterConfig3
embeddedBrokerProperties=embedded-broker.properties
connection.retry=10
instanceName=6bd9d6b2-1993-4020-ab91-02054e120040
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=false
# 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=false
## 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=nio://127.0.0.1:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600&jms.useAsyncSend=true&transport.daemon=true&trace=true
## 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>
- 重启
- 同上新建第二个节点,不同之处是tomcat/webapps下不需要再部署activeMQ-broker-plugin.zip,cluster配置文件的embedded-broker.properties中的
activemq.transportConnectors.server.uri=nio://127.0.0.1:61616......
的端口要不同于已存在的节点设置的端口,即如果已经有了61616就应该设置其他不用于61616的端口 - 重启,geoserver界面配置
配置nginx
# geoserver 集群端口
upstream geoserverCluster {
ip_hash; # 支持session
server localhost:8083;
server localhost:8084;
server localhost:8085;
}
server {
listen 80;
server_name localhost;
# 用于访问geoserver
location ^~ /geoserver/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_pass http://geoserverCluster/geoserver/;
}
}
nginx -t
检查nginx配置脚本是否有错
nginx -s reload
重新加载脚本