Tomcat 多实例部署

一、Tomcat多实例的操作步骤

1、关闭防火墙,将安装 Tomcat 所需软件包传到/opt目录下

jdk-8u201-linux-x64.rpm
apache-tomcat-9.0.16.tar.gz

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2、安装JDK

cd /opt
rpm -qpl jdk-8u201-linux-x64.rpm 
rpm -ivh jdk-8u201-linux-x64.rpm 
java -version

3、安装 tomcat

cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mkdir /usr/local/tomcat
mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat1
cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2

4、配置 tomcat 环境变量

vim /etc/profile.d/tomcat.sh
#tomcat1
export CATALINA_HOME1=/usr/local/tomcat/tomcat1
export CATALINA_BASE1=/usr/local/tomcat/tomcat1
export TOMCAT_HOME1=/usr/local/tomcat/tomcat1

#tomcat2
export CATALINA_HOME2=/usr/local/tomcat/tomcat2
export CATALINA_BASE2=/usr/local/tomcat/tomcat2
export TOMCAT_HOME2=/usr/local/tomcat/tomcat2


source /etc/profile.d/tomcat.sh

5、修改 tomcat2 中的 server.xml 文件,要求各 tomcat 实例配置不能有重复的端口号

vim /usr/local/tomcat/tomcat2/conf/server.xml
<Server port="8006" shutdown="SHUTDOWN">		#22行,修改Server prot,默认为8005 -> 修改为8006
<Connector port="8081" protocol="HTTP/1.1"		#69行,修改Connector port,HTTP/1.1  默认为8080 -> 修改为8081
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />	#116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8010

6、修改各 tomcat 实例中的 startup.sh 和 shutdown.sh 文件,添加 tomcat 环境变量

vim /usr/local/tomcat/tomcat1/bin/startup.sh 
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
##添加以下内容
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1


vim /usr/local/tomcat/tomcat1/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1


vim /usr/local/tomcat/tomcat2/bin/startup.sh 
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2


vim /usr/local/tomcat/tomcat2/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2

7、启动各 tomcat 中的 /bin/startup.sh

/usr/local/tomcat/tomcat1/bin/startup.sh 
/usr/local/tomcat/tomcat2/bin/startup.sh 

netstat -natp | grep java

8、浏览器访问测试

http://192.168.229.90:8080
http://192.168.229.90:8081  

二、实例操作:Tomcat多实例

1、关闭防火墙,将安装 Tomcat 所需软件包传到/opt目录下

[root@192 ~]# cd /opt/
[root@192 opt]# rz -E
rz waiting to receive.
[root@192 opt]# rz -E
rz waiting to receive.
[root@192 opt]# ls
apache-tomcat-9.0.16.tar.gz  jdk-8u201-linux-x64.rpm  rh
[root@192 opt]# systemctl stop firewalld
[root@192 opt]# systemctl disable firewalld
[root@192 opt]# setenforce 0
setenforce: SELinux is disabled

  

2、安装JDK

2.1 安装JDK并加入环境变量

[root@192 opt]# ls
apache-tomcat-9.0.16.tar.gz  jdk-8u201-linux-x64.rpm  rh
[root@192 opt]# rpm -ivh jdk-8u201-linux-x64.rpm 
警告:jdk-8u201-linux-x64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID ec551f03: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:jdk1.8-2000:1.8.0_201-fcs        ################################# [100%]
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...
[root@192 opt]# vim /etc/profile.d/java.sh

export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH

  

2.2 运行脚本文件,然后查看jdk版本

[root@192 opt]# vim /etc/profile.d/java.sh
[root@192 opt]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
[root@192 opt]# source /etc/profile.d/java.sh 
[root@192 opt]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

  

3、安装 tomcat 

[root@192 opt]# ls
apache-tomcat-9.0.16.tar.gz  jdk-8u201-linux-x64.rpm  rh
[root@192 opt]# tar zxvf apache-tomcat-9.0.16.tar.gz 
[root@192 opt]# ls
apache-tomcat-9.0.16  apache-tomcat-9.0.16.tar.gz  jdk-8u201-linux-x64.rpm  rh
[root@192 opt]# mkdir /usr/local/tomcat
[root@192 opt]# mv apache-tomcat-9.0.16 !$
mv apache-tomcat-9.0.16 /usr/local/tomcat
[root@192 opt]# cd /usr/local/tomcat/
[root@192 tomcat]# ls
apache-tomcat-9.0.16
[root@192 tomcat]# mv apache-tomcat-9.0.16/ tomcat1
[root@192 tomcat]# cp -a tomcat1/ tomcat2
[root@192 tomcat]# ls
tomcat1  tomcat2

  

4、配置 tomcat 环境变量

[root@192 tomcat]# vim /etc/profile.d/tomcat.sh

#tomcat1
export CATALINA_HOME1=/usr/local/tomcat/tomcat1
export CATALINA_BASE1=/usr/local/tomcat/tomcat1
export TOMCAT_HOME1=/usr/local/tomcat/tomcat1

#tomcat2
export CATALINA_HOME2=/usr/local/tomcat/tomcat2
export CATALINA_BASE2=/usr/local/tomcat/tomcat2
export TOMCAT_HOME2=/usr/local/tomcat/tomcat2

  

  

5、修改 tomcat2 中的 server.xml 文件,要求各 tomcat 实例配置不能有重复的端口号

  

6、修改各 tomcat 实例中的 startup.sh 和 shutdown.sh 文件,添加 tomcat 环境变量

6.1 修改tomcat1的startup.sh  

  

6.2  修改tomcat1的shutdown.sh

  

6.3  修改tomcat2的startup.sh

6.4 修改tomcat2的shutdown.sh

7、启动各 tomcat 中的 /bin/startup.sh

[root@192 ~]# /usr/local/tomcat/tomcat1/bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat/tomcat1
Using CATALINA_HOME:   /usr/local/tomcat/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat1/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_201-amd64
Using CLASSPATH:       /usr/local/tomcat/tomcat1/bin/bootstrap.jar:/usr/local/tomcat/tomcat1/bin/tomcat-juli.jar
Tomcat started.
[root@192 ~]# /usr/local/tomcat/tomcat2/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat/tomcat2
Using CATALINA_HOME:   /usr/local/tomcat/tomcat2
Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat2/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_201-amd64
Using CLASSPATH:       /usr/local/tomcat/tomcat2/bin/bootstrap.jar:/usr/local/tomcat/tomcat2/bin/tomcat-juli.jar
Tomcat started.
[root@192 ~]# netstat -natp | grep java
tcp6       0      0 :::8080                 :::*                    LISTEN      3552/java           
tcp6       0      0 :::8081                 :::*                    LISTEN      3609/java           
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      3552/java           
tcp6       0      0 127.0.0.1:8006          :::*                    LISTEN      3609/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      3552/java           
tcp6       0      0 :::8010                 :::*                    LISTEN      3609/java 

  

8、浏览器访问测试

  

posted on 2021-08-17 22:00  笑洋仟  阅读(150)  评论(0编辑  收藏  举报

levels of contents