{"id":405,"date":"2013-05-10T17:46:08","date_gmt":"2013-05-10T17:46:08","guid":{"rendered":"http:\/\/vickistan.com\/?p=405"},"modified":"2013-05-10T20:47:35","modified_gmt":"2013-05-10T20:47:35","slug":"tomcat-stuff","status":"publish","type":"post","link":"https:\/\/vickistan.com\/?p=405","title":{"rendered":"Tomcat stuff"},"content":{"rendered":"<h1>How to connect apache and tomcat<\/h1>\n<p>mod_proxy_ajp is an Apache module which can be used to forward a client HTTP request to an internal Tomcat application server using the AJP protocol. Make sure this line is in the httpd.conf:<\/p>\n<p>LoadModule proxy_ajp_module modules\/mod_proxy_ajp.so<\/p>\n<p>Add this info into a VirtualHost:<\/p>\n<p>Listen 1989<br \/>\nNameVirtualHost *:1989<\/p>\n<p>ServerName localhost<br \/>\nErrorLog \/var\/log\/apache2\/ajp.error.log<br \/>\nCustomLog \/var\/log\/apache2\/ajp.log combined<\/p>\n<p>AddDefaultCharset Off<br \/>\nOrder deny,allow<br \/>\nAllow from all<\/p>\n<p>ProxyPass \/ ajp:\/\/localhost:8009\/<br \/>\nProxyPassReverse \/ ajp:\/\/localhost:8009\/<\/p>\n<p>Make sure that Tomcat is listening on port 8009 (will show as java listening):<\/p>\n<p>netstat -ntlp<\/p>\n<p>should show a line like:<\/p>\n<p>tcp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0 0 :::8009\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 :::*\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LISTEN\u00a0\u00a0\u00a0\u00a0\u00a0 1329\/java<\/p>\n<p>A web client will now be able to connect through HTTP to http:\/\/IPADDDR:1989\/, the mod_proxy_ajp will forward your request transparently using the AJP protocol to the tomcat application server on port 8009. Remember to open 1989 on the firewall if appropriate.<\/p>\n<p>At this point, the servlet container is ready to start processing the request. Tomcat can send the following messages back to the web server:<\/p>\n<p>SEND_HEADERS<br \/>\nSend a set of headers back to the browser.<br \/>\nSEND_BODY_CHUNK<br \/>\nSend a chunk of body data back to the browser.<br \/>\nGET_BODY_CHUNK<br \/>\nGet further data from the request if it hasn&#8217;t all been transferred yet. This is necessary because the packets have a fixed maximum size and arbitrary amounts of data can be included the body of a request (for uploaded files, for example). (Note: this is unrelated to HTTP chunked transfer).<br \/>\nEND_RESPONSE<br \/>\nFinish the request-handling cycle.<\/p>\n<h1>How to deploy a war file<\/h1>\n<p>Detemine webapps location<br \/>\nDrop sample.war in that location (sample war file is available at http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/appdev\/sample\/sample.war )<br \/>\nCheck that it deploys by checking for a directory call sample in your webapps directory<br \/>\nBrowse to http:\/\/ServerIP:8080\/sample<br \/>\nShould see &#8216;Sample &#8220;Hello, World&#8221; Application&#8217;<\/p>\n<p>Note: Any web application archive file within the application base (appBase) directory that does not have a corresponding directory of the same name (without the &#8220;.war&#8221; extension) will be automatically expanded, unless the unpackWARs property is set to false. If you redeploy an updated WAR file, be sure to delete the expanded directory when restarting Tomcat, so that the updated WAR file will be re-expanded (note that the auto deployer, if enabled, will automatically expand the updated WAR file once the previously expanded directory is removed).<\/p>\n<h1>Troubleshooting<\/h1>\n<p>Tomcat logs to $TOMCAT_HOME\/logs\/catalina.out<\/p>\n<h1>How to increase java heap size<\/h1>\n<p>If you are experiencing performance issues with Tomcat, a common cause is the lack of JVM (Java Virtual Machine) memory allocation. The default setting of the maximum heap size is 64MB or 128MB. You can increase the maximum heap size of applications by setting the -Xmx JVM parameter.<\/p>\n<p>For example -Xmx512m allows maximum 512MB heap to be allocated for the JVM.<br \/>\nCheck both CATALINA_OPTS and JAVA_OPTS environment variables. Set the environment variables to a higher value. For example if the JAVA_OPTS variable is containing a minimum of 64MB and 128MB maximum heap size, increase it to 128MB and 256MB values.<\/p>\n<p>OLD: JAVA_OPTS=\u201d-Xms64m -Xmx128m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000\u2033<\/p>\n<p>OLD: JAVA_OPTS=\u201d-Xms128m -Xmx256m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000\u2033<\/p>\n<p>Make sure not to use so high a value that exceeds your physical RAM\u2019s size \u2013 otherwise it will be paged to the harddisk which could cause more performance issues.<\/p>\n<h1>How to rotate Tomcat&#8217;s catalina.out log<\/h1>\n<p>Create:<br \/>\n\/etc\/logrotate.d\/tomcat<\/p>\n<p>\/var\/log\/tomcat\/catalina.out {<br \/>\ncopytruncate<br \/>\ndaily<br \/>\nrotate 7<br \/>\ncompress<br \/>\nmissingok<br \/>\nsize 5M<br \/>\n}<\/p>\n<p>Run the following command to run the cron job manually<\/p>\n<p>\/usr\/sbin\/logrotate \/etc\/logrotate.conf<\/p>\n<p>Tomcat uses Log4j for everything else, but catalina.out gets a copy of everything printed to stdout and stderr.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to connect apache and tomcat mod_proxy_ajp is an Apache module which can be used to forward a client HTTP request to an internal Tomcat application server using the AJP protocol. Make sure this line is in the httpd.conf: LoadModule &hellip; <a href=\"https:\/\/vickistan.com\/?p=405\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-405","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=405"}],"version-history":[{"count":9,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/405\/revisions"}],"predecessor-version":[{"id":407,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/405\/revisions\/407"}],"wp:attachment":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}