[personal log] Tomcat 6 with apache2 as reverse proxy on one or more Virtual Hosts

Tomcat-logo.svg
As reported on the my other article about Hippo Open Source CMS i will start a fresh install of tomcat 6.

If you need to do the same as me, read on this article until the end.

First thing to do is to remove the tomcat6 installation made by using aptitude.

so let’s type:

apt-get remove tomcat6 tomcat6-admin tomcat6-common

if any.

Second: since we are going to build and install Tomcat from source, we need ant, so :

apt-get install ant

will install ant, and accetp extra packages to be installed.

Download Tomcat6 from the sources indicated at the bottom of this page: http://tomcat.apache.org/download-60.cgi

I’ve downloaded it in a folder called “tomcat” in my (root) home with the following commands, but be aware of updates before using these lines

cd
mkdir tomcat
cd tomcat
wget http://apache.hippo.nl/tomcat/tomcat-6/v6.0.36/src/apache-tomcat-6.0.36-src.tar.gz

Then uncompress it with

tar -xvzf apache-tomcat-6.0.36-src.tar.gz

then

cd apache-tomcat-6.0.36-src

then

ant download

This should end up with something similar:

BUILD SUCCESSFUL
Total time: 14 seconds

But this is NOT my case: actually what i’ve got is:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

Oh lord! also:

locate tools.jar
root@server:~/tomcat/apache-tomcat-6.0.36-src#

also :O

updatedb

—coffee—
—chat with Filippa

root@server:~/tomcat/apache-tomcat-6.0.36-src# locate tools.jar
/usr/lib/jvm/java-1.5.0-gcj-4.4/lib/tools.jar

So it looks like i have it but it is not where it is supposed to be.
At same time i’ve this ant output:

Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"

 

So first of all is to check if i have a correct installation for java and for jdk.

openjdk-6-jdk

was missing 🙂
then i go back to ~/tomcat/apa[tab] and

root@server:~/tomcat/apache-tomcat-6.0.36-src# ant download
Buildfile: /root/tomcat/apache-tomcat-6.0.36-src/build.xml

build-manifests:
     [copy] Copying 8 files to /root/tomcat/apache-tomcat-6.0.36-src/output/manifests

download:

testexist:
     [echo] Testing  for /usr/share/java/tomcat-native-1.1.23/tomcat-native.tar.gz

downloadfile-2:

testexist:
     [echo] Testing  for /usr/share/java/tomcat-native-1.1.23/LICENSE

downloadzip-2:

proxyflags:

setproxy:

testexist:
     [echo] Testing  for /usr/share/java/commons-daemon-1.0.10/commons-daemon-1.0.10.jar

downloadgz-2:

testexist:
     [echo] Testing  for /usr/share/java/commons-daemon-1.0.10/commons-daemon-1.0.10-native-src.tar.gz

downloadfile-2:

testexist:
     [echo] Testing  for /usr/share/java/commons-daemon-1.0.10/windows/prunmgr.exe

downloadzip-2:

proxyflags:

setproxy:

testexist:
     [echo] Testing  for /usr/share/java/commons-pool-1.5.7-src/build.xml

downloadgz-2:

proxyflags:

setproxy:

testexist:
     [echo] Testing  for /usr/share/java/commons-dbcp-1.3-src/build.xml

downloadgz-2:

build-manifests:
     [copy] Copying 8 files to /root/tomcat/apache-tomcat-6.0.36-src/output/manifests

build-tomcat-dbcp:

testexist:
     [echo] Testing  for /usr/share/java/ecj-3.7.2/ecj-3.7.2.jar

downloadfile-2:

proxyflags:

setproxy:

testexist:
     [echo] Testing  for /usr/share/java/nsis-2.46/makensis.exe

downloadzip:

BUILD SUCCESSFUL
Total time: 1 second

Wew.
Now let’s try to build it with

ant

BUT…

BUILD FAILED
/root/tomcat/apache-tomcat-6.0.36-src/build.xml:513: Execute failed: java.io.IOException: Cannot run program "chmod": java.io.IOException: error=12, Cannot allocate memory

No-way.

root@server:~/tomcat/apache-tomcat-6.0.36-src# free
             total       used       free     shared    buffers     cached
Mem:       1830748    1582248     248500          0     118344     502096
-/+ buffers/cache:     961808     868940
Swap:      1048568     132728     915840
root@server:~/tomcat/apache-tomcat-6.0.36-src#

Let’s add some memory… starting witrh 256 megs.

root@server:~# free
             total       used       free     shared    buffers     cached
Mem:       2092892    1429024     663868          0      10644     278196
-/+ buffers/cache:    1140184     952708
Swap:      1048568          0    1048568

yeas!
And also:

root@server:~/tomcat/apache-tomcat-6.0.36-src# ant
[blah blah]
BUILD SUCCESSFUL
Total time: 16 seconds

It should be in the new created dir “output”.

Now, let’s enable the mod_proxy for apache2

a2enmod proxy_http

then let’s choose a virtualhost to thinker with and add the following lines as suggested here

  <VirtualHost  *:80>
  ServerName www.example.com
  ServerAlias *.example.com
  ProxyPreserveHost  On
  ProxyPass  / http://localhost:8080/site/
  ProxyPassReverse  / http://localhost:8080/site/
  ProxyPassReverseCookiePath  /site /
</VirtualHost

and after restarting Apache, it worked, it worked that fine that is showed my ispconfig page warning me about using https. 🙂
funny.
Now i have to modify this one so it connects to a different port, let’s say 8081, so the relevant part of the virtualHost configuration file will be modified to reflect this:

ProxyPreserveHost  On
  ProxyPass  / http://localhost:8081/site/
  ProxyPassReverse  / http://localhost:8081/site/
  ProxyPassReverseCookiePath  /site /

So the Tomcat6 build took place into the /root/tomcat6/apache-tomcat[tab] and taking a look at its startup script, these files can be moved into any convenient directory.
I will stay here for a while, at least until i figure out how to move conf files into /etc/tomcat6, binaries inti /usr/local/tomcat6 , logs into /var/log/tomcat6, lib into /var/lib/tomcat and so.
But for the moment let’s see how it goes if we try to connect with tomcat. Before this, it is necessary (at least for me) to change the post specified for the connector (this case apache2) into ~/tomcat6/output/conf/server.xml, on an untoucher server.xml file, in this version, you find this param at line 69, precisely:

    <Connector port="8081" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

Now if have to startup the whole things:

service apache2 restart
root@server:~/tomcat/apache-tomcat-6.0.36-src/output/build/bin# ./shutdown.sh 
Using CATALINA_BASE:   /root/tomcat/apache-tomcat-6.0.36-src/output/build
Using CATALINA_HOME:   /root/tomcat/apache-tomcat-6.0.36-src/output/build
Using CATALINA_TMPDIR: /root/tomcat/apache-tomcat-6.0.36-src/output/build/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /root/tomcat/apache-tomcat-6.0.36-src/output/build/bin/bootstrap.jar
root@server:~/tomcat/apache-tomcat-6.0.36-src/output/build/bin# ./startup.sh start
Using CATALINA_BASE:   /root/tomcat/apache-tomcat-6.0.36-src/output/build
Using CATALINA_HOME:   /root/tomcat/apache-tomcat-6.0.36-src/output/build
Using CATALINA_TMPDIR: /root/tomcat/apache-tomcat-6.0.36-src/output/build/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /root/tomcat/apache-tomcat-6.0.36-src/output/build/bin/bootstrap.jar
root@server:~/tomcat/apache-tomcat-6.0.36-src/output/build/bin# netstat -an |grep 8081
tcp6       0      0 :::8081                 :::*                    LISTEN

And with my browser i see:

tomcat6-apache2-as-proxyWhich basicalaly means that apache2 is correctly forwarding http request received on port 80 to the destination specified in the VirtualHost configuration file.

Also

apache2-tomcat-working

Obviously this case there is no webapp configured yet or at least, if any by default, there are no jsp nor html files to be presented to users.

This means that now it’s time to download Hippo.. let’s find a downloadable package…

http://download.demo.onehippo.com/7.8.0/HippoCMS-GoGreenlinux.gtk.x86_64.zip

While download finishes, let’s put on a coffee.

Fine, download finished, i just discovered that this package contains tomcat as well, so i decided to use this one. To do this i changed the configuration in order to listen on port 8081 and voilà

http://giuseppeurso.it:8081/site

At the end...
At the end…

But it looks like i have to tune the proxy part so i can access this through my normal port 80.

CONCLUSIONS in short: it requires more ram than expected. It’s not for small machines or even worst, for small VPSs. This last case regards me and my machine, at the end i had to shutdown tomcat and java to avoid to limit the memory apache2 needs to create child processes.

Cannot allocate memory: couldn't create child process:

And Also

PHP Fatal error:  Out of memory (allocated 64225280) (tried to allocate 78 bytes) in /blah

And

unable to init Zlib: deflateInit2 returned -4: URL /index.php, referer: https://blog.giuseppeurso.net/

 

USEFUL LINKS:
http://tomcat.apache.org/tomcat-6.0-doc/introduction.html
http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html
http://www.onehippo.org/7_8/library/deployment/configuring/configure-apache-httpd-web-server-for-sites.html
http://www.onehippo.org/7_7/library/development/build-hippo-cms-from-scratch.html 

(Visited 3,069 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

One thought on “[personal log] Tomcat 6 with apache2 as reverse proxy on one or more Virtual Hosts”

  1. This server apache tomcat post is very helpful for advance java deployment team. How to implement on any system with error support. This blog describe very well that how use server apache tomcat manager and mange java coding from initial download and configuration on system.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.