我的系统里面原本就有一份 Tomcat ,名称为 tomcat8
:
wxs@ubuntu:/usr/local$ ls
bin games jdk1.8.0_161 man redis share tomcat8
etc include lib nginx sbin src zookeeper-3.5.2-alpha
注:本篇文章只使用两台 Tomcat ,配置更多个同理。
复制两份,分别为 tomcat-jit
和 tomcat-wxs
:
wxs@ubuntu:/usr/local$ sudo cp -r tomcat8/ tomcat8-jit
wxs@ubuntu:/usr/local$ sudo cp -r tomcat8/ tomcat8-wxs
wxs@ubuntu:/usr/local$ ls
bin include man sbin tomcat8 zookeeper-3.5.2-alpha
etc jdk1.8.0_161 nginx share tomcat8-jit
games lib redis src tomcat8-wxs
配置多个Tomcat需要修改 3个 地方的端口信息,分别是:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
下面修改这两个tomcat的端口信息:
(1)对于 tomcat8-jit:
wxs@ubuntu:/usr/local$ sudo vim tomcat8-jit/conf/server.xml
(2)对于 tomcat8-wxs:
wxs@ubuntu:/usr/local$ sudo vim tomcat8-wxs/conf/server.xml
如果只修改了那三个端口信息,启动某一个,另外一个无法启动,因为默认只使用了同一个环境变量,需要为每一个tomcat配置环境变量。
修改 /etc/profile
文件,在尾部添加环境变量:
####第一个Tomcat####
export CATALINA_JIT_BASE=/usr/local/tomcat8-jit
export CATALINA_JIT_HOME=/usr/local/tomcat8-jit
export TOMCAT_JIT_HOME=/usr/local/tomcat8-jit
####第二个Tomcat####
export CATALINA_WXS_BASE=/usr/local/tomcat8-wxs
export CATALINA_WXS_HOME=/usr/local/tomcat8-wxs
export TOMCAT_WXS_HOME=/usr/local/tomcat8-wxs
修改每个 tomcat 下的 bin/catalina.sh
文件,找到下面代码:
# OS specific support. $var _must_ be set to either true or false.
在下面添加对应的 CATALINA_BASE
和 CATALINA_HOME
:
(1)对于 tomcat8-jit:
# myself : add
export CATALINA_BASE=$CATALINA_JIT_BASE
export CATALINA_HOME=$CATALINA_JIT_HOME
(2)对于 tomcat8-wxs:
# myself : add
export CATALINA_BASE=$CATALINA_WXS_BASE
export CATALINA_HOME=$CATALINA_WXS_HOME
修改两个 Tomcat 首页以便测试区分:
wxs@ubuntu:/usr/local$ sudo vim tomcat8-jit/webapps/ROOT/index.jsp
wxs@ubuntu:/usr/local$ sudo vim tomcat8-wxs/webapps/ROOT/index.jsp
我的服务器IP是 192.168.30.149
,分别访问 192.168.30.149:8090
和 192.168.30.149:8091
: