在同一台主机安装tomcat实现多实例单应用
[root@douyanru ~]# tar xf apache-tomcat-8.5.16.tar 解压tomcat软件包 [root@douyanru ~]# ls //查看解压后文件 apache-tomcat-8.5.16 apache-tomcat-8.5.16.tar.gz [root@douyanru ~]# mv apache-tomcat-8.5.16 /usr/local/ //将解压后的文件转移到/usr/local/ [root@douyanru ~]# cp -R /usr/local/apache-tomcat-8.5.16/conf/ /usr/local/tomcat_instance/tomcat1 //解压后的文件内conf文件下内容复制到新建的tomcat1下 [root@douyanru ~]# cp -R /usr/local/apache-tomcat-8.5.16/conf/ /usr/local/tomcat_instance/tomcat2 //解压后的文件内conf文件下内容复制到新建的tomcat2下 [root@douyanru ~]# mkdir /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin //在两个新建的tomcat下创建bin文档 [root@douyanru ~]# touch /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin/startup.sh //在新文档下创建启动脚本 #tomcat2启动脚本 [root@douyanru ~]# cat /usr/local/tomcat_instance/tomcat1/startup.sh 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 -Xms1024m -Djava.awt.headless=true -Dtomcat.name=tomcat1" if [ ! -d "$CATALINA_BASE/logs" ];then mkdir $CATALINA_BASE/logs fi if [ ! -d "$CATALINA_BASE/temp" ];then mkdir $CATALINA_BASE/temp fi bash $CATALINA_HOME/bin/startup.sh "$@" [root@douyanru ~]# chmod +x /usr/local/tomcat_instance/tomcat1/bin/start.sh //添加执行权限 #tomcat2启动脚本 [root@douyanru ~]# cat /usr/local/tomcat_instance/ tomcat2/bin/startup.sh 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" export JAVA_OPTS="-server -Xms1024m -Xms1024m -Djava.awt.headless=true -Dtomcat.name=tomcat2" if [ ! -d "$CATALINA_BASE/logs" ];then mkdir $CATALINA_BASE/logs fi if [ ! -d "$CATALINA_BASE/temp" ];then mkdir $CATALINA_BASE/temp fi bash $CATALINA_HOME/bin/startup.sh "$@" [root@douyanru ~]# chmod +x /usr/local/tomcat_instance/tomcat2/bin/start.sh //添加执行权限 [root@douyanru ~]# vim /usr/local/tomcat_instance/tomcat1/bin/startup.sh [root@douyanru ~]# cd /usr/local/ [root@douyanru local]# ls apache-tomcat-8.5.16 lib sbin bin lib64 share boost libexec src etc mysql tomcat_instance games nginx yd.socket.server include php5 java qcloud [root@douyanru local]# vim /usr/local/tomcat_instance/tomcat1/bin/startup.sh [root@douyanru local]# cp /usr/local/tomcat_instance/tomcat1/bin/startup.sh /usr/local/tomcat_instance/tomcat2/bin/startup.sh [root@douyanru local]# vim /usr/local/tomcat_instance/tomcat2/bin/startup.sh [root@douyanru local]# vim /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh //关闭脚本 [root@douyanru ~]# cat /usr/local/tomcat_instance/tomcat2/bin/shudown.sh 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/shudown.sh "$@" [root@douyanru local]# cp /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh /usr/local/tomcat_instance/tomcat1/bin/shudown.sh [root@douyanru local]# vim /usr/local/tomcat_instance/tomcat1/bin/shudown.sh //关闭脚本 [root@douyanru ~]# cat /usr/local/tomcat_instance/tomcat1/bin/shudown.sh 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/shudown.sh "$@" [root@douyanru local]# chmod +x /usr/local/tomcat_instance/tomcat1/bin/shudown.sh //添加执行权限 [root@douyanru local]# chmod +x /usr/local/tomcat_instance/tomcat2/bin/shudown.sh //添加执行权限 [root@douyanru local]# cd [root@douyanru ~]# vim /usr/local/tomcat_instance/tomcat2/conf/server.xml //修改主配置文件更改端口防止冲突 [root@douyanru ~]# mkdir -p /usr/local/tomcat_instance/tomcat1/webapps/ROOT [root@douyanru ~]# [root@douyanru ~]# mkdir -p /usr/local/tomcat_instance/tomcat2/webapps/ROOT [root@douyanru ~]# vim /usr/local/tomcat_instance/tomcat1/webapps/ROOT/index.jsp [root@douyanru ~]# vim /usr/local/tomcat_instance/tomcat2/webapps/ROOT/index.jsp [root@douyanru ~]# /usr/local/tomcat_instance/tomcat1/bin/start.sh Using CATALINA_BASE: /usr/local/tomcat_instance/tomcat1 Using CATALINA_HOME: /usr/local/apache-tomcat-8.5.16 Using CATALINA_TMPDIR: /usr/local/tomcat_instance/tomcat1/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/apache-tomcat-8.5.16/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.16/bin/tomcat-juli.jar Using CATALINA_PID: /usr/local/tomcat_instance/tomcat1/bin/tomcat.pid Tomcat started. [root@douyanru ~]# /usr/local/tomcat_instance/tomcat2/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat_instance/tomcat2 Using CATALINA_HOME: /usr/local/apache-tomcat-8.5.16 Using CATALINA_TMPDIR: /usr/local/tomcat_instance/tomcat2/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/apache-tomcat-8.5.16/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.16/bin/tomcat-juli.jar Using CATALINA_PID: /usr/local/tomcat_instance/tomcat2/bin/tomcat.pid Tomcat started. [root@douyanru ~]# netstat -lnpt |grep java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2363/java tcp6 0 0 127.0.0.1:8006 :::* LISTEN 2448/java tcp6 0 0 :::8008 :::* LISTEN 2448/java tcp6 0 0 :::8009 :::* LISTEN 2363/java tcp6 0 0 :::8080 :::* LISTEN 2363/java tcp6 0 0 :::8090 :::* LISTEN 2448/java [root@douyanru ~]#