1、关闭防火墙,将安装 Tomcat 所需软件包传到/opt目录下
1 jdk-8u201-linux-x64.rpm 2 apache-tomcat-9.0.16.tar.gz 3 4 systemctl stop firewalld 5 systemctl disable firewalld 6 setenforce 0
2、安装JDK
cd /opt rpm -qpl jdk-8u201-linux-x64.rpm rpm -ivh jdk-8u201-linux-x64.rpm java -version
3、安装 tomcat
1 cd /opt 2 tar zxvf apache-tomcat-9.0.16.tar.gz 3 mkdir /usr/local/tomcat 4 mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat1 5 cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2
4、配置 tomcat 环境变量
1 vim /etc/profile.d/tomcat.sh 2 #tomcat1 3 export CATALINA_HOME1=/usr/local/tomcat/tomcat1 4 export CATALINA_BASE1=/usr/local/tomcat/tomcat1 5 export TOMCAT_HOME1=/usr/local/tomcat/tomcat1 6 7 #tomcat2 8 export CATALINA_HOME2=/usr/local/tomcat/tomcat2 9 export CATALINA_BASE2=/usr/local/tomcat/tomcat2 10 export TOMCAT_HOME2=/usr/local/tomcat/tomcat2 11 12 13 source /etc/profile.d/tomcat.sh
5、修改 tomcat2 中的 server.xml 文件,要求各 tomcat 实例配置不能有重复的端口号
1 vim /usr/local/tomcat/tomcat2/conf/server.xml 2 <Server port="8006" shutdown="SHUTDOWN"> #22行,修改Server prot,默认为8005 -> 修改为8006 3 <Connector port="8081" protocol="HTTP/1.1" #69行,修改Connector port,HTTP/1.1 默认为8080 -> 修改为8081 4 <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> #116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8010
6、修改各 tomcat 实例中的 startup.sh 和 shutdown.sh 文件,添加 tomcat 环境变量
1 vim /usr/local/tomcat/tomcat1/bin/startup.sh 2 # ----------------------------------------------------------------------------- 3 # Start Script for the CATALINA Server 4 # ----------------------------------------------------------------------------- 5 ##添加以下内容 6 export CATALINA_BASE=$CATALINA_BASE1 7 export CATALINA_HOME=$CATALINA_HOME1 8 export TOMCAT_HOME=$TOMCAT_HOME1 9 10 11 vim /usr/local/tomcat/tomcat1/bin/shutdown.sh 12 # ----------------------------------------------------------------------------- 13 # Stop script for the CATALINA Server 14 # ----------------------------------------------------------------------------- 15 export CATALINA_BASE=$CATALINA_BASE1 16 export CATALINA_HOME=$CATALINA_HOME1 17 export TOMCAT_HOME=$TOMCAT_HOME1 18 19 20 vim /usr/local/tomcat/tomcat2/bin/startup.sh 21 # ----------------------------------------------------------------------------- 22 # Start Script for the CATALINA Server 23 # ----------------------------------------------------------------------------- 24 export CATALINA_BASE=$CATALINA_BASE2 25 export CATALINA_HOME=$CATALINA_HOME2 26 export TOMCAT_HOME=$TOMCAT_HOME2 27 28 29 vim /usr/local/tomcat/tomcat2/bin/shutdown.sh 30 # ----------------------------------------------------------------------------- 31 # Stop script for the CATALINA Server 32 # ----------------------------------------------------------------------------- 33 export CATALINA_BASE=$CATALINA_BASE2 34 export CATALINA_HOME=$CATALINA_HOME2 35 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.80.101:8080 http://192.168.80.101:8081