zoukankan      html  css  js  c++  java
  • windows下Tomcat配置多实例

    详情参见tomcat安装目录下RUNNING.txt中Advanced Configuration - Multiple Tomcat Instances部分。

    问题源于下面这段tomcat官方文档的介绍:

    Throughout the docs, you'll notice there are numerous references to $CATALINA_HOME. This represents the root of your Tomcat installation. When we say, "This information can be found in your $CATALINA_HOME/README.txt file" we mean to look at the README.txt file at the root of your Tomcat install. Optionally, Tomcat may be configured for multiple instances by defining $CATALINA_BASE for each instance. If multiple instances are not configured, $CATALINA_BASE is the same as $CATALINA_HOME.

    These are some of the key tomcat directories:

    • /bin - Startup, shutdown, and other scripts. The *.sh files (for Unix systems) are functional duplicates of the *.bat files (for Windows systems). Since the Win32 command-line lacks certain functionality, there are some additional files in here.
    • /conf - Configuration files and related DTDs. The most important file in here is server.xml. It is the main configuration file for the container.
    • /logs - Log files are here by default.
    • /webapps - This is where your webapps go.

    主要介绍了$CATALINA_HOME和$CATALINA_BASE的区别,这里讲如果要配置多实例,应该对$CATALINA_BASE进行配置。
    由于默认情况下,一般只会使用tomcat的一个实例,所以平时很少用到$CATALINA_BASE配置的方式。
    以前要配置多个tomcat时,会解压多个tomcat程序,修改端口后分别启动,相对会占用较多的存储空间。
    本文的配置方式是实现在只用一个tomcat程序的情况下,启动多个实例。

    1、原理:
    在tomcat的安装目录中,所有实例共享的文件夹只有lib、bin两个文件夹,其余的文件夹每个实例分别持有一份。由于一般只有一个实例,所以这些文件夹放在了同一目录下,目录结构如下:

    若要实现多实例,目录结构如下所示:

    上图中定义了2个实例。

    2、步骤二:在instance1和instance2下分别增加一个自定义的startup.bat文件,内容如下

    @echo off
    
    @echo 删除缓存
    rmdir /S/Q %CD%/work
    
    SET CATALINA_BASE=%CD%
    
    cd ../../bin
    catalina.bat start

    前提是已经定义了系统变量JAVA_HOME,并且已经添加到PATH中
    此处可根据需要设置CATALINA_OPTS和JAVA_OPTS环境变量。

    3、注意事项:
    为了保证端口不冲突,需要分别设置各个实例下conf/server.xml中的端口,避免重复,否则启动多个时会出现jvm_bind异常。
    4、启动:
    分别双击instances/instance1/startup.bat和instances/instance1/startup.bat,就启动了2个实例,由于我设定的端口分别为8080和8081,
    分别访问http://localhost:8080和http://localhost:8081即可分别访问,对应的部署不作赘述。

  • 相关阅读:
    数据分析的数据来源都有哪些?
    数据分析的技能要求及分析流程
    (原创)使用matlab-cftools拟合工具的问题
    Spring加载xml配置文件的方式
    Spring-ResolvableType可解决的数据类型
    从list中取N个随机生成一个集合
    AOP统一处理修改人、创建人、修改时间、创建时间
    Java依据集合元素的属性,集合相减
    java去掉数字后面的0
    数字格式化NumberFormat
  • 原文地址:https://www.cnblogs.com/tq03/p/3507658.html
Copyright © 2011-2022 走看看