`
ssxxjjii
  • 浏览: 938232 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

tomcat多实例配置

 
阅读更多

原文地址:http://azeditech.com/tomcat/multiple-tomcat-instances.html

Running multiple Tomcat instances on one server

Here's a brief step by step guide to running more than one instance of Tomcat on a single machine.

 

Step 1: Install the Tomcat files

Download Tomcat 4.1 or 5.5, and unzip it into an appropriate directory. I usually put it in /usr/local, so it ends up in a directory called /usr/local/apache-tomcat-5.5.17 (5.5.17 being the current version as of this writing), and make a symlink named /usr/local/tomcat to that directory. When later versions come out, I can unzip them and relink, leaving the older version in case things don't work out (which rarely if ever happens, but I'm paranoid).

Step 2: Make directories for each instance

For each instance of Tomcat you're going to run, you'll need a directory that will be CATALINA_HOME. For example, you might make them /var/tomcat/serverA and /var/tomcat/serverB.

In each of these directories you need the following subdirectories: conf, logs, temp, webapps, and work.

Put a server.xml and web.xml file in the conf directory. You can get these from the conf directory of the directory where you put the tomcat installation files, although of course you should tighten up your server.xml a bit.

The webapps directory is where you'll put the web applications you want to run on the particular instance of Tomcat.

I like to have the Tomcat manager webapp installed on each instance, so I can play with the webapps, and see how many active sessions there are. See my instructions for configuring the Tomcat manager webapp.

Step 3: Configure the ports and/or addresses for each instance

Tomcat listens to at least two network ports, one for the shutdown command, and one or more for accepting requests. Two instances of Tomcat can't listen to the same port number on the same IP address, so you will need to edit your server.xml files to change the ports they listen to.

The first port to look at is the shutdown port. This is used by the command line shutdown script (actually, but the Java code it runs) to tell the Tomcat instance to shut itself down. This port is defined at the top of the server.xml file for the instance.

<Server port="8001" shutdown="_SHUTDOWN_COMMAND_" debug="0">

Make sure each instance uses a different port value. The port value will normally need to be higher than 1024, and shouldn't conflict with any other network service running on the same system. The shutdown string is the value that is sent to shut the server down. Note that Tomcat won't accept shutdown commands that come from other machines.

Unlike the other ports Tomcat listens to, the shutdown port can't be configured to listen to its port on a different IP address. It always listens on 127.0.0.1.

The other ports Tomcat listens to are configured with the <Connector> elements, for instance the HTTP or JK listeners. The port attribute configures which port to listen to. Setting this to a different value on the different Tomcat instances on a machine will avoid conflict.

Of course, you'll need to configure whatever connects to that Connector to use the different port. If a web server is used as the front end using mod_jk, mod_proxy, or the like, then this is simple enough - change your web server's configuration.

In some cases you may not want to do this, for instance you may not want to use a port other than 8080 for HTTP connectors. If you want all of your Tomcat intances to use the same port number, you'll need to use different IP addresses. The server system must be configured with multiple IP addresses, and the address attribute of the <Connector> element for each Tomcat instance will be set to the appropriate IP address.

Step 4: Startup

Startup scripts are a whole other topic, but here's the brief rundown. The main different from running a single Tomcat instance is you need to set CATALINA_BASE to the directory you set up for the particular instance you want to start (or stop). Here's a typical startup routine:

JAVA_HOME=/usr/java JAVA_OPTS="-Xmx800m -Xms800m" CATALINA_HOME=/usr/local/tomcat CATALINA_BASE=/var/tomcat/serverA export JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE $CATALINA_HOME/bin/catalina.sh start
补充:每个tomcat实例的启动脚本和关闭脚本必须设置的环境变量是:
 CATALINA_HOME (每个实例的值都一样,指向tomcat程序的安装目录)
 CATALINA_BASE (各个实例有不同的值,指向各个实例的安装目录)
 JAVA_HOME或JRE_HOME (各个实例的值都一样)
例子:start.bat (Windows环境下)
  1. rem 每个tomcat实例的启动脚本  
  2.   
  3. rem 设置Java虚拟机的安装路径(也可以设置JDK的安装路径JAVA_HOME,二者选其一即可)  
  4. rem ------------------------------------------------------------------  
  5. set JRE_HOME=C:/Program Files/Java/jre6  
  6.   
  7. rem 设置CATALINA_HOME  
  8. rem -----------------  
  9. set CATALINA_HOME=D:/server/tomcat6_HOME  
  10.   
  11. rem 每个tomcat实例的CATALINA_BASE的值是不一样的  
  12. rem -------------------------------------------  
  13. set CATALINA_BASE=D:/server/tomcat6_BASE_1  
  14.   
  15. call %CATALINA_HOME%/bin/startup.bat  
分享到:
评论

相关推荐

    Linux下tomcat多实例配置

    Linux下tomcat多实例配置成功。步骤如下:  1. 下载一个免安装版本的tomcat,例如:apache-tomcat-7.0.59.tar.gz。解压:tar xvf pache-tomcat-7.0.59.tar.gz.  解压后的文件夹中大致有7个文件夹:  bin (运行...

    tomcat 多实例脚本文件

    多实例配置允许开发者或系统管理员在同一个物理或虚拟机上隔离不同的应用,提高资源利用率并方便管理。 描述 "tomcat 多实例脚本文件" 提示我们这里可能有一个自动化脚本,用于创建、启动、停止或管理这些独立的 ...

    Tomcat+JSP配置实例

    Tomcat+JSP配置实例 、、、、、

    jdk,tomcat配置实例

    jdk,tomcat配置实例 可以下载

    zabbix监控tomcat多实例自动化脚本配置

    首先,理解“Zabbix监控Tomcat多实例自动化脚本配置”意味着我们需要在Zabbix中设置一个自动发现规则,以便它能识别并监控运行在同一服务器或不同服务器上的所有Tomcat实例。这通常涉及到以下几个关键步骤: 1. **...

    Nginx+tomcat配置集群负载均衡实例

    配置Nginx+Tomcat集群负载均衡的第一步是安装Nginx和多个Tomcat实例。在多台服务器上部署Tomcat,形成一个集群,确保服务的高可用性。每台服务器上的Tomcat实例都需要配置相同的应用,以处理相同类型的请求。 接...

    zabbix自动安装单机多tomcat实例脚本

    【Zabbix自动安装单机多Tomcat实例脚本详解】 在IT运维中,监控系统扮演着至关重要的角色,Zabbix作为一款开源的企业级监控解决方案,能够有效地监控服务器、网络设备以及应用程序的运行状态。本资源提供的"zabbix...

    tomcat配置实例.rar

    6. **虚拟主机配置**:如何配置多个域名指向同一Tomcat实例,实现多站点部署。 7. **日志和错误处理**:设置和查看Tomcat的日志文件,理解错误代码和解决常见问题。 8. **安全性设置**:涵盖用户认证、角色权限、 ...

    tomcat及其配置文件

    【标题】:“Tomcat及其配置文件” 在Java Web开发领域,Tomcat是一个广泛使用的开源应用服务器,它专注于Servlet和JSP的应用。Tomcat是Apache软件基金会的Jakarta项目的一部分,作为一个轻量级的Web服务器和...

    TomcatJSP经典配置实例

    TomcatJSP经典配置实例

    maven+tomcat+eclipse配置实例

    maven+tomcat+eclipse配置实例

    Tomcat集群实例下载

    当我们谈论“Tomcat集群实例下载”时,这通常指的是通过设置多个Tomcat实例来构建一个集群,以实现负载均衡、高可用性和容错性。 集群是一种策略,将多个独立的服务器组织成一个逻辑单元,共同提供服务,从而提高...

    nginx+tomcat多域名配置

    - **Redis共享Session**:在Tomcat和Nginx之间部署一个Redis服务器,将Session数据存储在Redis中,所有Tomcat实例都可以访问。 5. **实践步骤**: 1. 安装Nginx和Tomcat。 2. 配置Nginx,添加多域名的虚拟主机...

    Tomcat JSP经典配置实例

    Tomcat JSP经典配置实例

    Tomcat服务器配置 视频教程 Tomcat视频

    6. **虚拟主机配置**:如何在同一台机器上配置多个独立的Tomcat实例,或者在单个Tomcat中设置多个虚拟主机,以托管不同的Web应用。 7. **部署Web应用**:演示如何将WAR文件或已解压的目录放入webapps目录,以及如何...

    Tomcat+JSP+MySQL经典配置实例

    Tomcat+JSP+MySQL经典配置实例

    tomcat集群配置

    Tomcat集群是指多个独立的Tomcat实例通过网络连接协同工作,共同处理请求,实现负载均衡和数据共享。在集群环境中,每个Tomcat实例被称为一个节点。 **二、负载均衡** 负载均衡是Tomcat集群的核心功能之一,它的...

    nginx负载均衡代理多个tomcat搭建实例过程

    "Nginx负载均衡代理多个Tomcat搭建实例过程" 一、Nginx安装与配置 Nginx是一款轻量级的Web...Nginx负载均衡代理多个Tomcat搭建实例过程需要完成Nginx和Tomcat的安装和配置,配置Nginx负载均衡,并进行压力测试。

    一个很好的tomcat实例

    这个"一个很好的tomcat实例"很可能是包含了Tomcat的配置、示例应用程序以及可能的部署指南,旨在帮助用户更好地理解和使用Tomcat。 首先,让我们深入了解一下Tomcat的核心功能。Tomcat是Apache软件基金会Jakarta...

    eclipse项目配置tomcat步骤

    Eclipse 项目配置 Tomcat 步骤 在 Eclipse 中配置 Tomcat 是一个非常重要的步骤,它能够让开发者在 Eclipse 中使用 Tomcat 服务器来运行和测试 Java Web 应用程序。下面是 Eclipse 项目配置 Tomcat 的详细步骤: ...

Global site tag (gtag.js) - Google Analytics