Wednesday, December 29, 2010

Tomcat load balancer using mod_proxy_balancer

/etc/init.d/apache2 stop
sudo a2ensite mynewsite
sudo /etc/init.d/apache2 restart
a2dissite utility to disable sites
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_ajp



NameVirtualHost *:80
<VirtualHost *:80>
    ServerName localhost
    UseCanonicalName On
    ServerAdmin harshal.shah@asurion.com
    Alias /healthcheck /var/www
     DocumentRoot /home/localadmin/liferay

    <Directory "/">
          Options FollowSymLinks
          AllowOverride All
          Order allow,deny
          Allow from all
          ProxyPass ajp://localhost:8009/
     </Directory>
     CustomLog /liferay.log combined
     Options +FollowSymlinks
</VirtualHost>
Enable modules  and configuration in the 

NameVirtualHost *:80
<VirtualHost *:80>
 ServerName ubuntu
 DocumentRoot /home/localadmin/
 ProxyRequests Off

 <Proxy *>
 Order deny,allow
 Allow from all
 </Proxy>

 ProxyPass /balancer-manager !
 ProxyPass / balancer://mycluster/ stickysession=JSESSIONID nofailover=On
 ProxyPassReverse / http://localhost:8081/
 ProxyPassReverse / http://localhost:8082/
 ProxyPassReverse / http://localhost:8083/

 <Proxy balancer://mycluster>
# BalancerMember http://localhost:8081  route=a1
# BalancerMember http://localhost:8082  route=a
  BalancerMember ajp://localhost:8109 route=a1
  BalancerMember ajp://localhost:8209 route=a2
  BalancerMember ajp://localhost:8309 route=a3
  ProxySet lbmethod=byrequests
 </Proxy>

 <Location /balancer-manager>
 SetHandler balancer-manager
 Order deny,allow
 Allow from all
 </Location>

</VirtualHost>

using http://ubuntu/balancer-manager

Enable proxy in proxy.conf in mods enabled.

<IfModule mod_proxy.c>
        #turning ProxyRequests on and allowing proxying from all may allow
        #spammers to use your proxy to send email.

        ProxyRequests Off

        <Proxy *>
                AddDefaultCharset off
                Order deny,allow
                Deny from none
                #Allow from .example.com
        </Proxy>

        # Enable/disable the handling of HTTP/1.1 "Via:" headers.
        # ("Full" adds the server version; "Block" removes all outgoing Via: he$
        # Set to one of: Off | On | Full | Block

        ProxyVia On
</IfModule>
To get PHP to run alongside Liferay and Tomcat is a simple matter of modifying the liferay.conf file. Here's how you do it:
ssh into the server.
cd /var/www/
sudo mkdir directory name
sudo nano (or vim if you prefer) index.php
Enter this into the text editor.
<?php
        echo "Hello World!";
?>
cd /etc/apache2/sites-enabled/
sudo nano (or vim if that's your preference) 000-default
Make sure the first item on the page looks like this...
NameVirtualHost *:80
Make sure the <VirtualHost> directive looks like this...
<VirtualHost *:80>
Save and exit the file.
sudo nano liferay.conf
Make sure the <VirtualHosts> directive looks like this...
<VirtualHost *:80>
Add an alias inside the <VirtualHost> tag.
Alias /apps "/var/www/apps"
Add a <Directory> directive inside the <VirtualHost> tag. It should look like this...
<Directory "/apps/">
      Options FollowSymLinks
      AllowOverride None
      Order allow,deny
      Allow from all
      ProxyPass [http://localhost:80/apps/]

</Directory>
Save and exit the file.
Restart the server
/etc/init.d/apache2 restart
Test to see if it's working by navigating to the root URL of the server. You should be taken to Liferay. Then navigate to the siteurl/apps/ and you should see a blank page that says "Hello World".

No comments:

Post a Comment