Usually Tomcat is really simple to handle – download, extract, start and forget about it. If you need multiple instances of Tomcat on the same machine for performance reasons (if i.e. the database or the file system is the bottleneck) then you usually simply copy the extracted tree, modify some config (server.xml to have different HTTP ports), start it and forget it.
However if you want to rely on the standard rpm (“yum install tomcat5″) this approach does not work very well – the rpm install distributes the tomcat files across the file system. Some parts are in /usr/share, some in /etc/ and the logs are of course in /var/log/. So how do you modify this system to be able to run multiple instances and also benefit from updates that Redhat releases? (And btw, this guide should also apply for other systems, i.e. Ubuntu or CentOS.)
Here is how to do it:
- Copy the config files from /etc/tomcat5 to this folder: /etc/tomcat5.1
- Modify the /etc/tomcat5.1/server.xml to have unique ports
- Create a log directory: /var/log/tomcat5.1 and make sure the group is set to tomcat
- Create cache directories /var/cache/tomcat5.1/temp and /var/cache/tomcat5.1/work and make sure the group is set to tomcat
- Create a copy of the /usr/share/tomcat5 directory as /usr/share/tomcat5.1 and modify the symlinks in there to point to the newly created folders (conf, logs, temp, work) and remove the bin/ directory and symlink it to /usr/share/tomcat5/bin
- Copy /etc/sysconfig/tomcat5 as /etc/sysconfig/tomcat5.1 and replace all instances of “tomcat5″ with “tomcat5.1″ within that file
- Copy the /etc/init.d/tomcat5 as /etc/init.d/tomcat5.1 and replace all instances of “/tomcat5″ with “/tomcat5.1″ within that file
Once these steps are executed you can start the new instance using “service tomcat5.1 start”. This works for any number of instances and will share the Web apps as well (so no multiple deployments needed) and should improve performance if you use Apache + mod_jk in front of Tomcat.