linux安装部署多个tomcat

你的名字 2022-02-28 09:28 440阅读 0赞

因公司节约成本,把两个项目迁移到一台linux服务器上,每个项目使用不同的端口,所以要部署多个tomcat解决。

创建文件夹放置tomcat

  1. mkdir /yearns
  2. cd yearns

下载tomcat

  1. wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.93/bin/apache-tomcat-7.0.93.tar.gz

解压tomcat并重命名

  1. tar xzvf apache-tomcat-7.0.93.tar.gz
  2. mv apache-tomcat-7.0.93 tomcat-jinbaili
  3. tar xzvf apache-tomcat-7.0.93.tar.gz
  4. mv apache-tomcat-7.0.93 tomcat-transport

在这里插入图片描述
修改 /etc/profile,末尾加入以下配置文件

  1. #第一个Tomcat
  2. CATALINA_BASE=/yearns/tomcat-jinbaili
  3. CATALINA_HOME=/yearns/tomcat-jinbaili
  4. export CATALINA_BASE CATALINA_HOME
  5. #第二个Tomcat
  6. CATALINA_2_BASE=/yearns/tomcat-transport
  7. CATALINA_2_HOME=/yearns/tomcat-transport
  8. export CATALINA_2_BASE CATALINA_2_HOME
  9. #第一个Tomcat路径
  10. TOMCAT_HOME=/yearns/tomcat-jinbaili
  11. export TOMCAT_HOME
  12. #第二个Tomcat路径
  13. TOMCAT_2_HOME=/yearns/tomcat-transport
  14. export TOMCAT_2_HOME

执行以下命令,保存生效

  1. source /etc/profile

分别修改两个tomcat的端口信息
tomcat-jinbaili的端口7775,的server.xml内容:

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- Note: A "Server" is not itself a "Container", so you may not
  17. define subcomponents such as "Valves" at this level.
  18. Documentation at /docs/config/server.html
  19. -->
  20. <Server port="8005" shutdown="SHUTDOWN">
  21. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  22. <!-- Security listener. Documentation at /docs/config/listeners.html
  23. <Listener className="org.apache.catalina.security.SecurityListener" />
  24. -->
  25. <!--APR library loader. Documentation at /docs/apr.html -->
  26. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  27. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  28. <Listener className="org.apache.catalina.core.JasperListener" />
  29. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  30. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  31. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  32. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  33. <!-- Global JNDI resources
  34. Documentation at /docs/jndi-resources-howto.html
  35. -->
  36. <GlobalNamingResources>
  37. <!-- Editable user database that can also be used by
  38. UserDatabaseRealm to authenticate users
  39. -->
  40. <Resource name="UserDatabase" auth="Container"
  41. type="org.apache.catalina.UserDatabase"
  42. description="User database that can be updated and saved"
  43. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  44. pathname="conf/tomcat-users.xml" />
  45. </GlobalNamingResources>
  46. <!-- A "Service" is a collection of one or more "Connectors" that share
  47. a single "Container" Note: A "Service" is not itself a "Container",
  48. so you may not define subcomponents such as "Valves" at this level.
  49. Documentation at /docs/config/service.html
  50. -->
  51. <Service name="Catalina">
  52. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  53. <!--
  54. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  55. maxThreads="150" minSpareThreads="4"/>
  56. -->
  57. <!-- A "Connector" represents an endpoint by which requests are received
  58. and responses are returned. Documentation at :
  59. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  60. Java AJP Connector: /docs/config/ajp.html
  61. APR (HTTP/AJP) Connector: /docs/apr.html
  62. Define a non-SSL HTTP/1.1 Connector on port 8080
  63. -->
  64. <Connector port="7775" protocol="HTTP/1.1"
  65. connectionTimeout="20000"
  66. redirectPort="8443" />
  67. <!-- A "Connector" using the shared thread pool-->
  68. <!--
  69. <Connector executor="tomcatThreadPool"
  70. port="8080" protocol="HTTP/1.1"
  71. connectionTimeout="20000"
  72. redirectPort="8443" />
  73. -->
  74. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  75. This connector uses the BIO implementation that requires the JSSE
  76. style configuration. When using the APR/native implementation, the
  77. OpenSSL style configuration is required as described in the APR/native
  78. documentation -->
  79. <!--
  80. <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
  81. maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
  82. clientAuth="false" sslProtocol="TLS" />
  83. -->
  84. <!-- Define an AJP 1.3 Connector on port 8009 -->
  85. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  86. <!-- An Engine represents the entry point (within Catalina) that processes
  87. every request. The Engine implementation for Tomcat stand alone
  88. analyzes the HTTP headers included with the request, and passes them
  89. on to the appropriate Host (virtual host).
  90. Documentation at /docs/config/engine.html -->
  91. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  92. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  93. -->
  94. <Engine name="Catalina" defaultHost="localhost">
  95. <!--For clustering, please take a look at documentation at:
  96. /docs/cluster-howto.html (simple how to)
  97. /docs/config/cluster.html (reference documentation) -->
  98. <!--
  99. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  100. -->
  101. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  102. via a brute-force attack -->
  103. <Realm className="org.apache.catalina.realm.LockOutRealm">
  104. <!-- This Realm uses the UserDatabase configured in the global JNDI
  105. resources under the key "UserDatabase". Any edits
  106. that are performed against this UserDatabase are immediately
  107. available for use by the Realm. -->
  108. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  109. resourceName="UserDatabase"/>
  110. </Realm>
  111. <Host name="localhost" appBase="webapps"
  112. unpackWARs="true" autoDeploy="true">
  113. <!-- SingleSignOn valve, share authentication between web applications
  114. Documentation at: /docs/config/valve.html -->
  115. <!--
  116. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  117. -->
  118. <!-- Access log processes all example.
  119. Documentation at: /docs/config/valve.html
  120. Note: The pattern used is equivalent to using pattern="common" -->
  121. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  122. prefix="localhost_access_log." suffix=".txt"
  123. pattern="%h %l %u %t "%r" %s %b" />
  124. </Host>
  125. </Engine>
  126. </Service>
  127. </Server>

tomcat-transport的端口7776,的server.xml内容:

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- Note: A "Server" is not itself a "Container", so you may not
  17. define subcomponents such as "Valves" at this level.
  18. Documentation at /docs/config/server.html
  19. -->
  20. <Server port="8006" shutdown="SHUTDOWN">
  21. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  22. <!-- Security listener. Documentation at /docs/config/listeners.html
  23. <Listener className="org.apache.catalina.security.SecurityListener" />
  24. -->
  25. <!--APR library loader. Documentation at /docs/apr.html -->
  26. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  27. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  28. <Listener className="org.apache.catalina.core.JasperListener" />
  29. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  30. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  31. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  32. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  33. <!-- Global JNDI resources
  34. Documentation at /docs/jndi-resources-howto.html
  35. -->
  36. <GlobalNamingResources>
  37. <!-- Editable user database that can also be used by
  38. UserDatabaseRealm to authenticate users
  39. -->
  40. <Resource name="UserDatabase" auth="Container"
  41. type="org.apache.catalina.UserDatabase"
  42. description="User database that can be updated and saved"
  43. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  44. pathname="conf/tomcat-users.xml" />
  45. </GlobalNamingResources>
  46. <!-- A "Service" is a collection of one or more "Connectors" that share
  47. a single "Container" Note: A "Service" is not itself a "Container",
  48. so you may not define subcomponents such as "Valves" at this level.
  49. Documentation at /docs/config/service.html
  50. -->
  51. <Service name="Catalina">
  52. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  53. <!--
  54. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  55. maxThreads="150" minSpareThreads="4"/>
  56. -->
  57. <!-- A "Connector" represents an endpoint by which requests are received
  58. and responses are returned. Documentation at :
  59. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  60. Java AJP Connector: /docs/config/ajp.html
  61. APR (HTTP/AJP) Connector: /docs/apr.html
  62. Define a non-SSL HTTP/1.1 Connector on port 8080
  63. -->
  64. <Connector port="7776" protocol="HTTP/1.1"
  65. connectionTimeout="20000"
  66. redirectPort="8444" />
  67. <!-- A "Connector" using the shared thread pool-->
  68. <!--
  69. <Connector executor="tomcatThreadPool"
  70. port="8080" protocol="HTTP/1.1"
  71. connectionTimeout="20000"
  72. redirectPort="8443" />
  73. -->
  74. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  75. This connector uses the BIO implementation that requires the JSSE
  76. style configuration. When using the APR/native implementation, the
  77. OpenSSL style configuration is required as described in the APR/native
  78. documentation -->
  79. <!--
  80. <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
  81. maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
  82. clientAuth="false" sslProtocol="TLS" />
  83. -->
  84. <!-- Define an AJP 1.3 Connector on port 8009 -->
  85. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  86. <!-- An Engine represents the entry point (within Catalina) that processes
  87. every request. The Engine implementation for Tomcat stand alone
  88. analyzes the HTTP headers included with the request, and passes them
  89. on to the appropriate Host (virtual host).
  90. Documentation at /docs/config/engine.html -->
  91. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  92. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  93. -->
  94. <Engine name="Catalina" defaultHost="localhost">
  95. <!--For clustering, please take a look at documentation at:
  96. /docs/cluster-howto.html (simple how to)
  97. /docs/config/cluster.html (reference documentation) -->
  98. <!--
  99. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  100. -->
  101. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  102. via a brute-force attack -->
  103. <Realm className="org.apache.catalina.realm.LockOutRealm">
  104. <!-- This Realm uses the UserDatabase configured in the global JNDI
  105. resources under the key "UserDatabase". Any edits
  106. that are performed against this UserDatabase are immediately
  107. available for use by the Realm. -->
  108. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  109. resourceName="UserDatabase"/>
  110. </Realm>
  111. <Host name="localhost" appBase="webapps"
  112. unpackWARs="true" autoDeploy="true">
  113. <!-- SingleSignOn valve, share authentication between web applications
  114. Documentation at: /docs/config/valve.html -->
  115. <!--
  116. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  117. -->
  118. <!-- Access log processes all example.
  119. Documentation at: /docs/config/valve.html
  120. Note: The pattern used is equivalent to using pattern="common" -->
  121. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  122. prefix="localhost_access_log." suffix=".txt"
  123. pattern="%h %l %u %t "%r" %s %b" />
  124. </Host>
  125. </Engine>
  126. </Service>
  127. </Server>

加入项目war包,启动两个tomcat即可。

发表评论

表情:
评论列表 (有 0 条评论,440人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Linux安装tomcat

    前几天买了一个腾讯云服务器,想在上边部署几个tomcat,于是乎在网上找了一些教程,大部分是这样的http://www.linuxidc.com/Linux/2014-04/1

    相关 tomcat部署

    前言 在网上看了很多关于tomcat部署的帖子,大体都一样,但是一些细微的地方不太一样,例如多个tomcat访问环境变量的时候配置,有加环境变量的,有改配置文件的,自己摸