java - 在同一个 ec2 上运行多个 tomcat
问题描述
我有 2 个 ENI 连接到我的 ec2 实例,这两个 ENI 都连接了一个弹性 IP。我还在我的 ec2 实例中安装了两个 tomcat 8,并将 server.xmls 更改如下
对于服务器 1
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
address="10.0.0.174"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
对于服务器 2
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8004" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1"
address="10.0.0.161"
connectionTimeout="20000"
redirectPort="8444" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
成功启动这两个实例后,我可以访问服务器 1(端口 8080)但不能访问服务器 2(端口 8081)。如果我关闭服务器 1 并更改服务器 2 中的默认端口,那么我可以访问服务器 2。我哪里出错了?
解决方案
推荐阅读
- mysql - INSERT ON DUPLICATE 多行出错
- ansible - Ansible 警告“字符串字段中的类型列表已转换为字符串类型”
- java - Spring Cloud:如果第一个请求失败,如何重试另一个服务
- node.js - 在节点项目上添加域
- javascript - 如何在javascript中为字符串的所有整数添加值?
- vue.js - 如何将 v-for 数据传递到 VueJS 中的模态
- python - Discord Bot 到 DM 特定角色
- node.js - 如何在 Typescript 中将 Express 查询参数类型绑定为字符串数组
- javascript - 根据当前日期的时间隐藏元素
- apache-kafka - Kafka - 代理是否有可能成为同一分区的领导者和追随者?