1.环境说明
centos7系统,jdk1.8,tomcat8多实例
2.下载jdk1.8
https://www.oracle.com/technetwork/java/javase/downloads/index.html
3.下载tomcat8
https://tomcat.apache.org/download-80.cgi
4.上传jdk和tomcat
[root@localhost ~]# yum -y install vim lrzsz wget #基本工具安装:vim编辑器/xshell上传下载/主机下载 [root@localhost ~]# rz #上传jdk和tomcat
5.新建jdk和tomcat目录
[root@localhost ~]# mkdir -p /usr/java /usr/tomcat1 /usr/tomcat2
6.jdk配置
[root@localhost ~]# tar xf jdk-8u201-linux-i586.tar.gz [root@localhost ~]# mv jdk1.8.0_201/* /usr/java/ [root@localhost ~]# vim /etc/profile #添加如下jdk环境变量 export JAVA_HOME=/usr/java export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin [root@localhost ~]# source /etc/profile #刷新环境变量配置 [root@localhost ~]# java -version #查看Java版本 java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
7.tomcat配置
[root@localhost ~]# tar xf apache-tomcat-8.5.41.tar.gz
[root@localhost ~]# cp -a apache-tomcat-8.5.41/ /usr/tomcat1
[root@localhost ~]# cp -a apache-tomcat-8.5.41/ /usr/tomcat2
修改tomcat配置,指定各自tomcat文件路径
[root@localhost ~]# vim /home/tomcat1/bin/catalina.sh #tomcat1修改 #OS specific support. $var _must_ be set to either true or false. #下添加如下内容 export CATALINA_BASE=$CATALINA_BASE1 export CATALINA_HOME=$CATALINA_HOME1 [root@localhost ~]# vim /home/tomcat2/bin/catalina.sh #tomcat2修改 #OS specific support. $var _must_ be set to either true or false. #下添加如下内容 export CATALINA_BASE=$CATALINA_BASE2 export CATALINA_HOME=$CATALINA_HOME2
修改tomcat端口号,以免两个tomcat占用端口冲突
[root@localhost ~]# vim /usr/tomcat1/conf/server.xml #修改tomcat1端口 22行:Server port="8001" shutdown="SHUTDOWN" 69行:Connector port="8081" protocol="HTTP/1.1" 116行:Connector port="8011" protocol="AJP/1.3" redirectPort="8443" [root@localhost ~]# vim /usr/tomcat1/conf/server.xml #修改tomcat2端口 22行:Server port="8002" shutdown="SHUTDOWN" 69行:Connector port="8082" protocol="HTTP/1.1" 116行:Connector port="8012" protocol="AJP/1.3" redirectPort="8443"
随意修改一些tomcat主页内容,便于展示,意为可同时在一台机器上部署多个不同的java程序
[root@localhost ~]# vim /usr/tomcat1/webapps/ROOT/index.jsp #修改tomcat1主页 如38行:<span id="nav-home"><a href="${tomcatUrl}">Tomcat1_Home</a></span> [root@localhost ~]# vim /usr/tomcat2/webapps/ROOT/index.jsp #修改tomcat2主页 如38行:<span id="nav-home"><a href="${tomcatUrl}">Tomcat2_Home</a></span>
8.启动tomcat
[root@localhost ~]# /usr/tomcat1/bin/startup.sh #启动tomcat1 Using CATALINA_BASE: /usr/tomcat1 Using CATALINA_HOME: /usr/tomcat1 Using CATALINA_TMPDIR: /usr/tomcat1/temp Using JRE_HOME: /usr/java Using CLASSPATH: /usr/tomcat1/bin/bootstrap.jar:/usr/tomcat1/bin/tomcat-juli.jar Tomcat started. [root@localhost ~]# /usr/tomcat2/bin/startup.sh #启动tomcat2 Using CATALINA_BASE: /usr/tomcat2 Using CATALINA_HOME: /usr/tomcat2 Using CATALINA_TMPDIR: /usr/tomcat2/temp Using JRE_HOME: /usr/java Using CLASSPATH: /usr/tomcat2/bin/bootstrap.jar:/usr/tomcat2/bin/tomcat-juli.jar Tomcat started. [root@localhost ~]# ps -ef|grep java #查看tomcat进程 root 10436 1 31 10:54 pts/0 00:00:08 /usr/java/bin/java -Djava.util.logging.config.file=/usr/tomcat1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/tomcat1/bin/bootstrap.jar:/usr/tomcat1/bin/tomcat-juli.jar -Dcatalina.base=/usr/tomcat1 -Dcatalina.home=/usr/tomcat1 -Djava.io.tmpdir=/usr/tomcat1/temp org.apache.catalina.startup.Bootstrap start root 10495 1 38 10:54 pts/0 00:00:08 /usr/java/bin/java -Djava.util.logging.config.file=/usr/tomcat2/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/tomcat2/bin/bootstrap.jar:/usr/tomcat2/bin/tomcat-juli.jar -Dcatalina.base=/usr/tomcat2 -Dcatalina.home=/usr/tomcat2 -Djava.io.tmpdir=/usr/tomcat2/temp org.apache.catalina.startup.Bootstrap start root 10548 9891 0 10:54 pts/0 00:00:00 grep --color=auto java
9.开启防火墙端口
[root@localhost ~]# firewall-cmd --permanent --add-port=8081/tcp success [root@localhost ~]# firewall-cmd --permanent --add-port=8082/tcp success [root@localhost ~]# firewall-cmd --reload success