Tomcat Multiple Instances RHEL 7 CentOS 7

This is a follow-on to my earlier posts Apache Tomcat in RHEL 7 and RHEL 7 Administration Notes. This builds on the goal to use the system packaged Tomcat and Java software in order to receive security and bug fix updates from when the distribution posts those to the supported yum repositories. In this case, we’re leveraging the advanced “Multiple Tomcat Instances” capability included with Tomcat 7 as packaged by Red Hat for RHEL 7 and CentOS 7 Linux Distributions. It appears that the RHEL team has done the work to ensure that the supported package does enable multiple Tomcats if you follow a combination of the offical Apache Tomcat 7 “RUNNING” document (linked above) along with some of the comments provided with the RHEL Tomcat 7 configuration files. There is not a single place where this documentation was combined in a practical way, so here are my brief notes to help tie it all together.

  • REPLACE all occurrences of “INSTANCE” below with your true instance name. An example instance name might be “geoserver.”
  • Global configuration for ALL Tomcat Instances is provided in /etc/tomcat/tomcat.conf – any changes made here will be reflected across your entire “cat farm.”
  • Instance-Specific systemd (systemctl) Tomcat services are defined by creating new files like /usr/lib/systemd/system/tomcat@INSTANCE.service – copy the existing /usr/lib/systemd/system/tomcat@.service template file and alter for your instance. You can modify the instance Description, User and Group here.
  • Instance-Specific Environment Variables are defined by creating new files like /etc/sysconfig/tomcat@INSTANCE – copy existing /etc/sysconfig/tomcat. By default everything is commented out in this file. Use conf/server.xml changes listed below to set the ports used when a given instance of Tomcat runs.
    • To SET MAXIMUM MEMORY for specific tomcat instance, place a new line in /etc/sysconfig/tomcat@INSTANCE like the following for 8G max
    • CATALINA_OPTS="-Xmx8G"
  • Instance-Specific CATALINA_BASE directory is pre-defined to go under /var/lib/tomcats/INSTANCE – note the “Mimic” below means (use similar permissions scheme, expect similar contents when service is running).
    • Create a “conf” directory here
      • Should contain a COPY of contents of /etc/tomcat
      • CHANGE “server.xml” here to reflect instance-specific ports!!
    • Create a “logs” directory here
      • Mimic /var/log/tomcat
      • Add /etc/logrotate.d/tomcat@INSTANCE as needed
    • Create a “webapps” directory here
      • Mimic /var/lib/tomcat/webapps
      • Drop your app WAR files or app context directories here to deploy.
    • Create a “work” directory here
      • Mimic /var/cache/tomcat/work
    • Create a “temp” directory here
      • Mimic /var/cache/tomcat/temp
  • If SELinux is enabled, you may need to set the correct security context on the above instance-specific folders and files in addition to setting the instance-specific permissions based on the user & group the service runs as.
  • Manage with the standard systemctl commands like:
    • systemctl status tomcat@INSTANCE
    • systemctl enable tomcat@INSTANCE # enable start-on-boot
    • systemctl start tomcat@INSTANCE # start instance right now
    • systemctl stop tomcat@INSTANCE # stop instance right now

Good luck with your multi-instance Tomcat project on RHEL 7 or CentOS 7. By using a pattern similar to this, you should be able to take advantage of Red Hat provided security and bug-fix yum updates for your Java Servlet and JSP web apps. If you’re using the single default instance of Tomcat, see my earlier post linked at the top of this article.

Advertisements

About notesbytom

Keeping technology notes on WordPress.com to free up my mind to solve new problems rather than figuring out the same ones repeatedly :-).
This entry was posted in Linux, System Administration and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s