关闭主站
[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
准备多实例主目录
[root@dell710 ~]# mkdir /usr/local/tomcat/instance{1…3}
制作实例工作目录
[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/
查看目录结构
[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
修改端口
将web配置文件拷贝三份。分别修改为不同端口
[root@dell710 ~]# vim /usr/local/tomcat/instance1/conf/server.xml
1)
<!-- <Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" /> -->
服务端口 8080 替换成 8081
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2)
<!-- <Server port="8005" shutdown="SHUTDOWN"> -->
程序工作端口:8005替换成 8091
<Server port="8091" shutdown="SHUTDOWN">
3)
appBase="webapps"
网站目录:webapps 替换成 另一个目录
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"
服务端口 替换成 8082
<Connector port="8082" protocol="HTTP/1.1"
2)
<Server port="8091" shutdown="SHUTDOWN">
程序工作端口 替换成 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"
替换成
<Connector port="8083" protocol="HTTP/1.1"
2)
<Server port="8091" shutdown="SHUTDOWN">
替换成
<Server port="8093" shutdown="SHUTDOWN">
启动脚本
[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’
赋权
[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
网站源码
[root@dell710 ~]# mkdir /webapps
[root@dell710 ~]# cp -r /usr/local/tomcat/webapps/ROOT/ /webapps/
启动
[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.
测试
[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))
浏览器访问