zoukankan      html  css  js  c++  java
  • tomcat多实例配置

    部署方式有四种:

    单实例单应用:一个进程,一个项目。

    单实例多应用:一个进程,多个项目。

    **多实例单应用:多个进程,单个项目。

    **多实例多应用:多个进程,多个项目。

    这里我们来部署多实例单应用为例:

    1.解压并部署tomcat进程

    tar xf apache-tomcat-8.5.40.tar.gz
    mv apache-tomcat-8.5.40 /usr/local/

    2.创建两个实例的工作目录

    mkdir -p /usr/local/tomcat_instance/{tomcat1,tomcat2}

    3.拷贝tomcat目录下的conf目录分别放入两个实例目录中

    cp -R /usr/local/apache-tomcat-8.5.40/conf/ /usr/local/tomcat_instance/tomcat1

    cp -R /usr/local/apache-tomcat-8.5.40/conf/ /usr/local/tomcat_instance/tomcat2

    4.在tomcat实例目录下的bin目录中创建实例启动和停止脚本

    a.创建启动脚本

    mkdir /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin

    touch /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/startup.sh

    b.编辑启动脚本

    vim /usr/local/tomcat_instance/tomcat1/bin/startup.sh

    c.脚本内容:

    #!/bin/bash
    export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
    export CATALINA_BASE="/usr/local/tomcat_instance/tomcat1"
    export CATALINA_TMPDIR="$CATALINA_BASE/temp"
    export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
    export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dtomcat.name=tomcat1"
    #创建logs目录
    if [ ! -d "$CATALINA_BASE/logs" ]; then
      mkdir $CATALINA_BASE/logs
    fi
    #创建temp目录
    if [ ! -d "$CATALINA_BASE/temp" ]; then
      mkdir $CATALINA_BASE/temp
    fi
    #调用tomcat启动脚本
    bash $CATALINA_HOME/bin/startup.sh "$@"
    d.将tomcat1脚本内容拷贝到tomcat2中
    cp /usr/local/tomcat_instance/tomcat1/bin/startup.sh /usr/local/tomcat_instance/tomcat2/bin/startup.sh
    e.编辑脚本
    vim /usr/local/tomcat_instance/tomcat2/bin/startup.sh
    f.修改脚本内容:(红色部分)
    #!/bin/bash
    export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
    export CATALINA_BASE="/usr/local/tomcat_instance/tomcat2"
    export CATALINA_TMPDIR="$CATALINA_BASE/temp"
    export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
    export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dtomcat.name=tomcat2"
    #创建logs目录
    if [ ! -d "$CATALINA_BASE/logs" ]; then
      mkdir $CATALINA_BASE/logs
    fi
    #创建temp目录
    if [ ! -d "$CATALINA_BASE/temp" ]; then
      mkdir $CATALINA_BASE/temp
    fi
    #调用tomcat启动脚本
    bash $CATALINA_HOME/bin/startup.sh "$@"
    g.给脚本执行权限
    chmod +x /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/startup.sh
    h.创建停止脚本
    touch /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/shutdown.sh
    i.编辑停止脚本
    vim /usr/local/tomcat_instance/tomcat1/bin/shutdown.sh
    j.脚本内容:
    #!/bin/bash
    export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
    export CATALINA_BASE="/usr/local/tomcat_instance/tomcat1"
    export CATALINA_TMPDIR="$CATALINA_BASE/temp"
    export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
    bash $CATALINA_HOME/bin/shutdown.sh "$@"
    k.将tomcat1的关闭脚本内容拷贝给tomcat2
    cp /usr/local/tomcat_instance/tomcat1/bin/shutdown.sh /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh
    l.修改tomcat2关闭脚本的内容
    vim /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh
    m.修改内容:(红色部分)
     
    #!/bin/bash
    export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
    export CATALINA_BASE="/usr/local/tomcat_instance/tomcat2"
    export CATALINA_TMPDIR="$CATALINA_BASE/temp"
    export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
    bash $CATALINA_HOME/bin/shutdown.sh "$@"
    n.给与执行权限
    chmod +x /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/shutdown.sh
    5.编辑tomcat2的主配置文件
    vim /usr/local/tomcat_instance/tomcat2/conf/server.xml
    修改三个端口:

     

    与tomcat1 的端口不重复就行

     6.创建测试页目录

    mkdir /usr/local/tomcat_instance/tomcat1/webapps/ROOT -p
    mkdir /usr/local/tomcat_instance/tomcat2/webapps/ROOT -p
    7.创建测试网页
    vim /usr/local/tomcat_instance/tomcat1/webapps/ROOT/index.jsp
    网页内容:
    <html>
    <title>Tomcat-1</title>
    <body>
            Hello This is Tomcat-1.
    </body>
    </html>
    ============================
    vim /usr/local/tomcat_instance/tomcat2/webapps/ROOT/index.jsp
    网页内容:
    <html>
    <title>Tomcat-2</title>
    <body>
            Hello This is Tomcat-2.
    </body>
    </html>
    8.起服务
    /usr/local/tomcat_instance/tomcat1/bin/startup.sh
    /usr/local/tomcat_instance/tomcat2/bin/startup.sh
    9.查看java相关的进程端口
    netstat -lnpt | grep java

     10.进入网页进行测试

  • 相关阅读:
    经典的笔试题python操作数据库和python设计模式【多测师_王sir】
    上证所python笔试题【多测师_王sir】
    银行移动消费信贷业务梳理【多测师_王sir】
    查看log.txt 日志文件中包含关键字x123或者x124的行,以及该行前后10行内容,并输出到out.txt中【多测师_王sir】【Linux题目】
    文件权限设置
    windows OpenSSH WARNING: UNPROTECTED PRIVATE KEY FILE!
    vue对象合并
    elk安装配置
    ElasticSearch
    Elastic Search之Search API(Query DSL)、字段类查询、复合查询
  • 原文地址:https://www.cnblogs.com/990114-jhc/p/11583923.html
Copyright © 2011-2022 走看看