lamp

Well-Known Member
Dec 22, 2003
111
0
166
Does cpanel 11 install tomcat so that each virtual host has it's own instance?
 

lamp

Well-Known Member
Dec 22, 2003
111
0
166
No.

There is one main Tomcat process and several children.
Actually, I was able to get 5 instances of tomcat running on cpanel 11... and it really works like a charm.

In Summary:
---------------
I have the main tomcat installed (CATALINA_HOME) in /usr/local/jakarta/tomcat (symlinked to whatever version I want) and 5 instances with their own webapps,logs,conf, and temp (CATALINA_BASE). This is great because it means that each instance has their own manager, users, and are completely independent of one another. Also, if I upgrade tomcat, then there is no need to upgrade five of them... just CATALINA_HOME and all the others are automatically upgraded (saves space too).

Another advantage is that I can also start, stop, restart each individual instance without bothering other clients on tomcat.

Yes, to get things setup properly does take a little more work because I have to create distinct ajp13 worker for each instance... but the advantages are huge.

Thanks.
 

lamp

Well-Known Member
Dec 22, 2003
111
0
166
If anyone is looking to have 1 main tomcat and many instances running, let me know and I can post a how-to.

It's fairly straightforward.

Lamp.
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,607
79
458
cPanel Access Level
Root Administrator
Well sure, if you do the other 4 installs manually. But that wasn't the question. You can also run multiple Tomcat instances from the same CATALINA_HOME locaiton using jsvc. Check out http://miti.sourceforge.net/ for example.
 

rgrocha

Member
Aug 9, 2007
7
1
53
If anyone is looking to have 1 main tomcat and many instances running, let me know and I can post a how-to.

It's fairly straightforward.

Lamp.
I'm interested!
 

lamp

Well-Known Member
Dec 22, 2003
111
0
166
HOWTO: Install multiple tomcat instances with cPanel x.xx

Here's why you would want to do this:
==============================
1) Install tomcat in 1 location and have x number of instances running on a per client basis
2) Upgrade tomcat and have it propagate to all clients
3) Limit the resources each tomcat instance uses
4) Tomcat runs as the individual user rather than "root" or "tomcat"
5) Each user has its own manager; hence, no security risk to others
6) Start/Stop/Restart tomcat instances without affecting other clients who also have a tomcat instance

Assumptions:
============
1. Tomcat is installed in: /usr/local/tomcat (TOMCAT_HOME)
2. Instances are installed in: /usr/local/tomcat/instances
3. Java is installed somewhere on your machine

Step 1 - Create a Tomcat Instance
=================================
- Create a directory in /usr/local/tomcat/instances/user1 (CATALINA_BASE)
- Create a set of directories (conf,temp,logs,webapps) in $CATALINA_BASE
- Copy web.xml,server.xml,tomcat-users.xml from $TOMCAT_HOME/conf to $CATALINA_BASE/conf
- Create a bash script called user1startstop.sh as follows and make it executable
#!/bin/bash
export INSTANCE_NAME=user1
export CATALINA_BASE=/usr/local/tomcat/instances/user1
#This is where you'd be able to restrict the memory usage
export CATALINA_OPTS=" -Djava.awt.headless=true"
# Call the jsvc script to launch the Tomcat instance
/usr/local/tomcat/bin/Tomcat5.sh $1
Step 2 - Configure the Tomcat Instance
======================================
- edit $TOMCAT_BASE/conf/server.xml:

Replace: ... port=8005 with port 8101 ... This is shutdown port
Replace: ... port=8080 with port 8201 ... This is http port
Replace: ... port=8009 with port 8301 ... This is the AJP port

- edit $TOMCAT_HOME/conf/workers.properties

Add: user1 to worker.list=ajp12,ajp13...
Add:
worker.user1.host=localhost
worker.user1.port=8301
worker.user1.lbfactor=1
worker.user1.type=ajp13
Under:
DEFAULT ajp13 WORKER DEFINITION

Step 3 - Modify Main Tomcat (One-Time)
======================================
Edit $TOMCAT_HOME/bin/Tomcat5.sh

Add:
DAEMON_HOME=/usr/local/tomcat/bin
PIDFILE=/var/run/jsvc-$INSTANCE_NAME.pid
TMP_DIR=/usr/local/jakarta/servers/$INSTANCE_NAME/temp
TOMCAT_USER=$INSTANCE_NAME
Modify start case with the following:
$DAEMON_HOME/jsvc \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-outfile $CATALINA_BASE/logs/catalina.out \
-errfile $CATALINA_BASE/logs/catalina.err \
-pidfile "$PIDFILE" \
\
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap \
;;
Modify end case with the following:
PID=`cat $PIDFILE`
kill $PID
rm $PIDFILE
;;
Step 3 - Configure Apache
=========================

- Edit httpd.conf
Add the following code under the VirtualHost definition of the user in question:
<IfModule mod_jk.c>
JkMount /*.jsp user1
JkMount /webapps/* user1
JkMount /servlets/* user1
JkMount /servlet/* user1
</IfModule>


Step 4 - Restart Apache

Step 5 - run $TOMCAT_INSTANCE/user1startstop.sh start

That's it.
 

wisperz

Registered
Oct 26, 2007
2
0
51
Problem Configuring Multi Instance Tomcat

Hi,

Before Setting Multi Instance Tomcat:

I already install tomcat using cpanel /easyapache installer, I can assign user with [Install Servlet] link in WHM and it works already [can display the jsp test page].
But according to one of my user it is only JSP and not servlet since it can not load .do file.

I hope after Setting Multi Install Tomcat, I can provide servlet ready function to my user but still fail.

I have follow all your configuration detail but still can't running usr1startstop.sh.

The warning is: jsvc Invalid name - 'collabs

-Dcatalina-home : file / directory not found
-Dcatalina-home : file / directory not found

Notes:
I change all user1 to collabs [collabs is one of my user's username]
I use jakarta/tomcat folder instead of tomcat only.

Please help.
Thanks.
 

lamp

Well-Known Member
Dec 22, 2003
111
0
166
Hi,
But according to one of my user it is only JSP and not servlet since it can not load .do file.
Add /*.do like this:

<IfModule mod_jk.c>
JkMount /*.jsp user1
JkMount /webapps/* user1
JkMount /servlets/* user1
JkMount /servlet/* user1
JkMount /*.do user1
</IfModule>
 

Vinayak

Well-Known Member
Jun 27, 2003
281
4
168
Bharat
cPanel Access Level
Root Administrator
It seems there is a bug somewhere or may be some misconfiguration, this is what I am getting (TomCat installed by WHM):

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:
JSP FileName:/Menus/AdminMenu.jsp
Java FileName:/usr/local/jakarta/apache-tomcat-5.5.25/work/Catalina/sakariya.com/JSP//org/apache/jsp/Menus/AdminMenu_jsp.java

An error occurred at line: 4 in the jsp file: /Menus/AdminMenu.jsp
User cannot be resolved to a type
1: <%@page contentType="text/html"%>
2: <%@page import = 'Beans.*' %>
3: <%
4: User user = (User)session.getAttribute("user");
5: if(user == null || !user.getCurrentUserTypeRef().equals("administrato r"))
6: {
7: session.setAttribute("message", "Administrator Login failed. Please Login."); %>

JSP FileName:/Menus/AdminMenu.jsp
Java FileName:/usr/local/jakarta/apache-tomcat-5.5.25/work/Catalina/sakariya.com/JSP//org/apache/jsp/Menus/AdminMenu_jsp.java

An error occurred at line: 4 in the jsp file: /Menus/AdminMenu.jsp
User cannot be resolved to a type
1: <%@page contentType="text/html"%>
2: <%@page import = 'Beans.*' %>
3: <%
4: User user = (User)session.getAttribute("user");
5: if(user == null || !user.getCurrentUserTypeRef().equals("administrato r"))
6: {
7: session.setAttribute("message", "Administrator Login failed. Please Login."); %>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:98)
org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:435)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:298)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:277)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:265)
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
Apache Tomcat/5.5.25
whereas the index.jsp is working fine at http://www.sakariya.com

Server Information is:
WHM 11.15.0 cPanel 11.18.1-R20683
CENTOS Enterprise 4.6 i686 on virtuozzo - WHM X v3.1.0
Tomcat Version Apache Tomcat/5.5.25
JVM Version 1.6.0_02-b05
JVM Vendor Sun Microsystems Inc.
OS Name Linux
OS Version 2.6.18-53.el5.028stab051.1
OS Architecture i386
The developer says, it is not compiling JSP pages.

Any idea where it is going wrong?
 

Vinayak

Well-Known Member
Jun 27, 2003
281
4
168
Bharat
cPanel Access Level
Root Administrator
Ok I was able to fix the issue by tweaking server.xml <Host></Host> entries.

But when installed servlets on another domain through WHM it added its default <Host></Host> entries for the new domain and overwrite the tweaked entries of old domain by its default one.

Is this a bug or is it using some template somewhere?

If it is using a template from somewhere, where is it located so we can fix the template, any idea?

BTW my tweaked entries are:

<Host name="domain.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" reloadable="true">
<Alias>www.domain.com</Alias>
<Context path="" reloadable="true" docBase="/home/domain/public_html" debug="0" privileged="true" autoDeploy="true" liveDeploy="true">
<Resource name="jdbc/domain" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="test" password="test" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"/>

</Context>
</Host>
Above entry is working fine for me, application get deployed automatically without restarting TomCat, any changes made to application are also accepted without restart.

But do you people think every thing is fine in above entry, is there a better and more efficient way?

Any tips to optimise TomCat to consume less resources and for better performance?
 

rdhallman

Registered
Nov 30, 2009
1
0
51
Thanks Lamp for the HowTo about tomcat multi-instance on cpanel.

I'm trying to put it to good use, but having some issues:

Here's why you would want to do this:
Step 3 - Modify Main Tomcat (One-Time)
======================================
Edit $TOMCAT_HOME/bin/Tomcat5.sh
I have a virgin installation of CPanel and tomcat. First time it has been used. Tomcat5.5.28 is installed at /usr/local/jakarta/tomcat/

Problem is, Tomcat5.sh is not included in the bin directory. Has the latest versions of cpanel put this file elsewhere or something?



Here's why you would want to do this:
Step 3 - Configure Apache
=========================

- Edit httpd.conf
Add the following code under the VirtualHost definition of the user in question:
<IfModule mod_jk.c>
JkMount /*.jsp user1
JkMount /webapps/* user1
JkMount /servlets/* user1
JkMount /servlet/* user1
</IfModule>
Hmm... But cpanel will overwrite your edits directly to httpd.conf. As I understand it, to distill a manual modification to httpd.conf you must run /usr/local/cpanel/bin/apache_conf_distiller --update after you have saved the config file

Did you not (over time) have any such problems with cpanel overwriting your httpd.conf edits?
 
Last edited: