Tomcat7 multi instance

apt-get install tomcat7

apt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin tomcat7-user

Created for you:
Creating config file /etc/default/tomcat7 with new version
Adding system user `tomcat7' (UID 107) …
Adding new user `tomcat7' (UID 107) with group `tomcat7' …

apt-get install tomcat7-docs tomcat7-examples tomcat7-admin tomcat7-user

# find / -name "tomcat-users.xml"
There will be 2 tomcat-users.xml
• /etc/tomcat7/tomcat-users.xml is for the site created on port 8080
• /usr/share/tomcat7/skel/conf/tomcat-users.xml is the default used for create instance.

vi /etc/tomcat7/tomcat-users.xml (be sure to change user and password)
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="user" password="password" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

Restart tomcat:
/etc/init.d/tomcat7 restart

CD to the directory where you want to put the new instance.
mkdir /etc/tomcat7inst
cd /etc/tomcat7inst

tomcat7-instance-create -p 8100 -c 8105 810
You are about to create a Tomcat instance in directory '810'
* New Tomcat instance created in 810
* You might want to edit default configuration in 810/conf
* Run 810/bin/startup.sh to start your Tomcat instance

Modify/verify

/etc/tomcat7inst/810/conf/server.xml
<Server port="8105" shutdown="SHUTDOWN">
<Connector port="8100" protocol="HTTP/1.1"
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />

Modify/verify

/etc/tomcat7inst/810/conf/ tomcat-users.xml (same as above).

To get ROOT app
cp -r /var/lib/tomcat7/webapps/ROOT/ /etc/tomcat7inst/810/webapps/
Restart tomcat:

./810/bin/shutdown.sh
./810/bin/startup.sh
/etc/init.d/tomcat7 restart

To get manager sites to work
cp /etc/tomcat7/Catalina/localhost/* /etc/tomcat7inst/810/conf/Catalina/localhost/
Restart tomcat:

./810/bin/shutdown.sh
./810/bin/startup.sh
/etc/init.d/tomcat7 restart


When doing a deploy, be sure to cleanup…
rm -rf /etc/tomcat7inst/810/work/Catalina/
rm –rf /etc/tomcat7inst/810/temp/

=======================================================

Make Tomcat auto-start on boot (optional)

Now you should create an INIT-File that makes it possible to start, stop and restart your Tomcat Server. This file must be located in your “/etc/init.d/” directory. You can use the following command to create a file called “tomcat” and open up that file in an editor (I used nano).

vi /etc/init.d/tomcat8x0 (example here tomcat8x0 (519.00 bytes)). For a better script look at http://wiki.debian.org/LSBInitScripts or and example /etc/init.d/skeleton

Make sure you set the right paths for the startup.sh and shutdown.sh scripts. They reside in the /bin directory of your tomcat path (use the path to which you moved the tomcat files

chmod 755 /etc/init.d/tomcat8x0

update-rc.d tomcat8x0 defaults (you must cd to /etc/init.d/ for this to work)

You can remove the autostart with the following command:

update-rc.d -f tomcat8x0 remove (you must cd to /etc/init.d/ for this to work)


Now the Tomcat Server starts automatically at system bootup.

If you wish to start/stop Tomcat Server manually like this:
sudo /etc/init.d/tomcat8x0 start

sudo /etc/init.d/tomcat8x0 stop


Tag Cloud