Close main station
[root@dell710 ~]# bash /usr/local/tomcat/bin/shutdown.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/javaUsing CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Prepare multi instance home directory
[root@dell710 ~]# mkdir /usr/local/tomcat/instance{1..3}
Create instance working directory
[root@dell710 ~]# cp -r /usr/local/tomcat/{conf,logs,temp,work} /usr/local/tomcat/instance1/ [root@dell710 ~]# cp -r /usr/local/tomcat/{conf,logs,temp,work} /usr/local/tomcat/instance2/ [root@dell710 ~]# cp -r /usr/local/tomcat/{conf,logs,temp,work} /usr/local/tomcat/instance3/
View directory structure
[root@dell710 ~]# tree -d -L 2 /usr/local/tomcat/ /usr/local/tomcat/ ├── bin ├── conf │ └── Catalina ├── instance1 │ ├── conf │ ├── logs │ ├── temp │ └── work ├── instance2 │ ├── conf │ ├── logs │ ├── temp │ └── work ├── instance3 │ ├── conf │ ├── logs │ ├── temp │ └── work ├── lib ├── logs ├── temp ├── webapps │ ├── docs │ ├── examples │ ├── host-manager │ ├── manager │ └── ROOT └── work └── Catalina 29 directories
Modify port
Make three copies of the web configuration file. Modify to different ports respectively
[root@dell710 ~]# vim /usr/local/tomcat/instance1/conf/server.xml
1)
<!-- <Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" /> -->
Replace service port 8080 with 8081
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2)
<!-- <Server port="8005" shutdown="SHUTDOWN"> -->
Program work port: 8005 replaced by 8091
<Server port="8091" shutdown="SHUTDOWN">
3)
appBase="webapps"
Website Directory: replace webapps with another directory
appBase="/webapps"
[root@dell710 ~]# cp /usr/local/tomcat/instance1/conf/server.xml /usr/local/tomcat/instance2/conf/ cp: overwrite '/usr/local/tomcat/instance2/conf/server.xml'? y [root@dell710 ~]# vim /usr/local/tomcat/instance2/conf/server.xml
1)
<Connector port="8081" protocol="HTTP/1.1"
Replace service port with 8082
<Connector port="8082" protocol="HTTP/1.1"
2)
<Server port="8091" shutdown="SHUTDOWN">
Replace program work port with 8092
<Server port="8092" shutdown="SHUTDOWN">
[root@dell710 ~]# cp /usr/local/tomcat/instance1/conf/server.xml /usr/local/tomcat/instance3/conf/ cp: overwrite '/usr/local/tomcat/instance3/conf/server.xml'? y [root@dell710 ~]# vim /usr/local/tomcat/instance3/conf/server.xml
1)
<Connector port="8081" protocol="HTTP/1.1"
Replace with
<Connector port="8083" protocol="HTTP/1.1"
2)
<Server port="8091" shutdown="SHUTDOWN">
Replace with
<Server port="8093" shutdown="SHUTDOWN">
Startup script
[root@dell710 ~]# vim /usr/local/tomcat/instance1/ins1.sh [root@dell710 ~]# cat /usr/local/tomcat/instance1/ins1.sh #!/bin/bash #instance1 . /etc/init.d/functions export CATALINA_BASE="/usr/local/tomcat/instance1" case "$1" in start) $CATALINA_HOME/bin/startup.sh ;; stop) $CATALINA_HOME/bin/shutdown.sh ;; restart) $CATALINA_HOME/bin/shutdown.sh sleep 5 $CATALINA_HOME/bin/startup.sh ;; esac export JAVA_OPTS='-Xms64m -Xmx128m'
[root@dell710 ~]# cp /usr/local/tomcat/instance1/ins1.sh /usr/local/tomcat/instance2/ins2.sh [root@dell710 ~]# vim /usr/local/tomcat/instance2/ins2.sh [root@dell710 ~]# cat /usr/local/tomcat/instance2/ins2.sh #!/bin/bash #instance2 . /etc/init.d/functions export CATALINA_BASE="/usr/local/tomcat/instance2" case "$1" in start) $CATALINA_HOME/bin/startup.sh ;; stop) $CATALINA_HOME/bin/shutdown.sh ;; restart) $CATALINA_HOME/bin/shutdown.sh sleep 5 $CATALINA_HOME/bin/startup.sh ;; esac export JAVA_OPTS='-Xms64m -Xmx128m'
[root@dell710 ~]# cp /usr/local/tomcat/instance1/ins1.sh /usr/local/tomcat/instance3/ins3.sh [root@dell710 ~]# vim /usr/local/tomcat/instance3/ins3.sh [root@dell710 ~]# cat /usr/local/tomcat/instance3/ins3.sh #!/bin/bash #instance3 . /etc/init.d/functions export CATALINA_BASE="/usr/local/tomcat/instance3" case "$1" in start) $CATALINA_HOME/bin/startup.sh ;; stop) $CATALINA_HOME/bin/shutdown.sh ;; restart) $CATALINA_HOME/bin/shutdown.sh sleep 5 $CATALINA_HOME/bin/startup.sh ;; esac export JAVA_OPTS='-Xms64m -Xmx128m'
Empowerment
[root@dell710 ~]# chmod +x /usr/local/tomcat/instance1/ins1.sh [root@dell710 ~]# chmod +x /usr/local/tomcat/instance2/ins2.sh [root@dell710 ~]# chmod +x /usr/local/tomcat/instance3/ins3.sh
Website source code
[root@dell710 ~]# mkdir /webapps [root@dell710 ~]# cp -r /usr/local/tomcat/webapps/ROOT/ /webapps/
start-up
[root@dell710 ~]# /usr/local/tomcat/instance1/ins1.sh start Using CATALINA_BASE: /usr/local/tomcat/instance1 Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/instance1/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
[root@dell710 ~]# /usr/local/tomcat/instance2/ins2.sh start Using CATALINA_BASE: /usr/local/tomcat/instance2 Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/instance2/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
[root@dell710 ~]# /usr/local/tomcat/instance3/ins3.sh start Using CATALINA_BASE: /usr/local/tomcat/instance3 Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/instance3/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
test
[root@dell710 ~]# ss -nutpl |egrep "8081|8082|8083|8091|8092|8093" tcp LISTEN 0 100 :::8081 :::* users:(("java",pid=8388,fd=48)) tcp LISTEN 0 100 :::8082 :::* users:(("java",pid=8516,fd=48)) tcp LISTEN 0 100 :::8083 :::* users:(("java",pid=8695,fd=48)) tcp LISTEN 0 1 ::ffff:127.0.0.1:8091 :::* users:(("java",pid=8388,fd=72)) tcp LISTEN 0 1 ::ffff:127.0.0.1:8092 :::* users:(("java",pid=8516,fd=62)) tcp LISTEN 0 1 ::ffff:127.0.0.1:8093 :::* users:(("java",pid=8695,fd=62))
Browser access