Monday, July 30, 2012

Tomcat + Apache HTTP cluster in 4 steps!

In this post I want to describe an easy procedure to set up a Tomcat cluster. I assume that Apache Tomcat 6.0.x and HTTPD 2.2.x servers are already installed.
  1. Using Eclipse WTP, create two Tomcat instances and assign them different ports for Admin port, HTTP and AJP
  2. Go into server.xml of each server:
    1. Add the jvmRoute attribute at the element and specify a value (e.g. primary, secondary)
    2. Uncomment the line where  is present
  3. In the application web.xml add the <distributable/> element, directly under the web-app tag
  4. Configure the file httpd.conf as follows:
    1. Uncomment the following modules: 
      1. LoadModule proxy_module modules/mod_proxy.so
      2. LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
      3. LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
      4. LoadModule proxy_connect_module modules/mod_proxy_connect.so
      5. LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
      6. LoadModule proxy_http_module modules/mod_proxy_http.so
    2. Add the following VirtualHost element:
    3.  <VirtualHost *:80>  
           ServerName localhost  
            ServerAlias localhost  
           ProxyRequests Off  
           <Proxy *>  
            Order deny,allow  
            Allow from all  
           </Proxy>  
           ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid scolonpathdelim=On  
           ProxyPassReverse / balancer://mycluster/  
           <Proxy balancer://mycluster>  
            BalancerMember ajp://localhost:8009 route=primary loadfactor=10       
            BalancerMember ajp://localhost:8011 route=secondary loadfactor=10       
           </Proxy>  
           
       </VirtualHost>  
      
All is now ready for the cluster!

Here you can download the files:
https://dl.dropbox.com/u/1580227/blogspot/httpd.conf
https://dl.dropbox.com/u/1580227/blogspot/server1.xml
https://dl.dropbox.com/u/1580227/blogspot/server2.xml

Wednesday, July 25, 2012

Vaadin + Spring + MongoDB...on the cloud!

Hi all, in this post I want to publicize a little experiment I had with the cloud platform from VMWare, CloudFoundry http://www.cloudfoundry.com. The application deployed as example is an evolution of Vaadin Address Book (http://demo.vaadin.com/AddressBook) that is a CRUD application based on Vaadin and JPA. This is the list of modifications I've done on the original application:

  • Spring 3.1 integration
  • JPA implementation switched to Hibernate 4 (original was EclipseLink)
  • Added a document manager feature (upload/download/delete), that stores files with MongoDB GridFS implementation
  • Automatic configuration switch (development / cloud) using Spring 3.1 profiles
  • Integration with Vaadin addon vaadin-lazyquerycontainer https://vaadin.com/directory#addon/lazy-query-container
I found CloudFoundry very easy to use, especially with the Eclipse plugin (http://docs.cloudfoundry.com/tools/STS/configuring-STS.html#installing-the-cloud-foundry-integration-extension-in-eclipse). You can run your app in the same way you do with a generic web application in Eclipse.

I have shared the project on GitHub (https://github.com/cecchisandrone/cloudfoundry). Feel free to download it and try on the cloud! A guide to deploy the app on CloudFoundry can be found here: http://docs.cloudfoundry.com/tools/deploying-apps.html

Note: before starting the project as webapp (in the cloud or locally), please edit the services.properties file. It contains configurations parameters, especially for services on cloud and databases.