tomcat部署多实例

关闭主站

[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))
浏览器访问

http://10.18.45.133:8081
在这里插入图片描述

http://10.18.45.133:8082
在这里插入图片描述

http://10.18.45.133:8083
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值