tomcat单机多实例

回复 收藏

1:tomcat安装不说了,在/usr/local/tomcat 同级目录下创建 tomcat-1 tomcat-2  tomcat-shell

2:cd /usr/local/tomcat 

    mv conf/ webapps/ temp/ logs/ work/ -t ../tomcat-1

   cp -r tomcat-1/* tomcat-2

3:cd tomcat-shell/

 vim start_tomcat.sh

 vim stop_tomcat.sh

chmod 777 start_tomcat.sh stop_tomcat.sh

4:start_tomcat.sh:

#!/bin/bash

export CATALINA_HOME=/usr/local/tomcat

export CATALINA_BASE=${1%/}

echo $CATALINA_BASE

TOMCAT_ID=`ps aux |grep "java"|grep "Dcatalina.base=$CATALINA_BASE "|grep -v "grep"|awk '{ print $2}'`

if [ -n "$TOMCAT_ID" ] ; then

echo "tomcat(${TOMCAT_ITOMCAT_ID}) still running now , please shutdown it firest";

    exit 2;

fi

TOMCAT_START_LOG=`$CATALINA_HOME/bin/startup.sh`

if [ "$?" = "0" ]; then

    echo "$0 ${1%/} start succeed"

else

    echo "$0 ${1%/} start failed"

    echo $TOMCAT_START_LOG

fi

5:stop_tomcat.sh

#!/bin/bash

export CATALINA_HOME=/usr/local/tomcat

export CATALINA_BASE=${1%/}

echo $CATALINA_BASE

TOMCAT_ID=`ps aux |grep "java"|grep "[D]catalina.base=$CATALINA_BASE "|awk '{ print $2}'`

if [ -n "$TOMCAT_ID" ] ; then

TOMCAT_STOP_LOG=`$CATALINA_HOME/bin/shutdown.sh`

else

    echo "Tomcat instance not found : ${1%/}"

    exit

fi

if [ "$?" = "0" ]; then

    echo "$0 ${1%/} stop succeed"

else

    echo "$0 ${1%/} stop failed"

    echo $TOMCAT_STOP_LOG

fi

6:我这里把 tomcat-2 实例的 Connector Port 改为了 8081 ,并分别在 tomcat-1、tomcat-2 的 webapps/ROOT 目录下放入了一个页面文件,内容如下:

<html>

<title>Tomcat-1</title>

<body> Hello Mafly! from Tomcat-1.</body>

</html>

7:/usr/local/tomcat-shell/start_tomcat.sh /usr/local/tomcat-1

/usr/local/tomcat-shell/start_tomcat.sh /usr/local/tomcat-2

原文地址:https://www.cnblogs.com/mafly/p/tomcat.html

2018-07-27 11:57 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: