{"id":230,"date":"2010-08-02T13:02:44","date_gmt":"2010-08-02T17:02:44","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=230"},"modified":"2010-08-02T13:03:31","modified_gmt":"2010-08-02T17:03:31","slug":"having-two-tomcat-jvms","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=230","title":{"rendered":"Having two Tomcat JVMs"},"content":{"rendered":"<p>Let&#8217;s say you want to have two <a href=\"http:\/\/tomcat.apache.org\/\" target=\"_blank\">Tomcat<\/a> JVMs running. How do we do it? It&#8217;s quite easy. We only need to copy some directories and  modify the ports were we want Tomcat to run. We previously showed how to <a href=\"http:\/\/www.xavignu.com\/?p=139\" target=\"_blank\">install Tomcat<\/a>. Lets create the directory where we will make the new JVM run.<\/p>\n<pre>\r\ntomcat@debian:~$ mkdir \/opt\/tomcat\/srva\r\ntomcat@debian:~$\r\n<\/pre>\n<p>Now we copy the webapps, conf and bin directories to \/opt\/tomcat\/srva and create some directories in \/opt\/tomcat\/srva.<\/p>\n<pre>tomcat@debian:\/opt\/tomcat$ cp -R webapps\/ \/opt\/tomcat\/srva\/\r\ntomcat@debian:\/opt\/tomcat$ cp -R conf\/ \/opt\/tomcat\/srva\/\r\ntomcat@debian:\/opt\/tomcat$ cp -R bin\/ \/opt\/tomcat\/srva\/\r\ntomcat@debian:\/opt\/tomcat$ mkdir srva\/logs srva\/temp srva\/shared srva\/common srva\/work\r\n<\/pre>\n<p>We are now going to change startup ports to 8081 instead of default 8080 in \/opt\/tomcat\/conf\/server.xml. Don&#8217;t forget the shutdown port too.<\/p>\n<pre>\r\ntomcat@debian:\/opt\/tomcat$ grep -i port srva\/conf\/server.xml \r\n&lt;Server port=\"8006\" shutdown=\"SHUTDOWN\"&gt;\r\n  &lt;!-- JMX Support for the Tomcat server. Documentation at \/docs\/non-existent.html --&gt;\r\n         Define a non-SSL HTTP\/1.1 Connector on port 8080\r\n    &lt;Connector port=\"8081\" protocol=\"HTTP\/1.1\" \r\n               redirectPort=\"8444\" \/&gt;\r\n               port=\"8080\" protocol=\"HTTP\/1.1\" \r\n               redirectPort=\"8443\" \/&gt;\r\n    &lt;!-- Define a SSL HTTP\/1.1 Connector on port 8443\r\n    &lt;Connector port=\"8443\" protocol=\"HTTP\/1.1\" SSLEnabled=\"true\"\r\n    &lt;!-- Define an AJP 1.3 Connector on port 8009 --&gt;\r\n    &lt;Connector port=\"8009\" protocol=\"AJP\/1.3\" redirectPort=\"8443\" \/&gt;\r\n    &lt;!-- You should set jvmRoute to support load-balancing via AJP ie :\r\ntomcat@debian:\/opt\/tomcat$\r\n<\/pre>\n<p>Now we need to define $CATALINA_BASE and $CATALINA_HOME. The way I did is by adding them to startup.sh in the srva\/bin directory. Add the following to startup.sh.<\/p>\n<pre>\r\nCATALINA_HOME=\"\/opt\/tomcat\/\"\r\nexport CATALINA_HOME\r\nCATALINA_BASE=\"\/opt\/tomcat\/srva\"\r\nexport CATALINA_BASE\r\nJAVA_HOME=\"\/opt\/java\"\r\nexport JAVA_HOME\r\n<\/pre>\n<p>We should now be ready to go. So lets get the party started.<\/p>\n<pre>\r\ntomcat@debian:\/opt\/tomcat$ echo \"starting orig instance\"; bin\/startup.sh; echo \"starting srva new instance\"; srva\/bin\/startup.sh\r\nstarting orig instance\r\nUsing CATALINA_BASE:   \/opt\/tomcat\r\nUsing CATALINA_HOME:   \/opt\/tomcat\r\nUsing CATALINA_TMPDIR: \/opt\/tomcat\/temp\r\nUsing JRE_HOME:        \/opt\/java\r\nUsing CLASSPATH:       \/opt\/tomcat\/bin\/bootstrap.jar\r\nstarting srva new instance\r\nUsing CATALINA_BASE:   \/opt\/tomcat\/srva\r\nUsing CATALINA_HOME:   \/opt\/tomcat\/\r\nUsing CATALINA_TMPDIR: \/opt\/tomcat\/srva\/temp\r\nUsing JRE_HOME:        \/opt\/java\r\nUsing CLASSPATH:       \/opt\/tomcat\/srva\/bin\/tomcat-juli.jar:\/opt\/tomcat\/\/bin\/bootstrap.jar\r\ntomcat@debian:\/opt\/tomcat$ ps auxwww | grep -i java | grep -v grep\r\ntomcat    4759 10.4  1.3 1065228 50128 pts\/0   Sl   12:37   0:03 \/opt\/java\/bin\/java -Djava.util.logging.config.file=\/opt\/tomcat\r\n\/conf\/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=\/opt\/tomcat\/endorsed \r\n-classpath \/opt\/tomcat\/bin\/bootstrap.jar -Dcatalina.base=\/opt\/tomcat -Dcatalina.home=\/opt\/tomcat -Djava.io.tmpdir=\/opt\/tomcat\/temp \r\norg.apache.catalina.startup.Bootstrap start\r\ntomcat    4769 10.4  1.3 1064652 47872 pts\/0   Sl   12:37   0:03 \/opt\/java\/bin\/java -Djava.util.logging.config.file=\/opt\/tomcat\/srva\/conf\r\n\/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=\/opt\/tomcat\/\/endorsed \r\n-classpath \/opt\/tomcat\/srva\/bin\/tomcat-juli.jar:\/opt\/tomcat\/\/bin\/bootstrap.jar -Dcatalina.base=\/opt\/tomcat\/srva -Dcatalina.home=\/opt\r\n\/tomcat\/ -Djava.io.tmpdir=\/opt\/tomcat\/srva\/temp org.apache.catalina.startup.Bootstrap start\r\ntomcat@debian:\/opt\/tomcat$\r\n<\/pre>\n<p>We see from the ps output that there are two java processes running. So lets check on what ports they are running. They should be on 8080 and 8081.<\/p>\n<pre>\r\ntomcat@debian:\/opt\/tomcat$ lsof -i :8080\r\nCOMMAND  PID   USER   FD   TYPE DEVICE SIZE NODE NAME\r\njava    4759 tomcat   28u  IPv6  20974       TCP *:http-alt (LISTEN)\r\ntomcat@debian:\/opt\/tomcat$ lsof -i :8081\r\nCOMMAND  PID   USER   FD   TYPE DEVICE SIZE NODE NAME\r\njava    4769 tomcat   29u  IPv6  20980       TCP *:tproxy (LISTEN)\r\ntomcat@debian:\/opt\/tomcat$\r\n<\/pre>\n<p>And this is the end of this how-to. As usual suggestions are always welcome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you want to have two Tomcat JVMs running. How do we do it? It&#8217;s quite easy. We only need to copy some directories and modify the ports were we want Tomcat to run. We previously showed how to install Tomcat. Lets create the directory where we will make the new JVM run. tomcat@debian:~$ [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[20,22,6,23,49,70],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-3I","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/230"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":0,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}