tomcat 多实例做

Posted 123456likun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tomcat 多实例做相关的知识,希望对你有一定的参考价值。

tomcat 多实例做
解压部署tomcat程序
tar xf apache-tomcat-8.9.16.tar.gz
mv apache-tomcat-8.9.16  /usr/local/
创建实例一个
mkdir -p /usr/local/tomcat_instance/tomcat1
拷贝程序目录下的conf文件放入个实例中
cp -R /usr/local/apache-tomcat-8.9.16/conf/ /usr/local/tomcat_instance/tomcat1
在实例中创建启动脚本和停止脚本
mkdir /usr/local/tomcat_instance/tomcat1/bin
touch /usr/local/tomcat_instance/tomcat1/bin
chmod +x /usr/local/tomcat_instance/tomcat1/bin/startup.sh
ls /usr/local/tomcat_instance/
指向实例目录路径(编辑)
vim /usr/local/tomcat_instance/tomcat1/bin/startup.sh
------------------------------------------------------------
#!/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.16"
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 "$@"
----------------------------------------------------------------
第二个实例,同上
 touch /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh
chmod +x /usr/local/tomcat_instance/tomcat1,tomcat2/bin/shutdown.sh
 vim /usr/local/tomcat_instance/tomcat1/bin/shutdown.sh
---------------------------------------------------------------------
#!/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.16"
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 "$@"
------------------------------------------------------------------------------
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh
#!/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.16"
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 "$@"
----------------------------------------------------------------
创建测试页
# mkdir -p /usr/local/tomcat_instance/tomcat1,tomcat2/webapps/ROOT
编辑文件
 vim /usr/local/tomcat_instance/tomcat1/webapps/ROOT/index.jsp
<html>
<title>Tomcat-1</title>
<body>
    Hello This is Tomcat-1.
</body>
</html>
启动tomcat实例
 /usr/local/tomcat_instance/tomcat1/bin/startup.sh
查看监听端口
netstat -lnpt  | grep java
 
 
 

以上是关于tomcat 多实例做的主要内容,如果未能解决你的问题,请参考以下文章

mysql多实例安装

Tomcat多实例和负载均衡

Tomcat多实例和负载均衡

tomcat 多实例做

Tomcat 多实例及动静分离配置

Tomcat多实例集群架构 安全优化和性能优化