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

No comments:

Post a Comment