{"id":443,"date":"2011-07-26T12:00:02","date_gmt":"2011-07-26T12:00:02","guid":{"rendered":"http:\/\/localhost\/wordpress\/?p=443"},"modified":"2011-07-26T12:00:02","modified_gmt":"2011-07-26T12:00:02","slug":"apache2-ajp-tomcat6","status":"publish","type":"post","link":"https:\/\/www.slips.pl\/?p=443","title":{"rendered":"apache2 ajp tomcat6"},"content":{"rendered":"<p>First off, this post is long, and hideous. It really lacks visual clarity. Only read if really desperate.<\/p>\n<p>Here&#8217;s how you put apache2 on port 80, define virtual hosts, proxypass requests over ajp port 8009 to a tomcat6 server running on port 8080 with multiple apps each on their on vhost.<br \/>\nLet me break that down into steps and explain why you&#8217;d want to do it like this. Or why I&#8217;d want to do it like this.<\/p>\n<p>At work we use some atlassian applications, like jira3, jira4, crowd, fisheye, crucible, and will probably start using bamboo, etc. Most of these come in an easy to install, prepackaged with a tomcat stack. The java-vm that tomcat runs on takes roughly ~130MB per instance, 4-5 instances that&#8217;s 500MB on just java-vms. Add the memory consumption per application on top of that. So running 3-4 tomcat instances on one machine does seem wasteful. But wait, there&#8217;s more! Each of these tomcat instances need a socket\/port to listen for traffic. So, you&#8217;ll end up with jira3 on 8080, jira4 on 8081, crowd on 8082, etc. Do you really care to remember a port per application? Think your co-workers are able to?<\/p>\n<p>Shortcut 1! Install apache2, create virtual hosts, and redirect or proxypass to the correct port. That way, you can just type http:\/\/fisheye.mycompany.com\/ and it&#8217;ll do the rest. Fixed forever!<\/p>\n<p>No? Ok, so say we manage to run them all under one tomcat instance. The typical solution would be to give each application it&#8217;s own .xml-file in \/etc\/tomcat6\/Catalina\/localhost\/ Now you can access each application under http:\/\/mycompany.com:8080\/jira4. Even better, add port 80 to your \/etc\/tomcat6\/server.xml and forget about the portnumbers all together. You&#8217;re all set!<\/p>\n<p>Not professional enough? You want those fancy http:\/\/crucible.mycompany.com\/ URLs, without the \/crucible\/ after. For this there&#8217;s vhosts. Each application will get it&#8217;s own host-entry in \/etc\/tomcat6\/server.xml Each application will get it&#8217;s own directory for additional configuration under \/etc\/tomcat6\/Catalina\/ And each application will deploy to it&#8217;s own separate directory, under \/var\/lib\/tomcat6\/webapps\/<\/p>\n<p>So with tomcat running on port 80, properly defined vhosts, there&#8217;s really no need for apache2 at all? Well, yeah. But! Say you really want to push your luck, and install some normal web application. Like phpBB, phpPgAdmin, drupal, sugarcrm, etc. You want it to be the ultimate complete mary-jane-piss-in-your-face webserver. Then you&#8217;ll want apache2 aswell.<\/p>\n<p>Below I&#8217;ll give a rough outline on vhost on tomcat, and proxypass from apache2. I might even explain what you need to do for the easier paths mentioned.<\/p>\n<h2>tomcat6<\/h2>\n<p>You might not need sun-java6, but if you do uncomment the &#8220;partner&#8221; repo in \/etc\/apt\/sources.list<\/p>\n<blockquote><p>\n<code>aptitude install tomcat6 libtcnative-1 sun-java6-jre sun-java6-jdk<\/code>\n<\/p><\/blockquote>\n<p>It&#8217;ll probably start up by default.<\/p>\n<blockquote><p>\n<code>service tomcat6 stop<\/code>\n<\/p><\/blockquote>\n<p>Change default java (you&#8217;ll want the &#8220;java-6-sun&#8221; entry.)<\/p>\n<blockquote><p>\n<code>update-alternatives --config java<\/code>\n<\/p><\/blockquote>\n<p>Change it for tomcat also; <code>\/etc\/default\/tomcat6<\/code><\/p>\n<blockquote><p>\n<code>JAVA_HOME=\/usr\/lib\/jvm\/java-6-sun<\/code>\n<\/p><\/blockquote>\n<p>Depending on the database you&#8217;ll be using;<\/p>\n<blockquote><p>\n<code>aptitude install libmysql-java libpg-java<\/code>\n<\/p><\/blockquote>\n<p>If you&#8217;re running PostgreSQL 9.0 or higher, maybe you&#8217;ll want newer versions. XXX Maybe you need symlinks from tomcat. \/usr\/share\/tomcat6\/lib\/mysql-connector-java.jar -> ..\/..\/java\/mysql-connector-java.jar<br \/>\nIn \/etc\/tomcat6\/server.xml, I like to modify this line with the addition of \/localhost, as it keeps everything neat.<\/p>\n<blockquote><p>\n<code>&lt;Host name=\"localhost\" appBase=\"webapps\/<strong>localhost<\/strong>\"<\/code>\n<\/p><\/blockquote>\n<p>You&#8217;ll also want create a localhost directory, and to move the ROOT directory there, plus set the correct permissions.<\/p>\n<blockquote>\n<pre>\nmkdir \/var\/lib\/tomcat6\/webapps\/localhost\nmkdir \/var\/lib\/tomcat6\/webapps\/jira3\nmkdir \/var\/lib\/tomcat6\/webapps\/jira4\n\nmv \/var\/lib\/tomcat6\/webapps\/ROOT \/var\/lib\/tomcat6\/webapps\/localhost\/\n\nchown -R tomcat6:tomcat6 \/var\/lib\/tomcat6\/webapps\n<\/pre>\n<\/blockquote>\n<p>Now we can create the vhosts. (To skip this step, just create application.xml file in \/etc\/tomcat6\/Catalina\/localhost\/) We start by adding entries in \/etc\/tomcat6\/server.xml (Add as many aliases as you&#8217;d like.)<\/p>\n<blockquote>\n<pre>\n&lt;Host name=\"jira3\"  appBase=\"webapps\/jira3\"\n      unpackWARs=\"true\" autoDeploy=\"true\"\n      xmlValidation=\"false\" xmlNamespaceAware=\"false\"&gt;\n  &lt;Alias&gt;jira.mycompany.com&lt;\/Alias&gt;\n  &lt;Alias&gt;jira3.mycompany.com&lt;\/Alias&gt;\n&lt;\/Host&gt;\n\n&lt;Host name=\"jira4\"  appBase=\"webapps\/jira4\"\n      unpackWARs=\"true\" autoDeploy=\"true\"\n      xmlValidation=\"false\" xmlNamespaceAware=\"false\"&gt;\n  &lt;Alias&gt;jira4.mycompany.com&lt;\/Alias&gt;\n&lt;\/Host&gt;\n<\/pre>\n<\/blockquote>\n<p>Next, we need to create directories and configurations under \/etc\/tomcat6\/Catalina<\/p>\n<blockquote>\n<pre>\nmkdir \/etc\/tomcat6\/Catalina\/jira3\nln -s \/usr\/src\/atlassian-jira-professional-3.8\/dist-tomcat\/tomcat-5.5\/jira.xml \/etc\/tomcat6\/Catalina\/jira3\/ROOT.xml\n\nmkdir \/etc\/tomcat6\/Catalina\/jira4\nln -s \/usr\/src\/atlassian-jira-enterprise-4.2\/dist-tomcat\/tomcat-6\/jira.xml \/etc\/tomcat6\/Catalina\/jira4\/ROOT.xml\n<\/pre>\n<\/blockquote>\n<h2>atlassian jira<\/h2>\n<p>Step by step for configuring, compiling and running war\/ear jira3 and jira4.<\/p>\n<p><a href=\"http:\/\/www.atlassian.com\/software\/jira\/docs\/v3.8\">Jira 3.8 Documentation<\/a><br \/>\n<a href=\"http:\/\/confluence.atlassian.com\/display\/JIRA042\">Jira 4.2 Documentation<\/a><\/p>\n<p>I&#8217;ll be providing some gotcha&#8217;s and troubleshooting information along the way.<br \/>\nOne thing common for both jiras are the need for additional libraries. jira3 guide will provide with a link to <code>jira-jars-tomcat5.zip<\/code>, jira4 will provide <code>jira-jars-tomcat6.zip<\/code> The files in both are the same, but jira4 has additional ones, so you might aswell just get <code>jira-jars-tomcat6.zip<\/code><\/p>\n<blockquote><p>\n<code>cp \/usr\/share\/jira-jars-tomcat6\/* \/usr\/share\/tomcat6\/lib\/<\/code>\n<\/p><\/blockquote>\n<p>You&#8217;ll also need to link up your database connector.<\/p>\n<blockquote><p>\ncd \/usr\/share\/tomcat6\/lib\/<br \/>\nln -s ..\/..\/java\/mysql-connector-java.jar<br \/>\nln -s ..\/..\/java\/postgresql.jar\n<\/p><\/blockquote>\n<p>Give your tomcat instance lots more memory. And pass a few more options to the JVM. \/etc\/default\/tomcat6<\/p>\n<blockquote>\n<pre>\n# You may pass JVM startup parameters to Java here. If unset, the default\n# options (-Djava.awt.headless=true -Xmx128m) will be used.\nJAVA_OPTS=\"-Djava.awt.headless=true -Xmx2048m -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=768m\"\n\n# Use a CMS garbage collector for improved response time\nJAVA_OPTS=\"${JAVA_OPTS} -XX:+UseConcMarkSweepGC\"\n\n# Atlassian JIRA Tweaks\nJAVA_OPTS=\"${JAVA_OPTS} -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -Dmail.mime.decodeparameters=true\"\n<\/pre>\n<\/blockquote>\n<h2>jira3<\/h2>\n<p>edit-webapp\/WEB-INF\/classes\/entityengine.xml For mysql you&#8217;ll need\/want to remove the schema-name line.<\/p>\n<blockquote>\n<pre>\n&lt;datasource name=\"defaultDS\" field-type-name=\"mysql\"\n      helper-class=\"org.ofbiz.core.entity.GenericHelperDAO\"\n      check-on-start=\"true\"\n      use-foreign-keys=\"false\"\n      use-foreign-key-indices=\"false\"\n      check-fks-on-start=\"false\"\n      check-fk-indices-on-start=\"false\"\n      add-missing-on-start=\"true\"\n      check-indices-on-start=\"true\"&gt;\n  &lt;jndi-jdbc jndi-server-name=\"default\" jndi-name=\"java:comp\/env\/jdbc\/Jira3DS\"\/&gt;\n&lt;\/datasource&gt;\n<\/pre>\n<\/blockquote>\n<p>For postgresql7.2 and above, use postgres72.<\/p>\n<blockquote>\n<pre>\n&lt;datasource name=\"defaultDS\" field-type-name=\"postgres72\"\n      schema-name=\"public\"\n      helper-class=\"org.ofbiz.core.entity.GenericHelperDAO\"\n      check-on-start=\"true\"\n      use-foreign-keys=\"false\"\n      use-foreign-key-indices=\"false\"\n      check-fks-on-start=\"false\"\n      check-fk-indices-on-start=\"false\"\n      add-missing-on-start=\"true\"\n      check-indices-on-start=\"true\"&gt;\n  &lt;jndi-jdbc jndi-server-name=\"default\" jndi-name=\"java:comp\/env\/jdbc\/Jira3DS\"\/&gt;\n&lt;\/datasource&gt;\n<\/pre>\n<\/blockquote>\n<p>You&#8217;ll note I&#8217;ve changed the jndi-name for our source to Jira3DS.<br \/>\nHere&#8217;s a little workaround. If you see the atlassian-jira.log<\/p>\n<p>cp webapp\/WEB-INF\/classes\/log4j.properties edit-webapp\/WEB-INF\/classes\/log4j.properties<\/p>\n<p>Edit the file, look for this line and modify it.<\/p>\n<p>log4j.appender.filelog.File=\/var\/local\/jira3\/log\/atlassian-jira.log<\/p>\n<p>Have a look at etc\/tomcat-6-jira.xml and perhaps etc\/jira.xml<\/p>\n<p>Then create a symlink from dist-tomcat\/tomcat-5.5\/jira.xml, to \/etc\/tomcat6\/Catalina\/jira3\/ROOT.xml<br \/>\nmysql version<\/p>\n<blockquote>\n<pre>\n&lt;!--\nA sample configuration file for Tomcat 5.5\nCustomize the docBase attribute, drop in your $CATALINA_HOME\/conf\/Catalina\/localhost\/jira.xml\nNote the JOTM dependencies; you'll need to copy various jars to Tomcat's common\/lib\/ directory.\n--&gt;\n&lt;Context path=\"\/jira3\" docBase=\"\/usr\/src\/atlassian-jira-professional-3.8\/dist-tomcat\/atlassian-jira-3.8.war\" debug=\"0\"&gt;\n\n    &lt;!-- NOTE: If you use a database other than hsqldb:\n    * delete the minEvictableIdleTimeMillis and timeBetweenEvictionRunsMillis attributes\n    * change the database type in atlassian-jira\/WEB-INF\/classes\/entityengine.xml\n    --&gt;\n    &lt;Resource name=\"jdbc\/Jira3DS\" auth=\"Container\" type=\"javax.sql.DataSource\"\n            username=\"jira3db\"\n            password=\"jira3db-password\"\n            driverClassName=\"org.gjt.mm.mysql.Driver\"\n            url=\"jdbc:mysql:\/\/localhost\/jira3db?useUnicode=true&characterEncoding=UTF8\"\n            maxActive=\"20\"\n            validationQuery=\"select 1\"\/&gt;\n&lt;!--        driverClassName=\"org.mysql.jdbc.Driver\" --&gt;\n\n    &lt;Resource name=\"UserTransaction\" auth=\"Container\" type=\"javax.transaction.UserTransaction\"\n    factory=\"org.objectweb.jotm.UserTransactionFactory\" jotm.timeout=\"60\"\/&gt;\n&lt;!--&lt;Manager className=\"org.apache.catalina.session.PersistentManager\" saveOnRestart=\"false\"\/&gt;--&gt;\n    &lt;Manager pathname=\"\"\/&gt;\n\n&lt;\/Context&gt;\n<\/pre>\n<\/blockquote>\n<p>postgres version<\/p>\n<blockquote>\n<pre>\n&lt;!--\n  A sample configuration file for Tomcat 5.5\n  Customize the docBase attribute, drop in your $CATALINA_HOME\/conf\/Catalina\/localhost\/jira.xml\n  Note the JOTM dependencies; you'll need to copy various jars to Tomcat's common\/lib\/ directory.\n  --&gt;\n&lt;Context path=\"\/jira3\" docBase=\"\/usr\/src\/atlassian-jira-professional-3.8\/dist-tomcat\/atlassian-jira-3.8.war\" debug=\"0\"&gt;\n\n    &lt;!-- NOTE: If you use a database other than hsqldb:\n    * delete the minEvictableIdleTimeMillis and timeBetweenEvictionRunsMillis attributes\n    * change the database type in atlassian-jira\/WEB-INF\/classes\/entityengine.xml\n    --&gt;\n    &lt;Resource name=\"jdbc\/Jira3DS\" auth=\"Container\" type=\"javax.sql.DataSource\"\n            username=\"jira3db\"\n            password=\"jira3db-password\"\n            driverClassName=\"org.postgresql.Driver\"\n            url=\"jdbc:postgresql:\/\/localhost\/jira3db\"\/&gt;\n\n    &lt;Resource name=\"UserTransaction\" auth=\"Container\" type=\"javax.transaction.UserTransaction\"\n    factory=\"org.objectweb.jotm.UserTransactionFactory\" jotm.timeout=\"60\"\/&gt;\n    &lt;Manager className=\"org.apache.catalina.session.PersistentManager\" saveOnRestart=\"false\"\/&gt;\n&lt;\/Context&gt;\n<\/pre>\n<\/blockquote>\n<p>NOTE: jira3 does not have the &#8220;jira.home&#8221; entry in jira-application.properties, whilst jira4 does. You&#8217;ll be able to specify the jira.home locations during setup of jira3. I recommend the following; (jira4 defaults.)<\/p>\n<blockquote>\n<pre>\n\/var\/local\/jira3\/caches\/indexes   # indexing\n\/var\/local\/jira3\/data\/attachments # attachments\n\/var\/local\/jira3\/export           # backups\n<\/pre>\n<\/blockquote>\n<p>The reasonable thing to do is to create two directories, and give ownership to tomcat6. \/var\/local has default group &#8220;staff&#8221;.<\/p>\n<blockquote>\n<pre>\nmkdir \/var\/local\/jira3\nmkdir \/var\/local\/jira4\n\nchown -R tomcat6:staff \/var\/local\/jira*\n<\/pre>\n<p><\/blockqquote><\/p>\n<h2>jira4<\/h2>\n<p>For postgresql7.2 and above, use postgres72.<\/p>\n<blockquote>\n<pre>\n&lt;datasource name=\"defaultDS\" field-type-name=\"postgres72\"\n      schema-name=\"public\"\n      helper-class=\"org.ofbiz.core.entity.GenericHelperDAO\"\n      check-on-start=\"true\"\n      use-foreign-keys=\"false\"\n      use-foreign-key-indices=\"false\"\n      check-fks-on-start=\"false\"\n      check-fk-indices-on-start=\"false\"\n      add-missing-on-start=\"true\"\n      check-indices-on-start=\"true\"&gt;\n  &lt;jndi-jdbc jndi-server-name=\"default\" jndi-name=\"java:comp\/env\/jdbc\/Jira4DS\"\/&gt;\n&lt;\/datasource&gt;\n<\/pre>\n<\/blockquote>\n<p>You&#8217;ll note I&#8217;ve changed the jndi-name for our source to Jira4DS.<\/p>\n<p>Editing edit-webapp\/WEB-INF\/classes\/jira-application.properties<\/p>\n<p>jira.home = \/var\/local\/jira4<br \/>\nHave a look at etc\/tomcat-6-jira.xml and perhaps etc\/jira.xml<\/p>\n<blockquote>\n<pre>\n&lt;!--\nA sample configuration file for Tomcat 6\nCustomize the docBase attribute, drop in your $CATALINA_HOME\/conf\/Catalina\/localhost\/jira.xml\nNote the JOTM dependencies; you'll need to copy various jars to Tomcat's common\/lib\/ directory.\n--&gt;\n&lt;Context path=\"\/jira4\" docBase=\"\/usr\/src\/atlassian-jira-enterprise-4.2\/dist-tomcat\/tomcat-6\/atlassian-jira-4.2.war\" debug=\"0\" useHttpOnly=\"true\"&gt;\n\n    &lt;!-- NOTE: If you use a database other than hsqldb:\n    * delete the minEvictableIdleTimeMillis and timeBetweenEvictionRunsMillis attributes\n    * change the database type in atlassian-jira\/WEB-INF\/classes\/entityengine.xml\n    --&gt;\n    &lt;Resource name=\"jdbc\/Jira4DS\" auth=\"Container\" type=\"javax.sql.DataSource\"\n            username=\"jira4db\"\n            password=\"jira4db-password\"\n            driverClassName=\"org.postgresql.Driver\"\n            url=\"jdbc:postgresql:\/\/localhost\/jira4db\"\n            maxActive=\"20\"\n            validationQuery=\"select 1\"\/&gt;\n&lt;!--        driverClassName=\"org.mysql.jdbc.Driver\" --&gt;\n\n    &lt;Resource name=\"UserTransaction\" auth=\"Container\" type=\"javax.transaction.UserTransaction\"\n    factory=\"org.objectweb.jotm.UserTransactionFactory\" jotm.timeout=\"60\"\/&gt;\n&lt;!--&lt;Manager className=\"org.apache.catalina.session.PersistentManager\" saveOnRestart=\"false\"\/&gt;--&gt;\n    &lt;Manager pathname=\"\"\/&gt;\n&lt;\/Context&gt;\n<\/pre>\n<\/blockquote>\n<p>and build the damn thing.<\/p>\n<p>cd \/usr\/src\/atlassian-jira-enterprise-4.2\/ .\/build.sh<br \/>\nNext thing is to configure your jira.xml context. I pretty much just edit the dist-tomcat\/tomcat-6\/jira.xml, and create a symlink to it called \/etc\/tomcat6\/Catalina\/jira4\/ROOT.xml<\/p>\n<p>Hopefully you&#8217;ll notice I&#8217;ve replaced driverClassName. To determine this, I extracted \/usr\/share\/java\/mysql-connector-java.jar (it&#8217;s a normal zip file), and found mysql-connector-java\/org\/gjt\/mm\/mysql\/Driver.class<\/p>\n<h2>apache2<\/h2>\n<blockquote>\n<pre>\naptitude install apache2 apache2-mpm-prefork<\/code>\na2enmod proxy proxy_ajp\n<\/pre>\n<\/blockquote>\n<p>add jira3 and jira4 to <code>\/etc\/hosts<\/code><\/p>\n<blockquote>\n<pre>\n127.0.0.1       jira3.mycompany.com jira3\n127.0.0.1       jira4.mycompany.com jira4\n<\/pre>\n<\/blockquote>\n<p>This will enable the vhost on tomcat to respont correctly when apache2 proxypasses. \/etc\/apache\/sites-available\/jira3<\/p>\n<blockquote>\n<pre>\n&lt;VirtualHost *:80&gt;\n        ServerName jira3.mycompany.com\n        ServerAlias jira.mycompany.com\n\n        &lt;Proxy *&gt;\n                Order deny,allow\n                Allow from all\n        &lt;\/Proxy&gt;\n\n#       ProxyPreserveHost on\n        ProxyRequests off\n\n        ProxyPass        \/ ajp:\/\/jira3:8009\/\n        ProxyPassReverse \/ ajp:\/\/jira3:8009\/\n&lt;\/VirtualHost&gt;\n<\/pre>\n<\/blockquote>\n<p>Remember to enable the ajp connector in \/etc\/tomcat6\/server.xml<\/p>\n<blockquote>\n<pre>\n&lt;!-- Define an AJP 1.3 Connector on port 8009 --&gt;\n&lt;Connector port=\"8009\" protocol=\"AJP\/1.3\" redirectPort=\"8443\" \/&gt;\n<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>First off, this post is long, and hideous. It really lacks visual clarity. Only read if really desperate. Here&#8217;s how you put apache2 on port 80, define virtual hosts, proxypass requests over ajp port 8009 to a tomcat6 server running on port 8080 with multiple apps each on their on vhost. Let me break that &hellip; <a href=\"https:\/\/www.slips.pl\/?p=443\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">apache2 ajp tomcat6<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-443","post","type-post","status-publish","format-standard","hentry","category-sysadmin"],"_links":{"self":[{"href":"https:\/\/www.slips.pl\/index.php?rest_route=\/wp\/v2\/posts\/443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.slips.pl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.slips.pl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.slips.pl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.slips.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=443"}],"version-history":[{"count":0,"href":"https:\/\/www.slips.pl\/index.php?rest_route=\/wp\/v2\/posts\/443\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.slips.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.slips.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.slips.pl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}