- CATALINA_HOME是Tomcat的安装目录,CATALINA_BASE是Tomcat的工作目录。如果我们想要运行Tomcat的 多个实例,但是不想安装多个Tomcat软件副本。那么我们可以配置多个工作目录,每个运行实例独占一个工作目录,但是共享同一个安装目录。
- Tomcat每个运行实例需要使用自己的conf、logs、temp、webapps、work和shared目录,因此CATALINA_BASE就指向这些目录。
- 而其他目录主要包括了Tomcat的二进制文件和脚本,CATALINA_HOME就指向这些目录。
- 如果我们希望再运行另一个Tomcat实例,那么我们可以建立一个目录,把conf、logs、temp、webapps、work拷贝到该目录下,然后让CATALINA_BASE指向该目录即可
在一台服务器上,可以运行多个tomcat实例,不需要安装多个tomcat,可以采用不同的用户,以meth01用户为例,
root 用户/usr/local/apache-tomcat- 6.0.18 存放完整tomcat 资源、工作目录。
drwxr-xr-x. 2 root root 4096 Aug 23 12:05 bin
drwxr-xr-x. 3 root root 4096 Aug 23 09:34 conf
drwxr-xr-x. 2 root root 4096 Aug 23 09:34 lib
-rw-r--r--. 1 root root 56846 Aug 23 09:34 LICENSE
drwxr-xr-x. 2 root root 4096 Aug 23 10:27 logs
-rw-r--r--. 1 root root 1239 Aug 23 09:34 NOTICE
-rw-r--r--. 1 root root 8965 Aug 23 09:34 RELEASE-NOTES
-rw-r--r--. 1 root root 16195 Aug 23 09:34 RUNNING.txt
drwxr-xr-x. 2 root root 4096 Aug 23 09:34 temp
drwxr-xr-x. 8 root root 4096 Aug 23 09:34 webapps
drwxr-xr-x. 3 root root 4096 Aug 23 09:34 work
[root@192 apache-tomcat-7.0.73]#
并且将CATALINA_HOME,JAVA_HOME 或者JRE_HOME配置在.bash_profile 环境配置变量文件中。
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
CATALINA_HOME=/usr/local/apache-tomcat-7.0.73
JRE_HOME=/usr
export PATH
export CATALINA_HOME
export JRE_HOME
- 拷贝/usr/local/apache-tomcat- 6.0.18目录到/home/meth01下。
- 删除/home/meth01/apache-tomcat-6.0.18/bin(此目录不需要)。
- 编辑 /home/test/.bash_profile文件,设置CATALINA_HOME指向刚才的安装目录/usr/local/apache- tomcat-6.0.18,设置JAVA_HOME指向刚才的安装目录。设置CATALINA_BASE指 向/home/meth01/apache-tomcat-6.0.18。
Server port=”8015” shutdown=”SHUTDOWN”
Connector port=”8080” protocol=”HTTP/1.1”
Connector port=”8019” protocol=”AJP/1.3” redirectPort=”8443”
4. 自定义启动脚本。
#!/bin/bash
start_tomcat=$CATALINA_HOME/bin/startup.sh
${start_tomcat}
5. 配置meth01 环境变量
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
CATALINA_HOME=/usr/local/apache-tomcat-7.0.73
CATALINA_BASE=/home/meth01/apache-tomcat-7.0.73
JRE_HOME=/usr
export PATH
export CATALINA_HOME
export CATALINA_BASE
export JRE_HOME
6. 浏览器访问如下地址
localhost:8080
localhost:9080
均正常访问。
总结:
棘突不同的系统用户,不同的Tomcat实例使用相同的tomcat 资源文件,但是配置文件在单独实例工作目录当中做配置。