IP:192.168.200.112
java环境变量还是原来的配置
把以前的tomcat删除
tar xf apache-tomcat-8.5.40.tar.gz -C /usr/local/
mkdir -p /usr/local/tomcat_instance/tomcat1
mkdir -p /usr/local/tomcat_instance/tomcat2
cp -R /usr/local/apache-tomcat-8.5.40/conf/ /usr/local/tomcat_instance/tomcat1
cp -R /usr/local/apache-tomcat-8.5.40/conf/ /usr/local/tomcat_instance/tomcat2
mkdir /usr/local/tomcat_instance/{tomcat1,tomcat2}/bin
touch /usr/local/tomcat_instance/tomcat1/bin/startup.sh
chmod +x /usr/local/tomcat_instance/tomcat1/bin/startup.sh
touch /usr/local/tomcat_instance/tomcat2/bin/startup.sh
chmod +x /usr/local/tomcat_instance/tomcat2/bin/startup.sh
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat1/bin/startup.sh
#!/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
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=ture -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 "$@"
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat2/bin/startup.sh
#!/bin/bash
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
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 -Xmx1024m -Djava.awt.headless=ture -Dtomcat.name=tomcat2"
#创建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 "$@"
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat1/bin/shutdown.sh
export CATALINA_HOME="/usr/local/apache-tomcat-8.5.40"
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/shutdonw.sh "$@"
[root@localhost ~]#chmod +x /usr/local/tomcat_instance/tomcat1/bin/shutdown.sh
内容差不多修改个成tomcat2
[root@localhost ~]#chmod +x /usr/local/tomcat_instance/tomcat2/bin/shutdown.sh
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat2/conf/server.xml
只要tomcat2的端口不与tomcat1的端口冲突即可
[root@localhost ~]# mkdir /usr/local/tomcat_instance/tomcat1/webapps/ROOT -p
[root@localhost ~]# mkdir /usr/local/tomcat_instance/tomcat2/webapps/ROOT -p
[root@localhost ~]# vim/usr/local/tomcat_instance/tomcat1/webapps/ROOT/index.jsp
<html>
<title>Tomcat-1</title>
<body>
Hello This is Tomcat-1.
</body>
<html>
[root@localhost ~]# vim /usr/local/tomcat_instance/tomcat2/webapps/ROOT/index.jsp
<html>
<title>Tomcat-2</title>
<body>
Hello This is Tomcat-2.
</body>
<html>
[root@localhost ~]# /usr/local/tomcat_instance/tomcat1/bin/startup.sh
[root@localhost ~]# /usr/local/tomcat_instance/tomcat2/bin/startup.sh
[root@localhost ~]# netstat -lnpt |grep java
查看是否有两个PID号不一样Java进程
测试:在网址输入
192.168.200.112:8080
192.168.200.112:8090
在做个实例很简单:
[root@localhost ~]#
[root@localhost ~]# cd /usr/local/tomcat_instance/
[root@localhost tomcat_instance]# cp -r tomcat2 tomcat3
[root@localhost ~]#
[root@localhost tomcat_instance]# vim tomcat3/bin/shutdown.sh
把2全改成3
[root@localhost tomcat_instance]# vim tomcat3/bin/startup.sh
把2全改成3
[root@localhost tomcat_instance]# rm -rf tomcat3/bin/tomcat.pid
[root@localhost ~]#
[root@localhost tomcat_instance]# vim tomcat3/conf/server.xml
该那三个端口号即可:注意不要与tomcat1和tomcat2端口号冲突
[root@localhost tomcat_instance]# vim tomcat3/webapps/ROOT/index.jsp
把里面的内容2改成3即可
[root@localhost ~]# /usr/local/tomcat_instance/tomcat3/bin/startup.sh
Java端口号变成三对
测试即可
测试时找一台nginx机器,修改配置文件